From 92c311c527b864f35aa98dba950da677746d4708 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 6 Mar 2012 16:42:10 -0800 Subject: - detect document style edit [with Eric's input for styles-controller.js] - integrated save as Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 26 ++++++++++++++++++++------ js/controllers/styles-controller.js | 10 ++++++++-- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 4 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 1f8c58b0..e29148c9 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -157,7 +157,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ saveAsSettings.fileName = this.activeDocument.name; saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); - //add callback + saveAsSettings.callback = this.saveAsCallback.bind(this); this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); } } @@ -166,7 +166,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // fileSaveResult: { value: function (result) { - if(result.status === 204){ + if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved this.activeDocument.needsSave = false; if(this.application.ninja.currentDocument !== null){ //clear Dirty StyleSheets for the saved document @@ -254,10 +254,24 @@ var DocumentController = exports.DocumentController = Montage.create(Component, //////////////////////////////////////////////////////////////////// // saveAsCallback:{ - value:function(){ - //close current document - - //create a new file + value:function(saveAsDetails){ + var fileUri = null, filename = saveAsDetails.filename, destination = saveAsDetails.destination; + //update document metadata + this.activeDocument.name = ""+filename; + //prepare new file uri + if(destination && (destination.charAt(destination.length -1) !== "/")){ + destination = destination + "/"; + } + fileUri = destination+filename; + + this.activeDocument.uri = fileUri; + //save a new file + //use the ioMediator.fileSaveAll when implemented + this.activeDocument._userDocument.name=filename; + this.activeDocument._userDocument.root=destination; + this.activeDocument._userDocument.uri=fileUri; + this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); + // } }, diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 662816f5..addfc24e 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -1236,11 +1236,17 @@ var stylesController = exports.StylesController = Montage.create(Component, { clearDirtyStyleSheets : { value: function(doc) { - if(!doc) { + this.dirtyStyleSheets.length = 0; + + if(doc) { + var stillDirty = this.dirtyStyleSheets.filter(function(sheet) { + return sheet.document !== doc; + }); this.dirtyStyleSheets = null; - this.dirtyStyleSheets = []; + this.dirtyStyleSheets = stillDirty; } + } }, diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.js b/js/io/ui/save-as-dialog.reel/save-as-dialog.js index 0a322b99..c60a92f9 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.js +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js @@ -111,7 +111,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { handleOkButtonAction:{ value: function(evt){ var filename = this.fileName, - newFileDirectory = this.newFileDirectory, + newFileDirectory = this.folderUri, success = true; if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ try{ @@ -128,7 +128,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { } }catch(e){ success = false; - console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory); + console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ newFileDirectory); console.log(e.stack); } -- cgit v1.2.3