diff options
Diffstat (limited to 'js/io')
-rw-r--r-- | js/io/utils/file-utils.js | 75 | ||||
-rw-r--r--[-rwxr-xr-x] | js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js | 41 | ||||
-rw-r--r--[-rwxr-xr-x] | js/io/workflow/save-as-dialog.reel/save-as-dialog.css | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | js/io/workflow/save-as-dialog.reel/save-as-dialog.html | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | js/io/workflow/save-as-dialog.reel/save-as-dialog.js | 138 |
5 files changed, 193 insertions, 71 deletions
diff --git a/js/io/utils/file-utils.js b/js/io/utils/file-utils.js new file mode 100644 index 00000000..0afdffc6 --- /dev/null +++ b/js/io/utils/file-utils.js | |||
@@ -0,0 +1,75 @@ | |||
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 | |||
7 | var fileSystem = require("js/io/system/coreioapi").CoreIoApi; | ||
8 | |||
9 | var FileUtils = exports.FileUtils = Object.create(Object.prototype, { | ||
10 | |||
11 | /*** | ||
12 | * checks for valid uri pattern | ||
13 | * also flags if Windows uri pattern and Unix uri patterns are mixed | ||
14 | */ | ||
15 | isValidUri:{ | ||
16 | value: function(uri){ | ||
17 | var isWindowsUri=false, isUnixUri=false,status=false; | ||
18 | if(uri !== ""){ | ||
19 | uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces | ||
20 | |||
21 | //for local machine folder uri | ||
22 | isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); | ||
23 | isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix | ||
24 | status = isWindowsUri || isUnixUri; | ||
25 | if(isWindowsUri && isUnixUri){status = false;} | ||
26 | } | ||
27 | return status; | ||
28 | } | ||
29 | }, | ||
30 | |||
31 | /*** | ||
32 | * file name validation | ||
33 | */ | ||
34 | isValidFileName:{ | ||
35 | value: function(fileName){ | ||
36 | var status = false; | ||
37 | if(fileName !== ""){ | ||
38 | fileName = fileName.replace(/^\s+|\s+$/g,""); | ||
39 | status = !(/[/\\]/g.test(fileName)); | ||
40 | if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden | ||
41 | status = !(/^\./g.test(fileName)); | ||
42 | } | ||
43 | } | ||
44 | return status; | ||
45 | } | ||
46 | }, | ||
47 | |||
48 | /*** | ||
49 | * check if the file exists | ||
50 | */ | ||
51 | checkFileExists:{ | ||
52 | value: function(fileUri, folderUri, fileType){ | ||
53 | var uri = "", response=null, status=true; | ||
54 | |||
55 | //prepare absolute uri | ||
56 | if(/[^/\\]$/g.test(folderUri)){ | ||
57 | folderUri = folderUri + "/"; | ||
58 | } | ||
59 | |||
60 | //todo:add file extension check if fileType present | ||
61 | |||
62 | uri = ""+folderUri+fileUri; | ||
63 | |||
64 | response = fileSystem.fileExists({"uri":uri}); | ||
65 | if(!!response && response.success && (response.status === 204)){ | ||
66 | status = true; | ||
67 | }else if(!!response && response.success && (response.status === 404)){ | ||
68 | status = false; | ||
69 | }else{ | ||
70 | status = false; | ||
71 | } | ||
72 | return status; | ||
73 | } | ||
74 | } | ||
75 | }); \ No newline at end of file | ||
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 index 61b963b3..7702b1a2 100755..100644 --- 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, | |||
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/workflow/newFileDialog/new-file-workflow-controller"), | 11 | newFileLocationSelectionModule = require("js/io/workflow/newFileDialog/new-file-workflow-controller"), |
12 | fileSystem = require("js/io/system/filesystem").FileSystem; | 12 | fileUtils = require("js/io/utils/file-utils").FileUtils; |
13 | 13 | ||
14 | var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, { | 14 | var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, { |
15 | 15 | ||
@@ -244,7 +244,6 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C | |||
244 | this.okButton.setAttribute("disabled", "true"); | 244 | this.okButton.setAttribute("disabled", "true"); |
245 | } | 245 | } |
246 | } | 246 | } |
247 | |||
248 | } | 247 | } |
249 | }, | 248 | }, |
250 | 249 | ||
@@ -336,16 +335,8 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C | |||
336 | 335 | ||
337 | isValidUri:{ | 336 | isValidUri:{ |
338 | value: function(uri){ | 337 | value: function(uri){ |
339 | var isWindowsUri=false, isUnixUri=false,status=false; | 338 | var status= fileUtils.isValidUri(uri); |
340 | if(uri !== ""){ | 339 | if(uri !== ""){ |
341 | uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces | ||
342 | |||
343 | //for local machine folder uri | ||
344 | isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); | ||
345 | isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix | ||
346 | status = isWindowsUri || isUnixUri; | ||
347 | if(isWindowsUri && isUnixUri){status = false;} | ||
348 | |||
349 | if(!status){ | 340 | if(!status){ |
350 | this.showError("! Invalid directory."); | 341 | this.showError("! Invalid directory."); |
351 | } | 342 | } |
@@ -355,14 +346,8 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C | |||
355 | }, | 346 | }, |
356 | isValidFileName:{ | 347 | isValidFileName:{ |
357 | value: function(fileName){ | 348 | value: function(fileName){ |
358 | var status = false; | 349 | var status = fileUtils.isValidFileName(fileName); |
359 | if(fileName !== ""){ | 350 | if(fileName !== ""){ |
360 | fileName = fileName.replace(/^\s+|\s+$/g,""); | ||
361 | status = !(/[/\\]/g.test(fileName)); | ||
362 | if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden | ||
363 | status = !(/^\./g.test(fileName)); | ||
364 | } | ||
365 | |||
366 | if(!status){ | 351 | if(!status){ |
367 | this.showError("! Invalid file name."); | 352 | this.showError("! Invalid file name."); |
368 | } | 353 | } |
@@ -372,25 +357,9 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C | |||
372 | }, | 357 | }, |
373 | checkFileExists:{ | 358 | checkFileExists:{ |
374 | value: function(fileUri, folderUri, fileType){ | 359 | value: function(fileUri, folderUri, fileType){ |
375 | var uri = "", response=null, status=true; | 360 | var status= fileUtils.checkFileExists(fileUri, folderUri, fileType); |
376 | 361 | if(status){ | |
377 | //prepare absolute uri | ||
378 | if(/[^/\\]$/g.test(folderUri)){ | ||
379 | folderUri = folderUri + "/"; | ||
380 | } | ||
381 | |||
382 | //todo:add file extension check | ||
383 | |||
384 | uri = ""+folderUri+fileUri; | ||
385 | |||
386 | response = fileSystem.shellApiHandler.fileExists({"uri":uri}); | ||
387 | if(!!response && response.success && (response.status === 204)){ | ||
388 | this.showError("! File already exists."); | 362 | this.showError("! File already exists."); |
389 | status = true; | ||
390 | }else if(!!response && response.success && (response.status === 404)){ | ||
391 | status = false; | ||
392 | }else{ | ||
393 | this.showError("! Cloud Service Error."); | ||
394 | } | 363 | } |
395 | return status; | 364 | return status; |
396 | } | 365 | } |
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 | } |