From 92161460a6cbbdebfd1b0263ec6eb790091920a9 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:18:21 -0800 Subject: Moving changes from Gerrit, on 1/27, to the github branch: - added file existence check and validation to save as dialog - minor css fix for file picker, new file dialog Signed-off-by: Ananya Sen --- .../new-file-options-navigator.js | 41 +----- .../save-as-dialog.reel/save-as-dialog.css | 6 + .../save-as-dialog.reel/save-as-dialog.html | 4 +- .../workflow/save-as-dialog.reel/save-as-dialog.js | 138 ++++++++++++++++----- 4 files changed, 118 insertions(+), 71 deletions(-) mode change 100755 => 100644 js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js mode change 100755 => 100644 js/io/workflow/save-as-dialog.reel/save-as-dialog.css mode change 100755 => 100644 js/io/workflow/save-as-dialog.reel/save-as-dialog.html mode change 100755 => 100644 js/io/workflow/save-as-dialog.reel/save-as-dialog.js (limited to 'js/io/workflow') diff --git a/js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js old mode 100755 new mode 100644 index 61b963b3..7702b1a2 --- a/js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js +++ b/js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js @@ -9,7 +9,7 @@ var Montage = require("montage/core/core").Montage, iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), treeModule = require("js/components/ui/tree-basic/tree.reel"), newFileLocationSelectionModule = require("js/io/workflow/newFileDialog/new-file-workflow-controller"), - fileSystem = require("js/io/system/filesystem").FileSystem; + fileUtils = require("js/io/utils/file-utils").FileUtils; var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, { @@ -244,7 +244,6 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C this.okButton.setAttribute("disabled", "true"); } } - } }, @@ -336,16 +335,8 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C isValidUri:{ value: function(uri){ - var isWindowsUri=false, isUnixUri=false,status=false; + var status= fileUtils.isValidUri(uri); if(uri !== ""){ - uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces - - //for local machine folder uri - isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); - isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix - status = isWindowsUri || isUnixUri; - if(isWindowsUri && isUnixUri){status = false;} - if(!status){ this.showError("! Invalid directory."); } @@ -355,14 +346,8 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C }, isValidFileName:{ value: function(fileName){ - var status = false; + var status = fileUtils.isValidFileName(fileName); 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)); - } - if(!status){ this.showError("! Invalid file name."); } @@ -372,25 +357,9 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C }, checkFileExists:{ value: function(fileUri, folderUri, fileType){ - var uri = "", response=null, status=true; - - //prepare absolute uri - if(/[^/\\]$/g.test(folderUri)){ - folderUri = folderUri + "/"; - } - - //todo:add file extension check - - uri = ""+folderUri+fileUri; - - response = fileSystem.shellApiHandler.fileExists({"uri":uri}); - if(!!response && response.success && (response.status === 204)){ + var status= fileUtils.checkFileExists(fileUri, folderUri, fileType); + if(status){ this.showError("! File already exists."); - status = true; - }else if(!!response && response.success && (response.status === 404)){ - status = false; - }else{ - this.showError("! Cloud Service Error."); } return status; } diff --git a/js/io/workflow/save-as-dialog.reel/save-as-dialog.css b/js/io/workflow/save-as-dialog.reel/save-as-dialog.css old mode 100755 new mode 100644 index 75f57125..7082f485 --- a/js/io/workflow/save-as-dialog.reel/save-as-dialog.css +++ b/js/io/workflow/save-as-dialog.reel/save-as-dialog.css @@ -1,3 +1,9 @@ +/* + 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. +
*/ + .saveAsDialog{ font-size:12px; width:450px; diff --git a/js/io/workflow/save-as-dialog.reel/save-as-dialog.html b/js/io/workflow/save-as-dialog.reel/save-as-dialog.html old mode 100755 new mode 100644 index 1f20ee16..eca6801f --- a/js/io/workflow/save-as-dialog.reel/save-as-dialog.html +++ b/js/io/workflow/save-as-dialog.reel/save-as-dialog.html @@ -54,7 +54,9 @@ "properties": { "element": {"#": "saveAsDialog"}, "fileInputField": {"@": "fileInputField"}, - "newFileName": {"#": "newFileName"} + "newFileName": {"#": "newFileName"}, + "error":{"#": "error"}, + "okButton":{"#": "okButton"} } } } diff --git a/js/io/workflow/save-as-dialog.reel/save-as-dialog.js b/js/io/workflow/save-as-dialog.reel/save-as-dialog.js old mode 100755 new mode 100644 index 1255a1bd..52e5ab82 --- a/js/io/workflow/save-as-dialog.reel/save-as-dialog.js +++ b/js/io/workflow/save-as-dialog.reel/save-as-dialog.js @@ -5,7 +5,8 @@ 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; + Component = require("montage/ui/component").Component, + fileUtils = require("js/io/utils/file-utils").FileUtils; var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { @@ -19,6 +20,12 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { value: "" }, + folderUri:{ + enumerable: true, + writable: true, + value: "" + }, + callback : { enumerable: true, writable: true, @@ -42,10 +49,48 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { 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=""; + } } }, @@ -66,29 +111,40 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { var filename = this.fileName, newFileDirectory = this.newFileDirectory, success = true; - 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); + 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); } - }catch(e){ - success = false; - console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory); - } - if(success){ - //clean up memory - //this.cleanup(); + if(success){ + //clean up memory + //this.cleanup(); - if(this.popup){ - this.popup.hide(); + 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"); } } } @@ -96,31 +152,45 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { isValidUri:{ value: function(uri){ - var isWindowsUri=false, isUnixUri=false,status=false; + var status= fileUtils.isValidUri(uri); if(uri !== ""){ - uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces - - //for local machine folder uri - isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); - isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix - status = isWindowsUri || isUnixUri; - if(isWindowsUri && isUnixUri){status = false;} + if(!status){ + this.showError("! Invalid directory."); + } } return status; } }, isValidFileName:{ value: function(fileName){ - var status = false; + var status = fileUtils.isValidFileName(fileName); 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)); + if(!status){ + this.showError("! Invalid file name."); } } return status; } + }, + checkFileExists:{ + value: function(fileUri, folderUri, fileType){ + var status= fileUtils.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