Reset model attributes when textbook editing is cancelled

This commit is contained in:
David Baumgold
2013-06-25 16:35:51 -04:00
parent 9797b34c4e
commit 74b9703def
2 changed files with 12 additions and 0 deletions

View File

@@ -13,6 +13,16 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
relatedModel: "CMS.Models.Chapter",
collectionType: "CMS.Collections.ChapterSet"
}],
initialize: function() {
this.setOriginalAttributes();
return this;
},
setOriginalAttributes: function() {
this._originalAttributes = this.parse(this.toJSON());
},
reset: function() {
this.set(this._originalAttributes);
},
isEmpty: function() {
return !this.get('name') && this.get('chapters').isEmpty();
},

View File

@@ -125,6 +125,7 @@ CMS.Views.EditTextbook = Backbone.View.extend({
var that = this;
this.model.save({}, {
success: function() {
that.setOriginalAttributes();
that.close();
},
complete: function() {
@@ -134,6 +135,7 @@ CMS.Views.EditTextbook = Backbone.View.extend({
},
cancel: function(e) {
if(e && e.preventDefault) { e.preventDefault(); }
this.model.reset();
return this.close();
},
close: function() {