aboutsummaryrefslogtreecommitdiff
path: root/js/components/ui/FilePicker/file-picker-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/components/ui/FilePicker/file-picker-controller.js')
-rwxr-xr-x[-rw-r--r--]js/components/ui/FilePicker/file-picker-controller.js157
1 files changed, 77 insertions, 80 deletions
diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js
index 526578d1..0ff20cc8 100644..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
8var Montage = require("montage/core/core").Montage, 8var Montage = require("montage/core/core").Montage,
9 pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator, 9 pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator,
10 filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"), 10 filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"),
11 fileSystem = require("js/io/system/filesystem").FileSystem,
12 Popup = require("montage/ui/popup/popup.reel").Popup; 11 Popup = require("montage/ui/popup/popup.reel").Popup;
13 12
14//singleton with functions to create a new file picker instance and utilities to format or filter the model data 13//singleton with functions to create a new file picker instance and utilities to format or filter the model data
@@ -21,74 +20,38 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
21 enumerable:true, 20 enumerable:true,
22 value:function(){ 21 value:function(){
23 var that = this; 22 var that = this;
24 this.eventManager.addEventListener("executeFileOpen", function(evt){
25 23
26 var callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections; 24 this.eventManager.addEventListener("openFilePicker", function(evt){
27 25 var settings;
28 if(!!evt.callback){ 26 if(typeof evt._event.settings !== "undefined"){
29 callback = evt.callback; 27 settings = evt._event.settings;
30 }
31 if(!!evt.pickerMode){
32 pickerMode = evt.pickerMode;
33 }
34 if(!!evt.currentFilter){
35 currentFilter = evt.currentFilter;
36 }
37 if(!!evt.inFileMode){
38 inFileMode = evt.inFileMode;
39 }
40 if(!!evt.allFileFilters){
41 allFileFilters = evt.allFileFilters;
42 }
43 if(!!evt.allowNewFileCreation){
44 allowNewFileCreation = evt.allowNewFileCreation;
45 }
46 if(!!evt.allowMultipleSelections){
47 allowMultipleSelections = evt.allowMultipleSelections;
48 } 28 }
49 29 that.showFilePicker(settings);
50 that.showFilePicker(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections);
51
52 }, false); 30 }, false);
53 }
54 },
55 31
56 /**
57 * this will be stored in the local storage and in the cloud may be, for the cloud one.
58 */
59 _lastOpenedFolderURI:{
60 writable:true,
61 enumerable:true,
62 value:{
63 lastFolderUri_local:null,
64 lastFolderUri_cloud:null
65 } 32 }
66 }, 33 },
67 34
68 /** 35 filePickerPopupType:{
69 * this will be stored in the local storage and in the cloud may be, for the cloud one. 36 writable: true,
70 */ 37 enumerable: false,
71 _lastSavedFolderURI:{ 38 value: "filePicker"
72 writable:true,
73 enumerable:true,
74 value:{
75 lastSavedFolderUri_local:null,
76 lastSavedFolderUri_cloud:null
77 }
78 }, 39 },
79 40
80 /** 41 /**
81 *this function is used to create an instance of a file picker 42 *this function is used to create an instance of a file picker
82 * 43 *
83 * parameters: 44 * parameters:
84 * callback: the call back function which will be used to send the selected URIs back 45 * settings is an object containing :
85 * pickerMode: ["read", "write"] : specifies if the file picker is opened to read a file/folder or to save a file 46 * 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
86 * currentFilter: if a current filter needs to be applied [ex: .psd] 47 * callbackScope : required if callback is set
87 * allFileFilters: list of filters that user can use to filter the view 48 * pickerMode [optional]: ["read", "write"] : specifies if the file picker is opened to read a file/folder or to save a file
88 * inFileMode: true => allow file selection , false => allow directory selection 49 * currentFilter [optional]: if a current filter needs to be applied [ex: .psd]
89 * 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. 50 * allFileFilters [optional]: list of filters that user can use to filter the view
90 * allowMultipleSelections: allowMultipleSelections 51 * inFileMode [optional]: true => allow file selection , false => allow directory selection
91 *rootDirectories: invoker of this function can mention a subset of the allowed root directories to show in the file picker 52 * 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.
53 * allowMultipleSelections [optional]: allowMultipleSelections
54 * pickerName: name for montage custom popup
92 * 55 *
93 * return: none 56 * return: none
94 */ 57 */
@@ -96,12 +59,29 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
96 showFilePicker:{ 59 showFilePicker:{
97 writable:false, 60 writable:false,
98 enumerable:true, 61 enumerable:true,
99 value:function(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections){ 62 value:function(settings){
63 var callback, callbackScope, pickerMode, currentFilter, allFileFilters, inFileMode, allowNewFileCreation, allowMultipleSelections, pickerName;
64 if(!!settings){
65 if(typeof settings.callback !== "undefined"){callback = settings.callback;}
66 if(typeof settings.pickerMode !== "undefined"){pickerMode = settings.pickerMode;}
67 if(typeof settings.currentFilter !== "undefined"){currentFilter = settings.currentFilter;}
68 if(typeof settings.allFileFilters !== "undefined"){allFileFilters = settings.allFileFilters;}
69 if(typeof settings.inFileMode !== "undefined"){inFileMode = settings.inFileMode;}
70 if(typeof settings.allowNewFileCreation !== "undefined"){allowNewFileCreation = settings.allowNewFileCreation;}
71 if(typeof settings.allowMultipleSelections !== "undefined"){allowMultipleSelections = settings.allowMultipleSelections;}
72 if(typeof settings.pickerName !== "undefined"){this.filePickerPopupType = settings.pickerName;}
73 }
74
75 if(settings.pickerName === "saveAsDirectoryPicker"){//need to set the picker mode in a better way
76 pickerMode = "write";
77 }else{
78 pickerMode = "read";
79 }
100 80
101 var aModel = filePickerModelModule.FilePickerModel.create(); 81 var aModel = filePickerModelModule.FilePickerModel.create();
102 82
103 var topLevelDirectories = null; 83 var topLevelDirectories = null;
104 var driveData = fileSystem.shellApiHandler.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); 84 var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"});
105 if(driveData.success){ 85 if(driveData.success){
106 topLevelDirectories = (JSON.parse(driveData.content)).children; 86 topLevelDirectories = (JSON.parse(driveData.content)).children;
107 }else{ 87 }else{
@@ -114,8 +94,17 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
114 aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]"; 94 aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]";
115 } 95 }
116 96
117 aModel.currentFilter = currentFilter; 97 //dummy data - TODO:remove after testing
118 aModel.inFileMode = inFileMode; 98 //aModel.currentFilter = "*.html, *.png";
99 //aModel.currentFilter = "*.jpg";
100 aModel.currentFilter = "*.*";
101 aModel.inFileMode = true;
102 aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"];
103 //-end - dummy data
104
105 if(!!currentFilter){aModel.currentFilter = currentFilter;}
106 if(typeof inFileMode !== "undefined"){aModel.inFileMode = inFileMode;}
107
119 aModel.topLevelDirectories = topLevelDirectories; 108 aModel.topLevelDirectories = topLevelDirectories;
120 109
121 if(!!topLevelDirectories && !!topLevelDirectories[0]){ 110 if(!!topLevelDirectories && !!topLevelDirectories[0]){
@@ -123,30 +112,32 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
123 } 112 }
124 113
125 //populate the last opened folder first, if none then populate default root 114 //populate the last opened folder first, if none then populate default root
126 var sessionStorage = window.sessionStorage;
127 var storedUri = null; 115 var storedUri = null;
128 116 var sessionStorage = window.sessionStorage;
129 if(pickerMode === "write"){ 117 try{
130 storedUri = sessionStorage.getItem("lastSavedFolderURI"); 118 if(pickerMode === "write"){
131 }else{ 119 storedUri = sessionStorage.getItem("lastSavedFolderURI");
132 storedUri = sessionStorage.getItem("lastOpenedFolderURI"); 120 }else if(inFileMode === true){
121 storedUri = sessionStorage.getItem("lastOpenedFolderURI_fileSelection");
122 }else if(inFileMode === false){
123 storedUri = sessionStorage.getItem("lastOpenedFolderURI_folderSelection");
124 }
125 }catch(e){
126 if(e.code == 22){
127 sessionStorage.clear();
128 }
133 } 129 }
134 130
135 if(!!storedUri){ 131 if(!!storedUri){
136 aModel.currentRoot = unescape(storedUri); 132 aModel.currentRoot = unescape(storedUri);
137 } 133 }
138 134
139 aModel.fileFilters = allFileFilters; 135 if(!!allFileFilters){aModel.fileFilters = allFileFilters;}
140 aModel.callback = callback; 136 if(!!callback){aModel.callback = callback;}