2011-04-18 15:36:46 +00:00
|
|
|
var <%= plural_object_name %>View = Backbone.View.extend({
|
2011-05-03 19:43:19 +00:00
|
|
|
events: {
|
|
|
|
'click button.new': 'addNew'
|
|
|
|
},
|
2011-04-18 15:36:46 +00:00
|
|
|
template: JST['<%= plural_underscore_name %>/list'],
|
2011-05-03 19:43:19 +00:00
|
|
|
initialize: function() {
|
2011-05-03 19:53:36 +00:00
|
|
|
_.bindAll(this, 'render', 'addOne', 'addAll', 'addNew');
|
2011-04-15 19:32:04 +00:00
|
|
|
|
|
|
|
this.collection.bind('refresh', this.addAll);
|
|
|
|
|
|
|
|
this.render();
|
|
|
|
this.collection.fetch()
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
$(this.el).html(this.template());
|
2011-04-15 20:14:18 +00:00
|
|
|
return this;
|
2011-04-15 19:32:04 +00:00
|
|
|
},
|
|
|
|
addOne: function(model) {
|
2011-04-15 20:11:57 +00:00
|
|
|
var view = new <%= object_name %>View({model: model});
|
2011-04-15 19:32:04 +00:00
|
|
|
this.$('.list').append(view.render().el);
|
|
|
|
},
|
|
|
|
addAll: function() {
|
|
|
|
this.collection.each(this.addOne);
|
2011-05-03 19:43:19 +00:00
|
|
|
},
|
|
|
|
addNew: function() {
|
2011-05-03 19:53:36 +00:00
|
|
|
var facility = new <%= object_name %>();
|
|
|
|
this.collection.add(facility);
|
2011-05-03 19:43:19 +00:00
|
|
|
|
2011-05-03 19:53:36 +00:00
|
|
|
this.addOne(facility);
|
2011-04-15 19:32:04 +00:00
|
|
|
}
|
|
|
|
});
|