From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- .../ui/FilePicker/file-picker-controller.js | 106 +++++++++++---------- 1 file changed, 58 insertions(+), 48 deletions(-) mode change 100644 => 100755 js/components/ui/FilePicker/file-picker-controller.js (limited to 'js/components/ui/FilePicker/file-picker-controller.js') diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js old mode 100644 new mode 100755 index 526578d1..f14857ac --- a/js/components/ui/FilePicker/file-picker-controller.js +++ b/js/components/ui/FilePicker/file-picker-controller.js @@ -21,38 +21,24 @@ var FilePickerController = exports.FilePickerController = Montage.create(require enumerable:true, value:function(){ var that = this; - this.eventManager.addEventListener("executeFileOpen", function(evt){ - var callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections; - - if(!!evt.callback){ - callback = evt.callback; - } - if(!!evt.pickerMode){ - pickerMode = evt.pickerMode; - } - if(!!evt.currentFilter){ - currentFilter = evt.currentFilter; - } - if(!!evt.inFileMode){ - inFileMode = evt.inFileMode; - } - if(!!evt.allFileFilters){ - allFileFilters = evt.allFileFilters; + this.eventManager.addEventListener("openFilePicker", function(evt){ + var settings; + if(typeof evt._event.settings !== "undefined"){ + settings = evt._event.settings; } - if(!!evt.allowNewFileCreation){ - allowNewFileCreation = evt.allowNewFileCreation; - } - if(!!evt.allowMultipleSelections){ - allowMultipleSelections = evt.allowMultipleSelections; - } - - that.showFilePicker(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections); - + that.showFilePicker(settings); }, false); + } }, + filePickerPopupType:{ + writable: true, + enumerable: false, + value: "filePicker" + }, + /** * this will be stored in the local storage and in the cloud may be, for the cloud one. */ @@ -81,14 +67,16 @@ var FilePickerController = exports.FilePickerController = Montage.create(require *this function is used to create an instance of a file picker * * parameters: - * callback: the call back function which will be used to send the selected URIs back - * pickerMode: ["read", "write"] : specifies if the file picker is opened to read a file/folder or to save a file - * currentFilter: if a current filter needs to be applied [ex: .psd] - * allFileFilters: list of filters that user can use to filter the view - * inFileMode: true => allow file selection , false => allow directory selection - * allowNewFileCreation: flag to specify whether or not it should return URI(s) to item(s) that do not exist. i.e. a user can type a filename to a new file that doesn't yet exist in the file system. - * allowMultipleSelections: allowMultipleSelections - *rootDirectories: invoker of this function can mention a subset of the allowed root directories to show in the file picker + * settings is an object containing : + * callback [optional]: the call back function which will be used to send the selected URIs back. If undefined then an event is fired with the selected uri + * callbackScope : required if callback is set + * pickerMode [optional]: ["read", "write"] : specifies if the file picker is opened to read a file/folder or to save a file + * currentFilter [optional]: if a current filter needs to be applied [ex: .psd] + * allFileFilters [optional]: list of filters that user can use to filter the view + * inFileMode [optional]: true => allow file selection , false => allow directory selection + * allowNewFileCreation [optional]: flag to specify whether or not it should return URI(s) to item(s) that do not exist. i.e. a user can type a filename to a new file that doesn't yet exist in the file system. + * allowMultipleSelections [optional]: allowMultipleSelections + * pickerName: name for montage custom popup * * return: none */ @@ -96,7 +84,19 @@ var FilePickerController = exports.FilePickerController = Montage.create(require showFilePicker:{ writable:false, enumerable:true, - value:function(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections){ + value:function(settings){ + var callback, callbackScope, pickerMode, currentFilter, allFileFilters, inFileMode, allowNewFileCreation, allowMultipleSelections, pickerName; + if(!!settings){ + if(typeof settings.callback !== "undefined"){callback = settings.callback;} + if(typeof settings.callbackScope !== "undefined"){callbackScope = settings.callbackScope;} + if(typeof settings.pickerMode !== "undefined"){pickerMode = settings.pickerMode;} + if(typeof settings.currentFilter !== "undefined"){currentFilter = settings.currentFilter;} + if(typeof settings.allFileFilters !== "undefined"){allFileFilters = settings.allFileFilters;} + if(typeof settings.inFileMode !== "undefined"){inFileMode = settings.inFileMode;} + if(typeof settings.allowNewFileCreation !== "undefined"){allowNewFileCreation = settings.allowNewFileCreation;} + if(typeof settings.allowMultipleSelections !== "undefined"){allowMultipleSelections = settings.allowMultipleSelections;} + if(typeof settings.pickerName !== "undefined"){this.filePickerPopupType = settings.pickerName;} + } var aModel = filePickerModelModule.FilePickerModel.create(); @@ -114,8 +114,17 @@ var FilePickerController = exports.FilePickerController = Montage.create(require aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]"; } - aModel.currentFilter = currentFilter; - aModel.inFileMode = inFileMode; + //dummy data - TODO:remove after testing + //aModel.currentFilter = "*.html, *.png"; + //aModel.currentFilter = "*.jpg"; + aModel.currentFilter = "*.*"; + aModel.inFileMode = true; + aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"]; + //-end - dummy data + + if(!!currentFilter){aModel.currentFilter = currentFilter;} + if(typeof inFileMode !== "undefined"){aModel.inFileMode = inFileMode;} + aModel.topLevelDirectories = topLevelDirectories; if(!!topLevelDirectories && !!topLevelDirectories[0]){ @@ -136,17 +145,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require aModel.currentRoot = unescape(storedUri); } - aModel.fileFilters = allFileFilters; - aModel.callback = callback; - aModel.pickerMode = pickerMode; + if(!!allFileFilters){aModel.fileFilters = allFileFilters;} + if(!!callback){aModel.callback = callback;} + if(!!callbackScope){aModel.callbackScope = callbackScope;} + if(typeof pickerMode !== "undefined"){aModel.pickerMode = pickerMode;} + - //dummy data - TODO:remove after testing - //aModel.currentFilter = "*.html, *.png"; - //aModel.currentFilter = "*.jpg"; - aModel.currentFilter = "*.*"; - aModel.inFileMode = true; - aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"]; - //-end - dummy data //logic: get file content data onDemand from the REST api for the default or last opened root. Cache the data in page [in local cache ? dirty fs? ]. Filter on client side to reduce network calls. this.openFilePickerAsModal(callback, aModel); @@ -172,6 +176,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var pickerNavChoices = Montage.create(pickerNavigatorReel); var initUri = aModel.currentRoot; + + //remove extra / at the end + if((initUri.length > 1) && (initUri.charAt(initUri.length - 1) === "/")){ + initUri = initUri.substring(0, (initUri.length - 1)); + } + pickerNavChoices.mainContentData = this.prepareContentList(initUri, aModel); pickerNavChoices.pickerModel = aModel; pickerNavChoices.element = pickerNavContent; @@ -182,8 +192,8 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var popup = Popup.create(); popup.content = pickerNavChoices; popup.modal = true; + popup.type = this.filePickerPopupType;//should be set always to not default to the single custom popup layer popup.show(); - pickerNavChoices.popup = popup;//handle to be used for hiding the popup } }, -- 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/components/ui/FilePicker/file-picker-controller.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/components/ui/FilePicker/file-picker-controller.js') diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js index f14857ac..635da3a2 100755 --- a/js/components/ui/FilePicker/file-picker-controller.js +++ b/js/components/ui/FilePicker/file-picker-controller.js @@ -8,7 +8,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator, filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"), - fileSystem = require("js/io/system/filesystem").FileSystem, + fileSystem = require("js/io/system/coreioapi").CoreIoApi, Popup = require("montage/ui/popup/popup.reel").Popup; //singleton with functions to create a new file picker instance and utilities to format or filter the model data @@ -101,7 +101,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var aModel = filePickerModelModule.FilePickerModel.create(); var topLevelDirectories = null; - var driveData = fileSystem.shellApiHandler.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); + var driveData = fileSystem.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); if(driveData.success){ topLevelDirectories = (JSON.parse(driveData.content)).children; }else{ @@ -244,7 +244,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require || !this._directoryContentCache[folderUri].children){ //get data using IO api try{ - var iodata = fileSystem.shellApiHandler.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); @@ -456,7 +456,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require //check for directory staleness.... if stale query filesystem if((new Date()).getTime() > (this._directoryContentCache[folderUri].queriedTimeStamp + this.cacheStaleTime)){ try{ - var ifModifiedResponse = fileSystem.shellApiHandler.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); + var ifModifiedResponse = fileSystem.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); //console.log("ifModifiedResponse"); //console.log(ifModifiedResponse); }catch(e){ @@ -468,7 +468,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require wasStale = true; //uri has changed. so update cache try{ - var iodata = fileSystem.shellApiHandler.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); -- cgit v1.2.3 From 553fce7721cacfd13b6013fdcdd0243c90083b5e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 1 Feb 2012 11:59:11 -0800 Subject: fixed reference to coreioapi cleaning up opening code view tabs Signed-off-by: Ananya Sen --- js/components/ui/FilePicker/file-picker-controller.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'js/components/ui/FilePicker/file-picker-controller.js') diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js index 635da3a2..e71d1460 100755 --- a/js/components/ui/FilePicker/file-picker-controller.js +++ b/js/components/ui/FilePicker/file-picker-controller.js @@ -8,7 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator, filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"), - fileSystem = require("js/io/system/coreioapi").CoreIoApi, Popup = require("montage/ui/popup/popup.reel").Popup; //singleton with functions to create a new file picker instance and utilities to format or filter the model data @@ -101,7 +100,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var aModel = filePickerModelModule.FilePickerModel.create(); var topLevelDirectories = null; - var driveData = fileSystem.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); + var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); if(driveData.success){ topLevelDirectories = (JSON.parse(driveData.content)).children; }else{ @@ -244,7 +243,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require || !this._directoryContentCache[folderUri].children){ //get data using IO api try{ - var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = this.application.ninja.coreIoApi.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); @@ -456,7 +455,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require //check for directory staleness.... if stale query filesystem if((new Date()).getTime() > (this._directoryContentCache[folderUri].queriedTimeStamp + this.cacheStaleTime)){ try{ - var ifModifiedResponse = fileSystem.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); + var ifModifiedResponse = this.application.ninja.coreIoApi.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); //console.log("ifModifiedResponse"); //console.log(ifModifiedResponse); }catch(e){ @@ -468,7 +467,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require wasStale = true; //uri has changed. so update cache try{ - var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = this.application.ninja.coreIoApi.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); -- cgit v1.2.3 From ad0ee69be3512325ede94738f23597086a141a3e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 01:55:30 -0800 Subject: file open and file new integrated again Signed-off-by: Ananya Sen --- .../ui/FilePicker/file-picker-controller.js | 50 ++++++++-------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'js/components/ui/FilePicker/file-picker-controller.js') diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js index e71d1460..0ff20cc8 100755 --- a/js/components/ui/FilePicker/file-picker-controller.js +++ b/js/components/ui/FilePicker/file-picker-controller.js @@ -38,30 +38,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require value: "filePicker" }, - /** - * this will be stored in the local storage and in the cloud may be, for the cloud one. - */ - _lastOpenedFolderURI:{ - writable:true, - enumerable:true, - value:{ - lastFolderUri_local:null, - lastFolderUri_cloud:null - } - }, - - /** - * this will be stored in the local storage and in the cloud may be, for the cloud one. - */ - _lastSavedFolderURI:{ - writable:true, - enumerable:true, - value:{ - lastSavedFolderUri_local:null, - lastSavedFolderUri_cloud:null - } - }, - /** *this function is used to create an instance of a file picker * @@ -87,7 +63,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var callback, callbackScope, pickerMode, currentFilter, allFileFilters, inFileMode, allowNewFileCreation, allowMultipleSelections, pickerName; if(!!settings){ if(typeof settings.callback !== "undefined"){callback = settings.callback;} - if(typeof settings.callbackScope !== "undefined"){callbackScope = settings.callbackScope;} if(typeof settings.pickerMode !== "undefined"){pickerMode = settings.pickerMode;} if(typeof settings.currentFilter !== "undefined"){currentFilter = settings.currentFilter;} if(typeof settings.allFileFilters !== "undefined"){allFileFilters = settings.allFileFilters;} @@ -97,6 +72,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require if(typeof settings.pickerName !== "undefined"){this.filePickerPopupType = settings.pickerName;} } + if(settings.pickerName === "saveAsDirectoryPicker"){//need to set the picker mode in a better way + pickerMode = "write"; + }else{ + pickerMode = "read"; + } + var aModel = filePickerModelModule.FilePickerModel.create(); var topLevelDirectories = null; @@ -131,13 +112,20 @@ var FilePickerController = exports.FilePickerController = Montage.create(require } //populate the last opened folder first, if none then populate default root - var sessionStorage = window.sessionStorage; var storedUri = null; - - if(pickerMode === "write"){ - storedUri = sessionStorage.getItem("lastSavedFolderURI"); - }else{ - storedUri = sessionStorage.getItem("lastOpenedFolderURI"); + var sessionStorage = window.sessionStorage; + try{ + if(pickerMode === "write"){ + storedUri = sessionStorage.getItem("lastSavedFolderURI"); + }else if(inFileMode === true){ + storedUri = sessionStorage.getItem("lastOpenedFolderURI_fileSelection"); + }else if(inFileMode === false){ + storedUri = sessionStorage.getItem("lastOpenedFolderURI_folderSelection"); + } + }catch(e){ + if(e.code == 22){ + sessionStorage.clear(); + } } if(!!storedUri){ -- cgit v1.2.3