fix bugs in the view templates
This commit is contained in:
parent
ed9a824c37
commit
5c2e078c02
|
@ -1,15 +1,17 @@
|
||||||
var <%= object_name %>View = Backbone.View.extend({
|
var <%= object_name %>View = Backbone.View.extend({
|
||||||
events: {
|
events: {
|
||||||
'click button.save': 'save',
|
'click button.save': 'save',
|
||||||
'click button.destroy': 'destroy'
|
'click button.delete': 'destroy'
|
||||||
},
|
},
|
||||||
attributeFields: [],
|
attributeFields: [],
|
||||||
template: JST['<%= underscore_name %>s/view'],
|
template: JST['<%= underscore_name %>s/view'],
|
||||||
className: '<%= underscore_name %>',
|
className: '<%= underscore_name %>',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
_.bindAll(this, 'render', 'save', 'destroy');
|
_.bindAll(this, 'render', 'save', 'destroy', 'remove');
|
||||||
|
|
||||||
this.model.bind('change', this.render);
|
this.model.bind('change', this.render);
|
||||||
|
this.model.bind('remove', this.remove);
|
||||||
|
this.model.view = this;
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
$(this.el).html(this.template(this.model.toJSON()));
|
$(this.el).html(this.template(this.model.toJSON()));
|
||||||
|
@ -17,7 +19,7 @@ var <%= object_name %>View = Backbone.View.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
save: function() {
|
save: function() {
|
||||||
this.model.save(this.attributes());
|
this.model.save(this.attributes(), { success: function(model) { model.view.render(); } });
|
||||||
},
|
},
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
if (confirm("Are you sure?")) {
|
if (confirm("Are you sure?")) {
|
||||||
|
|
|
@ -18,10 +18,11 @@ describe('<%= object_name %>View', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
model = new <%= object_name %>({id: 1});
|
model = new <%= object_name %>({id: 1});
|
||||||
setFixtures('<div id="container" />');
|
setFixtures('<div id="container" />');
|
||||||
|
|
||||||
|
view = new <%= object_name %>View({model: model});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render with an update button', function() {
|
it('should render with an update button', function() {
|
||||||
view = new <%= object_name %>View({model: model});
|
|
||||||
view.render();
|
view.render();
|
||||||
|
|
||||||
expect(view.$('button.save')).toHaveText('Update');
|
expect(view.$('button.save')).toHaveText('Update');
|
||||||
|
@ -31,7 +32,7 @@ describe('<%= object_name %>View', function() {
|
||||||
spyOn(window, 'confirm').andReturn(true);
|
spyOn(window, 'confirm').andReturn(true);
|
||||||
spyOn(model, 'destroy');
|
spyOn(model, 'destroy');
|
||||||
|
|
||||||
$('#facility').append(view.el);
|
$('#container').append(view.el);
|
||||||
view.$('button.delete').trigger('click');
|
view.$('button.delete').trigger('click');
|
||||||
|
|
||||||
expect(model.destroy).toHaveBeenCalled();
|
expect(model.destroy).toHaveBeenCalled();
|
||||||
|
|
Loading…
Reference in New Issue