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