Skip to content
Snippets Groups Projects
Commit 74b9703d authored by David Baumgold's avatar David Baumgold
Browse files

Reset model attributes when textbook editing is cancelled

parent 9797b34c
No related merge requests found
......@@ -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();
},
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment