From d878aa470074d5698a316512b513949fa22073f2 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 18 May 2012 15:23:15 -0700 Subject: Fixing save logic Moved dirty marker clearing code to model. --- js/controllers/document-controller.js | 15 ++++++++------- js/document/models/base.js | 18 +++++++++++++++--- js/mediators/io-mediator.js | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index f1523d87..cf618360 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -145,18 +145,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function(event) { // if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ - // - this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) + //Currently we don't need a callback handler + //this.activeDocument.model.save(this.saveExecuted.bind(this)); + this.activeDocument.model.save(); } else { - //Error: + //Error: cloud not available and/or no active document } } }, - testCallback: { + //////////////////////////////////////////////////////////////////// + // + saveExecuted: { value: function (value) { - console.log(value); - //TODO: Move this to the model.save() - this.activeDocument.model.needsSave = false; + //File saved, any callbacks or events should go here } }, //////////////////////////////////////////////////////////////////// diff --git a/js/document/models/base.js b/js/document/models/base.js index df341b2f..c99e36c7 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -151,7 +151,7 @@ exports.BaseDocumentModel = Montage.create(Component, { head: this.views.design.iframe.contentWindow.document.head, body: this.views.design.iframe.contentWindow.document.body, mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator - }, callback.bind(this)); + }, this.handleSaved.bind({callback: callback, model: this})); } else { //TODO: Add logic to save code view data } @@ -180,7 +180,7 @@ exports.BaseDocumentModel = Montage.create(Component, { head: this.views.design.iframe.contentWindow.document.head, body: this.views.design.iframe.contentWindow.document.body, mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator - }, callback.bind(this)); + }, this.handleSaved.bind({callback: callback, model: this})); } else { //TODO: Add logic to save code view data } @@ -190,7 +190,7 @@ exports.BaseDocumentModel = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // saveAs: { - value: function () { + value: function (callback) { // if (this.needsSave) { //Save current file on memory @@ -199,6 +199,18 @@ exports.BaseDocumentModel = Montage.create(Component, { } } }, + //////////////////////////////////////////////////////////////////// + // + handleSaved: { + value: function (result) { + // + if (result.status === 204) { + this.model.needsSave = false; + } + // + if (this.callback) this.callback(result); + } + }, //////////////////////////////////////////////////////////////////// // close: { diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c506e186..ade27728 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -557,6 +557,7 @@ function loadWebGL (e) {\n\ mjslibtag = template.file.content.document.createElement('script'); mjslibtag.setAttribute('type', 'text/javascript'); mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js'); + mjslibtag.setAttribute('data-package', '.'); mjslibtag.setAttribute('data-mjs-lib', 'true'); if (ninjaWrapper) { template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag); -- cgit v1.2.3