Reset model attributes when textbook editing is cancelled
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user