From 92161460a6cbbdebfd1b0263ec6eb790091920a9 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:18:21 -0800 Subject: Moving changes from Gerrit, on 1/27, to the github branch: - added file existence check and validation to save as dialog - minor css fix for file picker, new file dialog Signed-off-by: Ananya Sen --- js/io/utils/file-utils.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 js/io/utils/file-utils.js (limited to 'js/io/utils/file-utils.js') diff --git a/js/io/utils/file-utils.js b/js/io/utils/file-utils.js new file mode 100644 index 00000000..c43fb41c --- /dev/null +++ b/js/io/utils/file-utils.js @@ -0,0 +1,75 @@ +/* +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 fileSystem = require("js/io/system/filesystem").FileSystem; + +var FileUtils = exports.FileUtils = Object.create(Object.prototype, { + + /*** + * checks for valid uri pattern + * also flags if Windows uri pattern and Unix uri patterns are mixed + */ + isValidUri:{ + value: function(uri){ + var isWindowsUri=false, isUnixUri=false,status=false; + if(uri !== ""){ + uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces + + //for local machine folder uri + isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); + isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix + status = isWindowsUri || isUnixUri; + if(isWindowsUri && isUnixUri){status = false;} + } + return status; + } + }, + + /*** + * 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; + } + }, + + /*** + * check if the file exists + */ + checkFileExists:{ + value: function(fileUri, folderUri, fileType){ + var uri = "", response=null, status=true; + + //prepare absolute uri + if(/[^/\\]$/g.test(folderUri)){ + folderUri = folderUri + "/"; + } + + //todo:add file extension check if fileType present + + uri = ""+folderUri+fileUri; + + response = fileSystem.shellApiHandler.fileExists({"uri":uri}); + if(!!response && response.success && (response.status === 204)){ + status = true; + }else if(!!response && response.success && (response.status === 404)){ + status = false; + }else{ + status = false; + } + return status; + } + } +}); \ No newline at end of file -- cgit v1.2.3 From fcd9d2f2fd63c11160fcabdc8a554a1b2a81cc47 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:41:56 -0800 Subject: calling coreioapi.js directly since filesystem.js will be deleted Signed-off-by: Ananya Sen --- js/io/utils/file-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/io/utils/file-utils.js') diff --git a/js/io/utils/file-utils.js b/js/io/utils/file-utils.js index c43fb41c..0afdffc6 100644 --- a/js/io/utils/file-utils.js +++ b/js/io/utils/file-utils.js @@ -4,7 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var fileSystem = require("js/io/system/filesystem").FileSystem; +var fileSystem = require("js/io/system/coreioapi").CoreIoApi; var FileUtils = exports.FileUtils = Object.create(Object.prototype, { @@ -61,7 +61,7 @@ var FileUtils = exports.FileUtils = Object.create(Object.prototype, { uri = ""+folderUri+fileUri; - response = fileSystem.shellApiHandler.fileExists({"uri":uri}); + response = fileSystem.fileExists({"uri":uri}); if(!!response && response.success && (response.status === 204)){ status = true; }else if(!!response && response.success && (response.status === 404)){ -- cgit v1.2.3