1 /**
  2  * Random comment generator button
  3  *
  4  * @class RandomButtonView
  5  * @extends Backbone.View
  6  * @author Bodnar Istvan <istvan@gawker.com>
  7  */
  8 /*global CommentModel, FormView */
  9 var RandomButtonView = Backbone.View.extend(
 10 /** @lends RandomButtonView.prototype */
 11 	{
 12 		/**
 13 		 * The map of delegated event handlers
 14 		 * @type Object
 15 		 */
 16 		events: {
 17 			'click': 'createComment'
 18 		},
 19 		
 20 		/**
 21 		 * Initialize view, make sure button has a comment collection to work with
 22 		 */
 23 		initialize: function () {
 24 			if (this.collection === undefined) {
 25 				throw 'NoCollectionDefined';
 26 			}
 27 		},
 28 		
 29 		/**
 30 		 * Click event handler that creates 5 new comment models with random texts
 31 		 * @returns {Boolean} Returns false to stop propagation
 32 		 */
 33 		createComment: function () {
 34 			var i;
 35 			for (i = 0; i < 5; i++) {
 36 				this.collection.add(new CommentModel({
 37 					text: 'Random comment ' + Math.floor(Math.random() * 100),
 38 					author: 'serif'
 39 				}));
 40 			}
 41 
 42 			// return false to stop event propagation
 43 			return false;
 44 		}
 45 	}
 46 );
 47