aboutsummaryrefslogtreecommitdiff
path: root/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js')
-rw-r--r--js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js74
1 files changed, 56 insertions, 18 deletions
diff --git a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js
index 3a2e3e96..2f148621 100644
--- a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js
+++ b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js
@@ -9,7 +9,6 @@ var Montage = require("montage/core/core").Montage,
9 iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), 9 iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"),
10 treeModule = require("js/components/ui/tree-basic/tree.reel"), 10 treeModule = require("js/components/ui/tree-basic/tree.reel"),
11 newFileLocationSelectionModule = require("js/io/ui/new-file-dialog/new-file-workflow-controller"); 11 newFileLocationSelectionModule = require("js/io/ui/new-file-dialog/new-file-workflow-controller");
12 //nj= ("js/lib/NJUtils.js").NJUtils;
13 12
14var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, { 13var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, {
15 14
@@ -82,6 +81,9 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
82 this.eventManager.addEventListener("newFileDirectorySet", function(evt){that.handleNewFileDirectorySet(evt);}, false); 81 this.eventManager.addEventListener("newFileDirectorySet", function(evt){that.handleNewFileDirectorySet(evt);}, false);
83 this.eventManager.addEventListener("newFileNameSet", function(evt){that.handleNewFileNameSet(evt);}, false); 82 this.eventManager.addEventListener("newFileNameSet", function(evt){that.handleNewFileNameSet(evt);}, false);
84 83
84 this.okButton.addEventListener("click", function(evt){that.handleOkButtonAction(evt);}, false);
85 this.cancelButton.addEventListener("click", function(evt){that.handleCancelButtonAction(evt);}, false);
86
85 if(!!this.newFileModel.defaultProjectType){ 87 if(!!this.newFileModel.defaultProjectType){
86 var templates = this.newFileModel.prepareContents(this.newFileModel.defaultProjectType); 88 var templates = this.newFileModel.prepareContents(this.newFileModel.defaultProjectType);
87 this.templateList = iconsListModule.IconsList.create(); 89 this.templateList = iconsListModule.IconsList.create();
@@ -92,6 +94,14 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
92 94
93 this.selectedProjectType = {"uri":this.newFileModel.defaultProjectType, "element":null}; 95 this.selectedProjectType = {"uri":this.newFileModel.defaultProjectType, "element":null};
94 } 96 }
97
98 //update file Extension
99 if(!!this.newFileModel.projectTypeData[this.newFileModel.defaultProjectType].fileExtension){
100 var fileExtensionEl = this.element.querySelector(".fileExtension");
101 if(!!fileExtensionEl){
102 fileExtensionEl.innerHTML = ""+this.newFileModel.projectTypeData[this.newFileModel.defaultProjectType].fileExtension;
103 }
104 }
95 } 105 }
96 106
97 }, 107 },
@@ -128,7 +138,15 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
128 138
129 //clear current template selection 139 //clear current template selection
130 if((!!this.selectedTemplate) && (this.selectedTemplate.element.classList.contains("selected"))){ 140 if((!!this.selectedTemplate) && (this.selectedTemplate.element.classList.contains("selected"))){
131 this.selectedTemplate.element.classList.remove("selected"); 141 this.selectedTemplate.element.classList.remove("selected");
142 }
143
144 //update file Extension
145 if(!!this.newFileModel.projectTypeData[evt.uri].fileExtension){
146 var fileExtensionEl = this.element.querySelector(".fileExtension");
147 if(!!fileExtensionEl){
148 fileExtensionEl.innerHTML = ""+this.newFileModel.projectTypeData[evt.uri].fileExtension;
149 }
132 } 150 }
133 151
134 //disable ok 152 //disable ok
@@ -186,6 +204,7 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
186 projectWidth = this.newFileLocation.templateWidth, 204 projectWidth = this.newFileLocation.templateWidth,
187 projectHeight = this.newFileLocation.templateHeight, 205 projectHeight = this.newFileLocation.templateHeight,
188 206
207 newFilePath = "", fileExtension=this.newFileModel.projectTypeData[selectedProjectTypeID].fileExtension,
189 208
190 selectionlog= "selectedProjectTypeID="+selectedProjectTypeID +"\n"+ 209 selectionlog= "selectedProjectTypeID="+selectedProjectTypeID +"\n"+
191 "templateID="+templateID+ "\n"+ 210 "templateID="+templateID+ "\n"+
@@ -194,29 +213,31 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
194 "projectWidth="+projectWidth+"\n"+ 213 "projectWidth="+projectWidth+"\n"+
195 "projectHeight="+projectHeight; 214 "projectHeight="+projectHeight;
196 215
216
217 if(/[^/\\]$/g.test(projectDirectory)){
218 projectDirectory = projectDirectory + "/";
219 }
220 if(!!fileExtension && (projectName.lastIndexOf(fileExtension) !== (projectName.length - fileExtension.length))){
221 projectName = projectName+fileExtension;
222 }
223 newFilePath = "" + projectDirectory + projectName;
224
225
197 if(!!this.selectedProjectType && !!this.selectedTemplate 226 if(!!this.selectedProjectType && !!this.selectedTemplate
198 && this.isValidFileName(projectName) && this.isValidUri(projectDirectory) 227 && this.isValidFileName(projectName) && this.isValidUri(projectDirectory)
199 && !this.checkFileExists(projectName, projectDirectory, this.selectedProjectType) 228 && !this.checkFileExists(projectName, projectDirectory, this.selectedProjectType)
200 ){ 229 ){
201 this.error.innerHTML=""; 230 this.error.innerHTML="";
202 console.log("$$$ new file selections: \n" + selectionlog); 231 //console.log("$$$ new file selections: \n" + selectionlog);
203 if(!!this.newFileModel.callback && !!this.newFileModel.callbackScope){//inform document-controller if save successful 232 if(!!this.newFileModel.callback && !!this.newFileModel.callbackScope){//inform document-controller if save successful
204 this.newFileModel.callback.call(this.newFileModel.callbackScope, {"selectedProjectTypeID":selectedProjectTypeID, 233 this.newFileModel.callback.call(this.newFileModel.callbackScope, {"fileTemplateUri":selectedProjectTypeID,
205 "templateID":templateID, 234 "newFilePath":newFilePath,
206 "projectName": projectName, 235 "fileExtension":fileExtension});//document-controller api
207 "projectDirectory":projectDirectory,
208 "projectWidth":projectWidth,
209 "projectHeight":projectHeight});//document-controller api
210 }else{ 236 }else{
211 //send selection event 237 //send selection event
212 var newFileSelectionEvent = document.createEvent("Events"); 238 var newFileSelectionEvent = document.createEvent("Events");
213 newFileSelectionEvent.initEvent("createNewFile", false, false); 239 newFileSelectionEvent.initEvent("createNewFile", false, false);
214 newFileSelectionEvent.newFileOptions = {"selectedProjectTypeID":selectedProjectTypeID, 240 newFileSelectionEvent.newFileOptions = {"fileTemplateUri":selectedProjectTypeID, "newFilePath":newFilePath,"fileExtension":fileExtension};
215 "templateID":templateID,
216 "projectName": projectName,
217 "projectDirectory":projectDirectory,
218 "projectWidth":projectWidth,
219 "projectHeight":projectHeight};
220 this.eventManager.dispatchEvent(newFileSelectionEvent); 241 this.eventManager.dispatchEvent(newFileSelectionEvent);
221 } 242 }
222 //store last selected project type 243 //store last selected project type
@@ -306,7 +327,7 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
306 327
307 if(!!this.selectedProjectType && !!this.selectedTemplate 328 if(!!this.selectedProjectType && !!this.selectedTemplate
308 && this.isValidFileName(this.newFileName) && this.isValidUri(this.newFileDirectory) 329 && this.isValidFileName(this.newFileName) && this.isValidUri(this.newFileDirectory)
309 && !this.checkFileExists(this.newFileName, this.newFileDirectory, this.selectedProjectType) 330 && !this.checkFileExists(this.newFileName, this.newFileDirectory, this.newFileModel.projectTypeData[this.selectedProjectType.uri].fileExtension)
310 ){ 331 ){
311 status = true; 332 status = true;
312 this.okButton.removeAttribute("disabled"); 333 this.okButton.removeAttribute("disabled");
@@ -346,7 +367,7 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
346 }, 367 },
347 isValidFileName:{ 368 isValidFileName:{
348 value: function(fileName){ 369 value: function(fileName){
349 var status = nj.isValidFileName(fileName); 370 var status = this.isValidFileName(fileName);
350 if(fileName !== ""){ 371 if(fileName !== ""){
351 if(!status){ 372 if(!status){
352 this.showError("! Invalid file name."); 373 this.showError("! Invalid file name.");
@@ -373,6 +394,23 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C
373 this.okButton.setAttribute("disabled", "true"); 394 this.okButton.setAttribute("disabled", "true");
374 } 395 }
375 } 396 }
376 } 397 },
398
399 /***
400 * file name validation
401 */
402 isValidFileName:{
403 value: function(fileName){
404 var status = false;
405 if(fileName !== ""){
406 fileName = fileName.replace(/^\s+|\s+$/g,"");
407 status = !(/[/\\]/g.test(fileName));
408 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
409 status = !(/^\./g.test(fileName));
410 }
411 }
412 return status;
413 }
414 }
377 415
378}); \ No newline at end of file