backbone-generator/templates/view.js.erb

22 lines
535 B
Plaintext
Raw Normal View History

2011-04-15 18:55:37 +00:00
var <%= object_name %>View = Backbone.View.extend({
2011-05-03 19:43:19 +00:00
events: {
'click button.save': 'save'
},
attributeFields: [],
template: JST['<%= underscore_name %>s/view'],
2011-04-15 18:55:37 +00:00
initialize: function() {
2011-05-03 19:43:19 +00:00
_.bindAll(this, 'render', 'save');
this.model.bind('change', this.render);
2011-04-15 18:55:37 +00:00
},
render: function() {
2011-04-29 19:05:54 +00:00
$(this.el).html(this.template(this.model.toJSON()));
2011-05-03 19:43:19 +00:00
this.$('button.save').text(this.model.isNew() ? 'Create' : 'Update');
return this;
2011-05-03 19:43:19 +00:00
},
save: function() {
this.model.save(this.attributes());
2011-04-15 18:55:37 +00:00
}
});