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 --- .../file-input-field.reel/file-input-field.js | 3 +- .../ui/FilePicker/file-picker-controller.js | 50 ++++++++-------------- .../pickerNavigator.reel/pickerNavigator.js | 37 ++++++++-------- 3 files changed, 38 insertions(+), 52 deletions(-) (limited to 'js/components') diff --git a/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js b/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js index 8710de63..235be8ad 100755 --- a/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js +++ b/js/components/ui/FilePicker/file-input-field.reel/file-input-field.js @@ -70,8 +70,7 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { settings.inFileMode = true; settings.pickerName = this.pickerName || "fileSelector"; } - settings.callback = this.filePickerCallback; - settings.callbackScope = this; + settings.callback = this.filePickerCallback.bind(this); openFilePicker.settings = settings; this.eventManager.dispatchEvent(openFilePicker); } 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){ diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index d7a19c14..ff9c7073 100644 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -7,7 +7,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, iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), - filePickerControllerModule = require("js/components/ui/FilePicker/file-picker-controller"), treeModule = require("js/components/ui/tree-basic/tree.reel"); var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { @@ -335,7 +334,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { temp = temp.substring(0, temp.lastIndexOf("/")); //populate dropdown irrespective of validity -// if(!!filePickerControllerModule.FilePickerController._directoryContentCache[temp]){//check if it is a valid location +// if(!!this.application.ninja.filePickerController._directoryContentCache[temp]){//check if it is a valid location // arr.push(temp); // }else{ // break; @@ -358,7 +357,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value:function(element, uri){ if(!!element){ var tree = treeModule.Tree.create(); - tree.treeViewDataObject = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + tree.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); //console.log("renderTree() for "+ uri); //console.log(tree.treeViewDataObject); tree.element = element; @@ -374,10 +373,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { var status = true; var iconViewContainer = this.element.querySelector(".iconViewContainer"); if((typeof fromCache === 'undefined') || (fromCache === true)){ - this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); } else{ - this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); + this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); } if(!!this.newContent && this.newContent.length > 0){ //clear selection @@ -423,10 +422,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { if(!!treeViewContainer){ var data = []; if((typeof fromCache === 'undefined') || (fromCache === true)){ - data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); } else{ - data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); + data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); } if(data.length > 0){ @@ -475,7 +474,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { enumerable: false, writable:false, value:function(currentUri){ - var data = filePickerControllerModule.FilePickerController._directoryContentCache[currentUri]; + var data = this.application.ninja.filePickerController._directoryContentCache[currentUri]; var metadata = ""; if(!!data){ if(data.name !== ""){ @@ -610,8 +609,8 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.currentSelectedNode = null; } //enable OK button if the selection is valid as per the picker mode - if((this.pickerModel.inFileMode && (filePickerControllerModule.FilePickerController._directoryContentCache[uri].type === "file")) - || (!this.pickerModel.inFileMode && (filePickerControllerModule.FilePickerController._directoryContentCache[uri].type === "directory"))){ + if((this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "file")) + || (!this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "directory"))){ this.okButton.removeAttribute("disabled"); //put into selectedItems..currently single selection is supported @@ -784,9 +783,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value: function(evt){ console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); var success = true; - if(!!this.pickerModel.callback && !!this.pickerModel.callbackScope && (this.selectedItems.length > 0)){//call the callback if it is available + if(!!this.pickerModel.callback && (this.selectedItems.length > 0)){//call the callback if it is available try{ - this.pickerModel.callback.call(this.pickerModel.callbackScope, {"uri":this.selectedItems}); + this.pickerModel.callback({"uri":this.selectedItems}); }catch(e){ success = false; console.log("[Error] Failed to open "+ this.selectedItems.toString()); @@ -803,12 +802,12 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { var dataStore = window.sessionStorage; try { if(this.pickerModel.pickerMode === "write"){ - filePickerControllerModule.FilePickerController._lastSavedFolderURI.lastSavedFolderUri_local = this.currentURI; dataStore.setItem('lastSavedFolderURI',escape(""+this.currentURI)); } - else{ - filePickerControllerModule.FilePickerController._lastOpenedFolderURI.lastFolderUri_local = this.currentURI; - dataStore.setItem('lastOpenedFolderURI',escape(""+this.currentURI)); + else if(this.pickerModel.inFileMode === true){ + dataStore.setItem('lastOpenedFolderURI_fileSelection',escape(""+this.currentURI)); + }else if(this.pickerModel.inFileMode === false){ + dataStore.setItem('lastOpenedFolderURI_folderSelection',escape(""+this.currentURI)); } } catch(e){ @@ -962,9 +961,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { handlePickerNavRefreshTreeSegment:{ value: function(evt){ -// if(filePickerControllerModule.FilePickerController.checkIfStale(evt.uri)){ +// if(this.application.ninja.filePickerController.checkIfStale(evt.uri)){ // //update tree segment if was stale -// evt.treeSegment.treeViewDataObject = filePickerControllerModule.FilePickerController.prepareContentList(evt.uri, this.pickerModel, true, false); +// evt.treeSegment.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(evt.uri, this.pickerModel, true, false); // } } }, @@ -1007,7 +1006,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value:function(){ //clear memory - TODO:check for more memory leaks this.pickerModel = null; - filePickerControllerModule.FilePickerController._directoryContentCache = {}; + this.application.ninja.filePickerController._directoryContentCache = {}; //remove listeners this.element.removeEventListener("openFolder", this, false);//add icon double click event listener to reload iconList with new set of data this.element.removeEventListener("selectedItem", this, false);//for single selection only -- cgit v1.2.3