aboutsummaryrefslogtreecommitdiff
path: root/js/io/workflow/save-as-dialog.reel
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/workflow/save-as-dialog.reel')
-rw-r--r--[-rwxr-xr-x]js/io/workflow/save-as-dialog.reel/save-as-dialog.css6
-rw-r--r--[-rwxr-xr-x]js/io/workflow/save-as-dialog.reel/save-as-dialog.html4
-rw-r--r--[-rwxr-xr-x]js/io/workflow/save-as-dialog.reel/save-as-dialog.js138
3 files changed, 113 insertions, 35 deletions
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
index 75f57125..7082f485 100755..100644
--- 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 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
1.saveAsDialog{ 7.saveAsDialog{
2 font-size:12px; 8 font-size:12px;
3 width:450px; 9 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
index 1f20ee16..eca6801f 100755..100644
--- 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 @@
54 "properties": { 54 "properties": {
55 "element": {"#": "saveAsDialog"}, 55 "element": {"#": "saveAsDialog"},
56 "fileInputField": {"@": "fileInputField"}, 56 "fileInputField": {"@": "fileInputField"},
57 "newFileName": {"#": "newFileName"} 57 "newFileName": {"#": "newFileName"},
58 "error":{"#": "error"},
59 "okButton":{"#": "okButton"}
58 } 60 }
59 } 61 }
60 } 62 }
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
index 1255a1bd..52e5ab82 100755..100644
--- 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
5</copyright> */ 5</copyright> */
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component; 8 Component = require("montage/ui/component").Component,
9 fileUtils = require("js/io/utils/file-utils").FileUtils;
9 10
10var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { 11var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
11 12
@@ -19,6 +20,12 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
19 value: "" 20 value: ""
20 }, 21 },
21 22
23 folderUri:{
24 enumerable: true,
25 writable: true,
26 value: ""
27 },
28
22 callback : { 29 callback : {
23 enumerable: true, 30 enumerable: true,
24 writable: true, 31 writable: true,
@@ -42,10 +49,48 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
42 didDraw: { 49 didDraw: {
43 enumerable: false, 50 enumerable: false,
44 value: function() { 51 value: function() {
52 var self = this;
45 this.fileInputField.selectDirectory = true; 53 this.fileInputField.selectDirectory = true;
46 this.fileInputField.pickerName = "saveAsDirectoryPicker"; 54 this.fileInputField.pickerName = "saveAsDirectoryPicker";
47 this.newFileName.value = this.fileName; 55 this.newFileName.value = this.fileName;
48 this.fileInputField.newFileDirectory.value = this.folderUri; 56 this.fileInputField.newFileDirectory.value = this.folderUri;
57
58 this.newFileName.addEventListener("blur", function(evt){self.handleNewFileNameOnblur(evt);}, false);
59 this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false);
60
61 this.enableOk();
62 }
63 },
64
65 handleNewFileDirectorySet:{
66 value:function(evt){
67 if(!!evt._event.newFileDirectory){
68 this.folderUri = evt._event.newFileDirectory;
69 if(this.folderUri !== ""){
70 this.enableOk();
71 }
72 }
73 }
74 },
75
76 handleNewFileNameOnblur:{
77 value:function(evt){
78 this.fileName = this.newFileName.value;
79 if(this.fileName !== ""){
80 if(this.fileName !== ""){
81 this.enableOk();
82 }
83 }
84 }
85 },
86
87
88 enableOk:{
89 value: function(){
90 if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){
91 this.okButton.removeAttribute("disabled");
92 this.error.innerHTML="";
93 }
49 } 94 }
50 }, 95 },
51 96
@@ -66,29 +111,40 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
66 var filename = this.fileName, 111 var filename = this.fileName,
67 newFileDirectory = this.newFileDirectory, 112 newFileDirectory = this.newFileDirectory,
68 success = true; 113 success = true;
69 try{ 114 if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){
70 //validate file name and folder path 115 try{
71 //check if file already exists 116 //validate file name and folder path
72 if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful 117 //check if file already exists
73 this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api 118 if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful
74 }else{ 119 this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api
75 //send save as event 120 }else{
76 var saveAsEvent = document.createEvent("Events"); 121 //send save as event
77 saveAsEvent.initEvent("saveAsFile", false, false); 122 var saveAsEvent = document.createEvent("Events");
78 saveAsEvent.saveAsOptions = {"filename":filename, "destination": newFileDirectory}; 123 saveAsEvent.initEvent("saveAsFile", false, false);
79 this.eventManager.dispatchEvent(saveAsEvent); 124 saveAsEvent.saveAsOptions = {"filename":filename, "destination": newFileDirectory};
125 this.eventManager.dispatchEvent(saveAsEvent);
126 }
127 }catch(e){
128 success = false;
129 console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory);
130 console.log(e.stack);
80 } 131 }
81 }catch(e){
82 success = false;
83 console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory);
84 }
85 132
86 if(success){ 133 if(success){
87 //clean up memory 134 //clean up memory
88 //this.cleanup(); 135 //this.cleanup();
89 136
90 if(this.popup){ 137 if(this.popup){
91 this.popup.hide(); 138 this.popup.hide();
139 }
140 }
141 }else{
142 if(this.error.innerHTML !== ""){
143 this.showError("! Name and Location should be valid.");
144 }
145 //disable ok
146 if(!this.okButton.hasAttribute("disabled")){
147 this.okButton.setAttribute("disabled", "true");
92 } 148 }
93 } 149 }
94 } 150 }
@@ -96,31 +152,45 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
96 152
97 isValidUri:{ 153 isValidUri:{
98 value: function(uri){ 154 value: function(uri){
99 var isWindowsUri=false, isUnixUri=false,status=false; 155 var status= fileUtils.isValidUri(uri);
100 if(uri !== ""){ 156 if(uri !== ""){
101 uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces 157 if(!status){
102 158 this.showError("! Invalid directory.");
103 //for local machine folder uri 159 }
104 isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri);
105 isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix
106 status = isWindowsUri || isUnixUri;
107 if(isWindowsUri && isUnixUri){status = false;}
108 } 160 }
109 return status; 161 return status;
110 } 162 }
111 }, 163 },
112 isValidFileName:{ 164 isValidFileName:{
113 value: function(fileName){ 165 value: function(fileName){
114 var status = false; 166 var status = fileUtils.isValidFileName(fileName);
115 if(fileName !== ""){ 167 if(fileName !== ""){
116 fileName = fileName.replace(/^\s+|\s+$/g,""); 168 if(!status){
117 status = !(/[/\\]/g.test(fileName)); 169 this.showError("! Invalid file name.");
118 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
119 status = !(/^\./g.test(fileName));
120 } 170 }
121 } 171 }
122