From 79b0173eeca079dec42ff1480182656dbe3af44f Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 09:49:23 -0800 Subject: removed usage of NJUtils.js as it is being deleted. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 14 ++++++++++--- .../new-file-options-navigator.js | 24 ++++++++++++++++++---- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 24 ++++++++++++++++++---- 3 files changed, 51 insertions(+), 11 deletions(-) (limited to 'js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index dd62b40b..7cc0eeeb 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -15,7 +15,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, Uuid = require("montage/core/uuid").Uuid, - nj= require("js/lib/NJUtils.js").NJUtils, HTMLDocument = require("js/io/document/html-document").HTMLDocument, TextDocument = require("js/io/document/text-document").TextDocument; @@ -123,7 +122,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); - filename = nj.getFileNameFromPath(uri); + filename = this.getFileNameFromPath(uri); if(uri.indexOf('.') != -1){ fileType = uri.substr(uri.lastIndexOf('.') + 1); } @@ -430,5 +429,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - } + }, + + ///// Return the last part of a path (e.g. filename) + getFileNameFromPath : { + value: function(path) { + path = path.replace(/[/\\]$/g,""); + path = path.replace(/\\/g,"/"); + return path.substr(path.lastIndexOf('/') + 1); + } + } }); \ No newline at end of file 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 467c5452..f17b15d5 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 @@ -8,8 +8,7 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), treeModule = require("js/components/ui/tree-basic/tree.reel"), - newFileLocationSelectionModule = require("js/io/ui/new-file-dialog/new-file-workflow-controller"), - nj= require("js/lib/NJUtils.js").NJUtils; + newFileLocationSelectionModule = require("js/io/ui/new-file-dialog/new-file-workflow-controller"); var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(Component, { @@ -364,7 +363,7 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C }, isValidFileName:{ value: function(fileName){ - var status = nj.isValidFileName(fileName); + var status = this.isValidFileName(fileName); if(fileName !== ""){ if(!status){ this.showError("! Invalid file name."); @@ -391,6 +390,23 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C this.okButton.setAttribute("disabled", "true"); } } - } + }, + + /*** + * 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; + } + } }); \ No newline at end of file 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 b20bed87..1de2eaf1 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 @@ -5,8 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot */ var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - nj= require("js/lib/NJUtils.js").NJUtils; + Component = require("montage/ui/component").Component; var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { @@ -163,7 +162,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { }, isValidFileName:{ value: function(fileName){ - var status = nj.isValidFileName(fileName); + var status = this.isValidFileName(fileName); if(fileName !== ""){ if(!status){ this.showError("! Invalid file name."); @@ -191,6 +190,23 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { this.okButton.setAttribute("disabled", "true"); } } - } + }, + + /*** + * 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; + } + } }); \ No newline at end of file -- cgit v1.2.3