aboutsummaryrefslogtreecommitdiff
path: root/js/io/ui/save-as-dialog.reel/save-as-dialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js')
-rw-r--r--js/io/ui/save-as-dialog.reel/save-as-dialog.js111
1 files changed, 86 insertions, 25 deletions
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 c60a92f9..e2f50ff5 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
@@ -16,13 +16,13 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
16 fileName : { 16 fileName : {
17 enumerable: true, 17 enumerable: true,
18 writable: true, 18 writable: true,
19 value: "" 19 value: null
20 }, 20 },
21 21
22 folderUri:{ 22 folderUri:{
23 enumerable: true, 23 enumerable: true,
24 writable: true, 24 writable: true,
25 value: "" 25 value: null
26 }, 26 },
27 27
28 callback : { 28 callback : {
@@ -36,7 +36,12 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
36 writable: true, 36 writable: true,
37 value: null 37 value: null
38 }, 38 },
39 39 prepareForDraw: {
40 value: function() {
41 this.newFileName.value = this.fileName;
42 this.fileInputField.newFileDirectory.value = this.folderUri;
43 }
44 },
40 willDraw: { 45 willDraw: {
41 enumerable: false, 46 enumerable: false,
42 value: function() {} 47 value: function() {}
@@ -51,41 +56,86 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
51 var self = this; 56 var self = this;
52 this.fileInputField.selectDirectory = true; 57 this.fileInputField.selectDirectory = true;
53 this.fileInputField.pickerName = "saveAsDirectoryPicker"; 58 this.fileInputField.pickerName = "saveAsDirectoryPicker";
54 this.newFileName.value = this.fileName;
55 this.fileInputField.newFileDirectory.value = this.folderUri;
56 59
57 this.newFileName.addEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false); 60 this.addEventListener("change@newFileName.value", this.handleNewFileNameChange, false);
61 this.newFileName.element.addEventListener("keyup", this, false);
58 this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); 62 this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false);
59
60 this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); 63 this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false);
61 this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false); 64 this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false);
62 65
66 this.eventManager.addEventListener("enterKey", this, false);
67 this.eventManager.addEventListener("escKey", this, false);
68
69
63 this.enableOk(); 70 this.enableOk();
71
72 this.element.addEventListener("keyup", function(evt){
73 if(evt.keyCode == 27) {//ESC key
74 if(self.application.ninja.newFileController.saveAsDialog !== null){
75 self.handleCancelButtonAction();
76 }
77 }else if((evt.keyCode == 13) && !(evt.ctrlKey || evt.metaKey)){//ENTER key
78 if((self.application.ninja.newFileController.saveAsDialog !== null)
79 && !self.okButton.hasAttribute("disabled")){
80
81 self.handleOkButtonAction();
82 }
83 }
84 }, true);
85
86 this.newFileName.element.focus();
87 this.newFileName.element.select();
88
64 } 89 }
65 }, 90 },
66 91
67 handleNewFileDirectorySet:{ 92 handleNewFileDirectorySet:{
68 value:function(evt){ 93 value:function(evt){
69 if(!!evt._event.newFileDirectory){ 94 this.folderUri = evt._event.newFileDirectory;
70 this.folderUri = evt._event.newFileDirectory; 95 if(this.isValidUri(this.folderUri)){
71 if(this.isValidUri(this.folderUri)){ 96 this.enableOk();
72 this.enableOk();
73 }
74 } 97 }
75 } 98 }
76 }, 99 },
77 100
78 handleNewFileNameOnkeyup:{ 101 handleNewFileNameChange:{
79 value:function(evt){ 102 value:function(evt){
80 this.fileName = this.newFileName.value; 103 this.fileName = this.newFileName.value;
81 if(this.fileName !== ""){ 104 if(this.isValidFileName(this.fileName)){
82 if(this.isValidFileName(this.fileName)){
83 this.enableOk(); 105 this.enableOk();
84 }
85 } 106 }
86 } 107 }
87 }, 108 },
88 109
110 handleKeyup:{
111 value: function(evt){
112 if(evt.keyCode === 13){
113 if(!this.okButton.hasAttribute("disabled")){
114 this.handleOkButtonAction(evt);
115 }
116 }else if(evt.keyCode === 27){
117 this.handleCancelButtonAction(evt);
118 }
119 }
120 },
121
122 handleEnterKey:{
123 value: function(evt){
124 if((this.application.ninja.newFileController.saveAsDialog !== null)
125 && !this.okButton.hasAttribute("disabled")){
126
127 this.handleOkButtonAction(evt);
128 }
129 }
130 },
131
132 handleEscKey:{
133 value: function(evt){
134 if(this.application.ninja.newFileController.saveAsDialog !== null){
135 this.handleCancelButtonAction(evt);
136 }
137 }
138 },
89 139
90 enableOk:{ 140 enableOk:{
91 value: function(){ 141 value: function(){
@@ -99,7 +149,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
99 handleCancelButtonAction :{ 149 handleCancelButtonAction :{
100 value:function(evt){ 150 value:function(evt){
101 //clean up memory 151 //clean up memory
102 //this.cleanup(); 152 this.cleanup();
103 153
104 if(this.popup){ 154 if(this.popup){
105 this.popup.hide(); 155 this.popup.hide();
@@ -134,7 +184,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
134 184
135 if(success){ 185 if(success){
136 //clean up memory 186 //clean up memory
137 //this.cleanup(); 187 this.cleanup();
138 188
139 if(this.popup){ 189 if(this.popup){
140 this.popup.hide(); 190 this.popup.hide();
@@ -155,10 +205,8 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
155 isValidUri:{ 205 isValidUri:{
156 value: function(uri){ 206 value: function(uri){
157 var status= this.application.ninja.coreIoApi.isValidUri(uri); 207 var status= this.application.ninja.coreIoApi.isValidUri(uri);
158 if(uri !== ""){ 208 if((uri !== null) && !status){
159 if(!status){
160 this.showError("! Invalid directory."); 209 this.showError("! Invalid directory.");
161 }
162 } 210 }
163 return status; 211 return status;
164 } 212 }
@@ -166,10 +214,8 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
166 isValidFileName:{ 214 isValidFileName:{
167 value: function(fileName){ 215 value: function(fileName){
168 var status = this.validateFileName(fileName); 216 var status = this.validateFileName(fileName);
169 if(fileName !== ""){ 217 if((fileName !== null) && !status){
170 if(!status){
171 this.showError("! Invalid file name."); 218 this.showError("! Invalid file name.");
172 }
173 } 219 }
174 return status; 220 return status;
175 } 221 }
@@ -218,8 +264,9 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
218 validateFileName:{ 264 validateFileName:{
219 value: function(fileName){ 265 value: function(fileName){
220 var status = false; 266 var status = false;
221 if(fileName !== ""){ 267 if((fileName !== null) && (fileName !== "")){
222 fileName = fileName.replace(/^\s+|\s+$/g,""); 268 fileName = fileName.replace(/^\s+|\s+$/g,"");
269 if(fileName === ""){return false;}
223 status = !(/[/\\]/g.test(fileName)); 270 status = !(/[/\\]/g.test(fileName));
224 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden 271 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
225 status = !(/^\./g.test(fileName)); 272 status = !(/^\./g.test(fileName));
@@ -227,6 +274,20 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
227 } 274 }
228 return status; 275 return status;
229 } 276 }
277 },
278