backbone-generator/templates/collection_view.coffee.erb

24 lines
605 B
Plaintext

class window.<%= plural_object_name %>View extends Backbone.View
events: {
'click button.new': 'addNew'
}
template: JST['<%= plural_underscore_name %>/list']
initialize: ->
@collection.bind('refresh', @addAll)
this.render()
@collection.fetch
render: =>
$(this.el).html(this.template())
this
addOne: (model) =>
view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el)
addAll: =>
@collection.each(this.addOne())
addNew: =>
facility = new <%= object_name %>()
@collection.add(facility)
this.addOne(facility)