From 0e595c4e11ce9b44eff157de8616ed15fcd5d6fc Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 12:37:29 -0800 Subject: refactoring some file names and locations, change made to maintain only one codemirror div. Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 196 +++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 js/io/ui/save-as-dialog.reel/save-as-dialog.js (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 new file mode 100644 index 00000000..371aa9a7 --- /dev/null +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js @@ -0,0 +1,196 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + nj= require("js/lib/NJUtils.js").NJUtils; + +var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { + + hasReel: { + value: true + }, + + fileName : { + enumerable: true, + writable: true, + value: "" + }, + + folderUri:{ + enumerable: true, + writable: true, + value: "" + }, + + callback : { + enumerable: true, + writable: true, + value: null + }, + + callbackScope : { + enumerable: true, + writable: true, + value: null + }, + + willDraw: { + enumerable: false, + value: function() {} + }, + draw: { + enumerable: false, + value: function() {} + }, + didDraw: { + enumerable: false, + value: function() { + var self = this; + this.fileInputField.selectDirectory = true; + this.fileInputField.pickerName = "saveAsDirectoryPicker"; + this.newFileName.value = this.fileName; + this.fileInputField.newFileDirectory.value = this.folderUri; + + this.newFileName.addEventListener("blur", function(evt){self.handleNewFileNameOnblur(evt);}, false); + this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); + + this.enableOk(); + } + }, + + handleNewFileDirectorySet:{ + value:function(evt){ + if(!!evt._event.newFileDirectory){ + this.folderUri = evt._event.newFileDirectory; + if(this.folderUri !== ""){ + this.enableOk(); + } + } + } + }, + + handleNewFileNameOnblur:{ + value:function(evt){ + this.fileName = this.newFileName.value; + if(this.fileName !== ""){ + if(this.fileName !== ""){ + this.enableOk(); + } + } + } + }, + + + enableOk:{ + value: function(){ + if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ + this.okButton.removeAttribute("disabled"); + this.error.innerHTML=""; + } + } + }, + + handleCancelButtonAction :{ + value:function(evt){ + //clean up memory + //this.cleanup(); + + if(this.popup){ + this.popup.hide(); + } + + } + }, + + handleOkButtonAction:{ + value: function(evt){ + var filename = this.fileName, + newFileDirectory = this.newFileDirectory, + success = true; + if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ + try{ + //validate file name and folder path + //check if file already exists + if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful + this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api + }else{ + //send save as event + var saveAsEvent = document.createEvent("Events"); + saveAsEvent.initEvent("saveAsFile", false, false); + saveAsEvent.saveAsOptions = {"filename":filename, "destination": newFileDirectory}; + this.eventManager.dispatchEvent(saveAsEvent); + } + }catch(e){ + success = false; + console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory); + console.log(e.stack); + } + + if(success){ + //clean up memory + //this.cleanup(); + + if(this.popup){ + this.popup.hide(); + } + } + }else{ + if(this.error.innerHTML !== ""){ + this.showError("! Name and Location should be valid."); + } + //disable ok + if(!this.okButton.hasAttribute("disabled")){ + this.okButton.setAttribute("disabled", "true"); + } + } + } + }, + + isValidUri:{ + value: function(uri){ + var status= nj.isValidUri(uri); + if(uri !== ""){ + if(!status){ + this.showError("! Invalid directory."); + } + } + return status; + } + }, + isValidFileName:{ + value: function(fileName){ + var status = nj.isValidFileName(fileName); + if(fileName !== ""){ + if(!status){ + this.showError("! Invalid file name."); + } + } + return status; + } + }, + checkFileExists:{ + value: function(fileUri, folderUri, fileType){ + var status= this.application.ninja.coreIoApi.checkFileExists(fileUri, folderUri, fileType); + if(status){ + this.showError("! File already exists."); + } + return status; + } + }, + + showError:{ + value:function(errorString){ + this.error.innerHTML = ""; + this.error.innerHTML=errorString; + //disable ok + if(!this.okButton.hasAttribute("disabled")){ + this.okButton.setAttribute("disabled", "true"); + } + } + } + +}); \ No newline at end of file -- cgit v1.2.3 From 476a25e8a662270dfe5b37c560e4235f02b146e4 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 12:59:41 -0800 Subject: uri validation moved to file io apis Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 371aa9a7..b20bed87 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 @@ -152,7 +152,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { isValidUri:{ value: function(uri){ - var status= nj.isValidUri(uri); + var status= this.application.ninja.coreIoApi.isValidUri(uri); if(uri !== ""){ if(!status){ this.showError("! Invalid directory."); -- cgit v1.2.3 From 79b0173eeca079dec42ff1480182656dbe3af44f Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 09:49:23 -0800 Subject: removed usage of NJUtils.js as it is being deleted. Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 b20bed87..1de2eaf1 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 @@ -5,8 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot */ var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - nj= require("js/lib/NJUtils.js").NJUtils; + Component = require("montage/ui/component").Component; var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { @@ -163,7 +162,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { }, isValidFileName:{ value: function(fileName){ - var status = nj.isValidFileName(fileName); + var status = this.isValidFileName(fileName); if(fileName !== ""){ if(!status){ this.showError("! Invalid file name."); @@ -191,6 +190,23 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { this.okButton.setAttribute("disabled", "true"); } } - } + }, + + /*** + * file name validation + */ + isValidFileName:{ + value: function(fileName){ + var status = false; + if(fileName !== ""){ + fileName = fileName.replace(/^\s+|\s+$/g,""); + status = !(/[/\\]/g.test(fileName)); + if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden + status = !(/^\./g.test(fileName)); + } + } + return status; + } + } }); \ No newline at end of file -- cgit v1.2.3 From 7618cabe1945acc6392c48f3b57820f67f7973b0 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 10:22:26 -0800 Subject: removed using montage button, since it has changed in Montafe 0.6 Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 1de2eaf1..d1f1c26b 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 @@ -57,6 +57,9 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { this.newFileName.addEventListener("blur", function(evt){self.handleNewFileNameOnblur(evt);}, false); this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); + this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); + this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false); + this.enableOk(); } }, -- cgit v1.2.3 From c9d0cb73698066247c6267bba8fa446a979565fb Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 9 Feb 2012 11:12:21 -0800 Subject: fixed templates descriptor, changed validation to on key up, fixed minor ui issues Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 d1f1c26b..4546e124 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 @@ -54,7 +54,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { this.newFileName.value = this.fileName; this.fileInputField.newFileDirectory.value = this.folderUri; - this.newFileName.addEventListener("blur", function(evt){self.handleNewFileNameOnblur(evt);}, false); + this.newFileName.addEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false); this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); @@ -68,18 +68,18 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { value:function(evt){ if(!!evt._event.newFileDirectory){ this.folderUri = evt._event.newFileDirectory; - if(this.folderUri !== ""){ + if(this.isValidUri(this.folderUri)){ this.enableOk(); } } } }, - handleNewFileNameOnblur:{ + handleNewFileNameOnkeyup:{ value:function(evt){ this.fileName = this.newFileName.value; if(this.fileName !== ""){ - if(this.fileName !== ""){ + if(this.isValidFileName(this.fileName)){ this.enableOk(); } } @@ -165,7 +165,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { }, isValidFileName:{ value: function(fileName){ - var status = this.isValidFileName(fileName); + var status = this.validateFileName(fileName); if(fileName !== ""){ if(!status){ this.showError("! Invalid file name."); @@ -198,7 +198,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { /*** * file name validation */ - isValidFileName:{ + validateFileName:{ value: function(fileName){ var status = false; if(fileName !== ""){ -- cgit v1.2.3 From c627ebb5735d55218813b073c655dae6cded6040 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 15:50:14 -0800 Subject: show iframeContainer if all documents are closed Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 4546e124..786ef5c9 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 @@ -89,7 +89,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { enableOk:{ value: function(){ - if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ + if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri)){ this.okButton.removeAttribute("disabled"); this.error.innerHTML=""; } @@ -141,7 +141,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { } } }else{ - if(this.error.innerHTML !== ""){ + if(this.error.innerHTML === ""){ this.showError("! Name and Location should be valid."); } //disable ok -- cgit v1.2.3 From 4641dbefb6e8cb41f1f3d7f4d070d50bcaed94be Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 16 Feb 2012 17:32:57 -0800 Subject: remove similar function from coreioapi.js Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js') 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 786ef5c9..55a09fa8 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 @@ -175,8 +175,25 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { } }, checkFileExists:{ - value: function(fileUri, folderUri, fileType){ - var status= this.application.ninja.coreIoApi.checkFileExists(fileUri, folderUri, fileType); + value: function(fileName, folderUri, fileType){ + var uri = "", response=null, status=true; + //prepare absolute uri + if(/[^/\\]$/g.test(folderUri)){ + folderUri = folderUri + "/"; + } + if(!!fileType && (fileName.lastIndexOf(fileType) !== (fileName.length - fileType.length))){ + fileName = fileName+fileType; + } + uri = ""+folderUri+fileName; + response= this.application.ninja.coreIoApi.fileExists({"uri":uri}); + if(!!response && response.success && (response.status === 204)){ + status = true; + }else if(!!response && response.success && (response.status === 404)){ + status = false; + }else{ + status = false; + } + if(status){ this.showError("! File already exists."); } -- cgit v1.2.3