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.css | 100 ++++++++++++ js/io/ui/save-as-dialog.reel/save-as-dialog.html | 86 ++++++++++ js/io/ui/save-as-dialog.reel/save-as-dialog.js | 196 +++++++++++++++++++++++ 3 files changed, 382 insertions(+) create mode 100644 js/io/ui/save-as-dialog.reel/save-as-dialog.css create mode 100644 js/io/ui/save-as-dialog.reel/save-as-dialog.html create mode 100644 js/io/ui/save-as-dialog.reel/save-as-dialog.js (limited to 'js/io/ui/save-as-dialog.reel') diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.css b/js/io/ui/save-as-dialog.reel/save-as-dialog.css new file mode 100644 index 00000000..40434c25 --- /dev/null +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.css @@ -0,0 +1,100 @@ +/* + 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; + height:150px; + padding-left: 15px; + padding-right: 15px; + background-color:#313131; + color: #ffffff; +} + +.saveAsDialog .title{ + font-size:14px; + height:15px; + padding:5px; + text-align: center; + font-weight: bold; + color: #C1C1C1; +} + +.saveAsDialog .locationSelection{ + border: 1px groove #000000; + overflow: auto; + height:38%; + padding: 15px; + background-color:#5f5f5f; +} + +.saveAsDialog .newFileName{ + width:80%; + margin-left:5px; +} + +.saveAsDialog .fileInputField .newFileDirectory{ + width: 80%; +} + +.saveAsDialog .nameText{ + margin-right:10px; +} + +.saveAsDialog .buttons{ + float:right; + margin-top: 10px; +} + +.saveAsDialog .filename{ + margin-bottom: 10px; +} + +.saveAsDialog .errorMsg{ + float:left; + margin-top: 7px; +} +.saveAsDialog .errorMsg span{ + color: #BF3B3B; +} + +.saveAsDialog .fileInputField{ + margin-left:3px; +} + +.saveAsDialog .okButton{ + margin-right:25px; + -webkit-box-align: center; + text-align: center; + cursor: default; + padding: 0px 6px 0px; + border:2px solid #d1d1d1; + background-color: #e1e1e1; + box-sizing: border-box; + border-radius:10px; + background-image: -webkit-linear-gradient(bottom, #e1e1e1 13%, #d1d1d1 58%, #e1e1e1 40%); + cursor:pointer; +} + +.saveAsDialog .cancelButton{ + -webkit-box-align: center; + text-align: center; + cursor: default; + padding: 0px 6px 0px; + border:2px solid #d1d1d1; + background-color: #e1e1e1; + box-sizing: border-box; + border-radius:10px; + background-image: -webkit-linear-gradient(bottom, #e1e1e1 13%, #d1d1d1 58%, #e1e1e1 40%); + cursor:pointer; +} + +.saveAsDialog input[type="button"]:disabled{ + background-color: #a1a1a1; + border:2px solid #a1a1a1; + background-image:none; + cursor:auto; +} \ No newline at end of file diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.html b/js/io/ui/save-as-dialog.reel/save-as-dialog.html new file mode 100644 index 00000000..968512f6 --- /dev/null +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.html @@ -0,0 +1,86 @@ + + + + + + + + + +
+
Save As
+
+
+ Save As : + +
+
+ Location : +
+
+
+
+
+ + +
+ +
+ + \ No newline at end of file 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') 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') 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.html | 33 ++---------------------- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 3 +++ 2 files changed, 5 insertions(+), 31 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel') diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.html b/js/io/ui/save-as-dialog.reel/save-as-dialog.html index 968512f6..f2011a34 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.html +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.html @@ -10,36 +10,6 @@