From 74b9703defb499a99e6f5632e7d82cfb6f7a4834 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 25 Jun 2013 16:35:51 -0400 Subject: [PATCH] Reset model attributes when textbook editing is cancelled --- cms/static/js/models/textbook.js | 10 ++++++++++ cms/static/js/views/textbook.js | 2 ++ 2 files changed, 12 insertions(+) diff --git a/cms/static/js/models/textbook.js b/cms/static/js/models/textbook.js index 01bb49f6a7..be87d0b67b 100644 --- a/cms/static/js/models/textbook.js +++ b/cms/static/js/models/textbook.js @@ -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(); }, diff --git a/cms/static/js/views/textbook.js b/cms/static/js/views/textbook.js index bfc0dc011f..a27d32f3db 100644 --- a/cms/static/js/views/textbook.js +++ b/cms/static/js/views/textbook.js @@ -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() {