From 6f5ffa17c72dd0aef7a02e3496154514750143c2 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 18 May 2012 18:38:09 -0700 Subject: save for code view documents in the new dom architecture Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 8 +++++- js/document/document-text.js | 10 ++++++- js/document/models/text.js | 53 ++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 86b1d057..814a30e1 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -356,7 +356,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, console.log("URI is: ", uri); } }, - + + //todo: remove this funciton as it is not used textDocumentOpened: { value: function(doc) { @@ -413,6 +414,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.hideCanvas(true); + if(this._documents.length === 0){ + document.getElementById("iframeContainer").style.display="block"; + document.getElementById("codeViewContainer").style.display="block"; + } + NJevent("closeDocument", doc.model.file.uri); //TODO: Delete object here diff --git a/js/document/document-text.js b/js/document/document-text.js index 533b32c9..09525f4e 100755 --- a/js/document/document-text.js +++ b/js/document/document-text.js @@ -53,8 +53,16 @@ exports.TextDocument = Montage.create(Component, { callback.call(context, this); } - } + }, //////////////////////////////////////////////////////////////////// + // + closeDocument: { + value: function (context, callback) { + var closed = this.model.close(null); + + callback.call(context, this); + } + } //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// diff --git a/js/document/models/text.js b/js/document/models/text.js index 5a5e86ef..d21666d0 100755 --- a/js/document/models/text.js +++ b/js/document/models/text.js @@ -16,7 +16,58 @@ exports.TextDocumentModel = Montage.create(BaseDocumentModel, { hasTemplate: { enumerable: false, value: false - } + }, +//////////////////////////////////////////////////////////////////// + // + save: { + enumerable: false, + value: function (callback) { + this.application.ninja.documentController.activeDocument.model.views.code.editor.save();//save to textarea + + var self = this; + + this.application.ninja.ioMediator.fileSave({ + mode: ""+ self.file.extension, + file: self.file, + content:self.views.code.textArea.value + }, this.handleSaved.bind({callback: callback, model: this})); + } + }, +//////////////////////////////////////////////////////////////////// + // + handleSaved: { + value: function (result) { + // + if (result.status === 204) { + this.model.needsSave = false; + } + // + if (this.callback) this.callback(result); + } + }, + //////////////////////////////////////////////////////////////////// + // + close: { + value: function (view, callback) { + //Outcome of close (pending on save logic) + var success; + // + if (this.needsSave) { + //Prompt user to save of lose data + } else { + //Close file + success = true; + } + // + this.views.code.textParentContainer.removeChild(this.views.code.textViewContainer); + this.views.code.restoreAllPanels(); + this.views.code.showCodeViewBar(false); + this.views.code = null; + + // + return success; + } + } }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// \ No newline at end of file -- cgit v1.2.3