backbone-generator/templates/collection_view.coffee.erb

21 lines
568 B
Plaintext
Raw Normal View History

2011-05-09 02:44:21 +00:00
class window.<%= plural_object_name %>View extends Backbone.View
events: {
'click button.new': 'addNew'
}
template: JST['<%= plural_underscore_name %>/list']
initialize: ->
2011-05-13 14:04:42 +00:00
@collection.bind('refresh', this.addAll)
2011-05-09 02:44:21 +00:00
render: =>
2011-05-09 11:35:37 +00:00
$(this.el).html(this.template())
2011-05-09 02:44:21 +00:00
this
addOne: (model) =>
view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el)
addAll: =>
2011-05-09 11:35:37 +00:00
@collection.each(this.addOne())
2011-05-09 02:44:21 +00:00
addNew: =>
facility = new <%= object_name %>()
@collection.add(facility)
2011-05-09 11:35:37 +00:00
this.addOne(facility)
2011-05-09 02:44:21 +00:00