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.js106
1 files changed, 58 insertions, 48 deletions
diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js
index 526578d1..f14857ac 100644..100755
--- 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
21 enumerable:true, 21 enumerable:true,
22 value:function(){ 22 value:function(){
23 var that = this; 23 var that = this;
24 this.eventManager.addEventListener("executeFileOpen", function(evt){
25 24
26 var callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections; 25 this.eventManager.addEventListener("openFilePicker", function(evt){
27 26 var settings;
28 if(!!evt.callback){ 27 if(typeof evt._event.settings !== "undefined"){
29 callback = evt.callback; 28 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 } 29 }
43 if(!!evt.allowNewFileCreation){ 30 that.showFilePicker(settings);
44 allowNewFileCreation = evt.allowNewFileCreation;
45 }
46 if(!!evt.allowMultipleSelections){
47 allowMultipleSelections = evt.allowMultipleSelections;
48 }
49
50 that.showFilePicker(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections);
51
52 }, false); 31 }, false);
32
53 } 33 }
54 }, 34 },
55 35
36 filePickerPopupType:{
37 writable: true,
38 enumerable: false,
39 value: "filePicker"
40 },
41
56 /** 42 /**
57 * this will be stored in the local storage and in the cloud may be, for the cloud one. 43 * this will be stored in the local storage and in the cloud may be, for the cloud one.
58 */ 44 */
@@ -81,14 +67,16 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
81 *this function is used to create an instance of a file picker 67 *this function is used to create an instance of a file picker
82 * 68 *
83 * parameters: 69 * parameters:
84 * callback: the call back function which will be used to send the selected URIs back 70 * 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 71 * 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] 72 * callbackScope : required if callback is set
87 * allFileFilters: list of filters that user can use to filter the view 73 * 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 74 * 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. 75 * allFileFilters [optional]: list of filters that user can use to filter the view
90 * allowMultipleSelections: allowMultipleSelections 76 * 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 77 * 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.
78 * allowMultipleSelections [optional]: allowMultipleSelections
79 * pickerName: name for montage custom popup
92 * 80 *
93 * return: none 81 * return: none
94 */ 82 */
@@ -96,7 +84,19 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
96 showFilePicker:{ 84 showFilePicker:{
97 writable:false, 85 writable:false,
98 enumerable:true, 86 enumerable:true,
99 value:function(callback, pickerMode, currentFilter, allFileFilters,inFileMode, allowNewFileCreation, allowMultipleSelections){ 87 value:function(settings){
88 var callback, callbackScope, pickerMode, currentFilter, allFileFilters, inFileMode, allowNewFileCreation, allowMultipleSelections, pickerName;
89 if(!!settings){
90 if(typeof settings.callback !== "undefined"){callback = settings.callback;}
91 if(typeof settings.callbackScope !== "undefined"){callbackScope = settings.callbackScope;}
92 if(typeof settings.pickerMode !== "undefined"){pickerMode = settings.pickerMode;}
93 if(typeof settings.currentFilter !== "undefined"){currentFilter = settings.currentFilter;}
94 if(typeof settings.allFileFilters !== "undefined"){allFileFilters = settings.allFileFilters;}
95 if(typeof settings.inFileMode !== "undefined"){inFileMode = settings.inFileMode;}
96 if(typeof settings.allowNewFileCreation !== "undefined"){allowNewFileCreation = settings.allowNewFileCreation;}
97 if(typeof settings.allowMultipleSelections !== "undefined"){allowMultipleSelections = settings.allowMultipleSelections;}
98 if(typeof settings.pickerName !== "undefined"){this.filePickerPopupType = settings.pickerName;}
99 }
100 100
101 var aModel = filePickerModelModule.FilePickerModel.create(); 101 var aModel = filePickerModelModule.FilePickerModel.create();
102 102
@@ -114,8 +114,17 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
114 aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]"; 114 aModel.fatalError = " ** Unable to get files [Error: "+ errorCause +"]";
115 } 115 }
116 116
117 aModel.currentFilter = currentFilter; 117 //dummy data - TODO:remove after testing
118 aModel.inFileMode = inFileMode; 118 //aModel.currentFilter = "*.html, *.png";
119 //aModel.currentFilter = "*.jpg";
120 aModel.currentFilter = "*.*";
121 aModel.inFileMode = true;
122 aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"];
123 //-end - dummy data
124
125 if(!!currentFilter){aModel.currentFilter = currentFilter;}
126 if(typeof inFileMode !== "undefined"){aModel.inFileMode = inFileMode;}
127
119 aModel.topLevelDirectories = topLevelDirectories; 128 aModel.topLevelDirectories = topLevelDirectories;
120 129
121 if(!!topLevelDirectories && !!topLevelDirectories[0]){ 130 if(!!topLevelDirectories && !!topLevelDirectories[0]){
@@ -136,17 +145,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
136 aModel.currentRoot = unescape(storedUri); 145 aModel.currentRoot = unescape(storedUri);
137 } 146 }
138 147
139 aModel.fileFilters = allFileFilters; 148 if(!!allFileFilters){aModel.fileFilters = allFileFilters;}
140 aModel.callback = callback; 149 if(!!callback){aModel.callback = callback;}
141 aModel.pickerMode = pickerMode; 150 if(!!callbackScope){aModel.callbackScope = callbackScope;}
151 if(typeof pickerMode !== "undefined"){aModel.pickerMode = pickerMode;}
152
142 153
143 //dummy data - TODO:remove after testing
144 //aModel.currentFilter = "*.html, *.png";
145 //aModel.currentFilter = "*.jpg";
146 aModel.currentFilter = "*.*";
147 aModel.inFileMode = true;
148 aModel.fileFilters = [".html, .htm", ".jpg, .jpeg, .png, .gif", ".js, .json", ".css", ".txt, .rtf", ".doc, .docx", ".pdf", ".avi, .mov, .mpeg, .ogg, .webm", "*.*"];
149 //-end - dummy data
150 154
151 //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. 155 //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.
152 this.openFilePickerAsModal(callback, aModel); 156 this.openFilePickerAsModal(callback, aModel);
@@ -172,6 +176,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
172 176
173 var pickerNavChoices = Montage.create(pickerNavigatorReel); 177 var pickerNavChoices = Montage.create(pickerNavigatorReel);
174 var initUri = aModel.currentRoot; 178 var initUri = aModel.currentRoot;
179
180 //remove extra / at the end
181 if((initUri.length > 1) && (initUri.charAt(initUri.length - 1) === "/")){
182 initUri = initUri.substring(0, (initUri.length - 1));
183 }
184
175 pickerNavChoices.mainContentData = this.prepareContentList(initUri, aModel); 185 pickerNavChoices.mainContentData = this.prepareContentList(initUri, aModel);
176 pickerNavChoices.pickerModel = aModel; 186 pickerNavChoices.pickerModel = aModel;
177 pickerNavChoices.element = pickerNavContent; 187 pickerNavChoices.element = pickerNavContent;
@@ -182,8 +192,8 @@ var FilePickerController = exports.FilePickerController = Montage.create(require
182 var popup = Popup.create(); 192 var popup = Popup.create();
183 popup.content = pickerNavChoices; 193 popup.content = pickerNavChoices;
184 popup.modal = true; 194 popup.modal = true;
195 popup.type = this.filePickerPopupType;//should be set always to not default to the single custom popup layer
185 popup.show(); 196 popup.show();
186
187 pickerNavChoices.popup = popup;//handle to be used for hiding the popup 197 pickerNavChoices.popup = popup;//handle to be used for hiding the popup
188 } 198 }
189 }, 199 },