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/document/models/text.js | 53 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'js/document/models') 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