2011-05-09 02:44:21 +00:00
|
|
|
class window.<%= object_name %>View extends Backbone.View
|
|
|
|
events: {
|
|
|
|
'click button.save': 'save',
|
|
|
|
'click button.delete': 'destroy'
|
|
|
|
}
|
|
|
|
attributeFields: []
|
|
|
|
template: JST['<%= underscore_name %>s/view']
|
2011-05-09 11:35:37 +00:00
|
|
|
className: '<%= css_class_name %>'
|
2011-05-09 02:44:21 +00:00
|
|
|
initialize: ->
|
|
|
|
@model.bind('change', @render)
|
|
|
|
@model.bind('remove', @remove)
|
|
|
|
@model.view = this
|
|
|
|
render: =>
|
2011-05-09 11:35:37 +00:00
|
|
|
$(@el).html(@template(@model.toJSON()))
|
|
|
|
this.$('button.save').text(if @model.isNew() then 'Create' else 'Update')
|
2011-05-09 02:44:21 +00:00
|
|
|
this
|
|
|
|
save: =>
|
2011-05-09 11:35:37 +00:00
|
|
|
@model.save(@attributes())
|
2011-05-09 02:44:21 +00:00
|
|
|
destroy: =>
|
|
|
|
if confirm("Are you sure?")
|
|
|
|
@model.destroy
|
|
|
|
|