diff options
Diffstat (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js')
-rw-r--r-- | js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 110 |
1 files changed, 60 insertions, 50 deletions
diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index 299d44f5..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 | |||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component, | 8 | Component = require("montage/ui/component").Component, |
9 | iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), | 9 | iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), |
10 | filePickerControllerModule = require("js/components/ui/FilePicker/file-picker-controller"), | ||
11 | treeModule = require("js/components/ui/tree-basic/tree.reel"); | 10 | treeModule = require("js/components/ui/tree-basic/tree.reel"); |
12 | 11 | ||
13 | var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | 12 | var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { |
@@ -209,26 +208,27 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
209 | this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly | 208 | this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly |
210 | this.backArrow.addEventListener("click", this, false); | 209 | this.backArrow.addEventListener("click", this, false); |
211 | this.forwardArrow.addEventListener("click", this, false); | 210 | this.forwardArrow.addEventListener("click", this, false); |
212 | this.okButton.addEventListener("click", this, false); | ||
213 | this.cancelButton.addEventListener("click", this, false); | ||
214 | |||
215 | //populate filters | ||
216 | var filtersDD = this.element.querySelector(".filters .dropdown"); | ||
217 | if(!!this.pickerModel.fileFilters | ||
218 | && (typeof this.pickerModel.fileFilters === "object") | ||
219 | && ('splice' in this.pickerModel.fileFilters) | ||
220 | && ('join' in this.pickerModel.fileFilters)){ | ||
221 | this.pickerModel.fileFilters.forEach(function(aFilter){ | ||
222 | var newDiv = document.createElement("div"); | ||
223 | newDiv.innerHTML = aFilter; | ||
224 | filtersDD.appendChild(newDiv); | ||
225 | newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); | ||
226 | }, this); | ||
227 | } | ||
228 | 211 | ||
229 | var renderedWidth = this.getComputedWidth(filtersDD); | 212 | //populate filters if in file selection mode |
230 | this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; | 213 | if(this.pickerModel.inFileMode === true){ |
214 | var filtersDD = this.element.querySelector(".filters .dropdown"); | ||
215 | if(!!this.pickerModel.fileFilters | ||
216 | && (typeof this.pickerModel.fileFilters === "object") | ||
217 | && ('splice' in this.pickerModel.fileFilters) | ||
218 | && ('join' in this.pickerModel.fileFilters)){ | ||
219 | this.pickerModel.fileFilters.forEach(function(aFilter){ | ||
220 | var newDiv = document.createElement("div"); | ||
221 | newDiv.innerHTML = aFilter; | ||
222 | filtersDD.appendChild(newDiv); | ||
223 | newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); | ||
224 | }, this); | ||
225 | } | ||
231 | 226 | ||
227 | var renderedWidth = this.getComputedWidth(filtersDD); | ||
228 | this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; | ||
229 | }else{ | ||
230 | this.filters.style.display = "none"; | ||
231 | } | ||
232 | /** | 232 | /** |
233 | * attach click event listeners to the addressbar dropdown arrows | 233 | * attach click event listeners to the addressbar dropdown arrows |
234 | */ | 234 | */ |
@@ -244,6 +244,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
244 | this.resultsArea.addEventListener("click", function(evt){that.handleResultsAreaClick(evt);}, false); | 244 | this.resultsArea.addEventListener("click", function(evt){that.handleResultsAreaClick(evt);}, false); |
245 | this.element.addEventListener("click", function(evt){that.handlePickerNavClick(evt);}, false); | 245 | this.element.addEventListener("click", function(evt){that.handlePickerNavClick(evt);}, false); |
246 | 246 | ||
247 | this.okButton.addEventListener("click", function(evt){that.handleOkButtonAction(evt);}, false); | ||
248 | this.cancelButton.addEventListener("click", function(evt){that.handleCancelButtonAction(evt);}, false); | ||
249 | |||
247 | //ready to show picker now | 250 | //ready to show picker now |
248 | this.element.style.visibility = "visible"; | 251 | this.element.style.visibility = "visible"; |
249 | } | 252 | } |
@@ -263,11 +266,11 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
263 | } | 266 | } |
264 | }, | 267 | }, |
265 | 268 | ||
266 | //TODO: add uri pattern validation | 269 | cleanupUri:{ |
267 | validateUri:{ | ||
268 | writable: false, | 270 | writable: false, |
269 | enumerable:true, | 271 | enumerable:true, |
270 | value: function(folderUri){ | 272 | value: function(folderUri){ |
273 | folderUri = folderUri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces | ||
271 | //remove unnecessary / from end - for Win and Mac .... don't trim for the root | 274 | //remove unnecessary / from end - for Win and Mac .... don't trim for the root |
272 | if(((folderUri.charAt(folderUri.length - 1) === "/") || (folderUri.charAt(folderUri.length - 1) === "\\")) && (folderUri !== "/")){ | 275 | if(((folderUri.charAt(folderUri.length - 1) === "/") || (folderUri.charAt(folderUri.length - 1) === "\\")) && (folderUri !== "/")){ |
273 | folderUri = folderUri.substring(0, (folderUri.length - 1)); | 276 | folderUri = folderUri.substring(0, (folderUri.length - 1)); |
@@ -324,14 +327,14 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
324 | writable:false, | 327 | writable:false, |
325 | enumerable:true, | 328 | enumerable:true, |
326 | value:function(uri){ | 329 | value:function(uri){ |
327 | uri = this.validateUri(uri); | 330 | uri = this.cleanupUri(uri); |
328 | var arr = []; | 331 | var arr = []; |
329 | var temp = new String(uri); | 332 | var temp = new String(uri); |
330 | while(temp.indexOf("/") != -1){ | 333 | while(temp.indexOf("/") != -1){ |
331 | temp = temp.substring(0, temp.lastIndexOf("/")); | 334 | temp = temp.substring(0, temp.lastIndexOf("/")); |
332 | 335 | ||
333 | //populate dropdown irrespective of validity | 336 | //populate dropdown irrespective of validity |
334 | // if(!!filePickerControllerModule.FilePickerController._directoryContentCache[temp]){//check if it is a valid location | 337 | // if(!!this.application.ninja.filePickerController._directoryContentCache[temp]){//check if it is a valid location |
335 | // arr.push(temp); | 338 | // arr.push(temp); |
336 | // }else{ | 339 | // }else{ |
337 | // break; | 340 | // break; |
@@ -354,7 +357,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
354 | value:function(element, uri){ | 357 | value:function(element, uri){ |
355 | if(!!element){ | 358 | if(!!element){ |
356 | var tree = treeModule.Tree.create(); | 359 | var tree = treeModule.Tree.create(); |
357 | tree.treeViewDataObject = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); | 360 | tree.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); |
358 | //console.log("renderTree() for "+ uri); | 361 | //console.log("renderTree() for "+ uri); |
359 | //console.log(tree.treeViewDataObject); | 362 | //console.log(tree.treeViewDataObject); |
360 | tree.element = element; | 363 | tree.element = element; |
@@ -370,10 +373,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
370 | var status = true; | 373 | var status = true; |
371 | var iconViewContainer = this.element.querySelector(".iconViewContainer"); | 374 | var iconViewContainer = this.element.querySelector(".iconViewContainer"); |
372 | if((typeof fromCache === 'undefined') || (fromCache === true)){ | 375 | if((typeof fromCache === 'undefined') || (fromCache === true)){ |
373 | this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); | 376 | this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); |
374 | } | 377 | } |
375 | else{ | 378 | else{ |
376 | this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); | 379 | this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); |
377 | } | 380 | } |
378 | if(!!this.newContent && this.newContent.length > 0){ | 381 | if(!!this.newContent && this.newContent.length > 0){ |
379 | //clear selection | 382 | //clear selection |
@@ -419,10 +422,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
419 | if(!!treeViewContainer){ | 422 | if(!!treeViewContainer){ |
420 | var data = []; | 423 | var data = []; |
421 | if((typeof fromCache === 'undefined') || (fromCache === true)){ | 424 | if((typeof fromCache === 'undefined') || (fromCache === true)){ |
422 | data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); | 425 | data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); |
423 | } | 426 | } |
424 | else{ | 427 | else{ |
425 | data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); | 428 | data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); |
426 | } | 429 | } |
427 | 430 | ||
428 | if(data.length > 0){ | 431 | if(data.length > 0){ |
@@ -471,7 +474,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
471 | enumerable: false, | 474 | enumerable: false, |
472 | writable:false, | 475 | writable:false, |
473 | value:function(currentUri){ | 476 | value:function(currentUri){ |
474 | var data = filePickerControllerModule.FilePickerController._directoryContentCache[currentUri]; | 477 | var data = this.application.ninja.filePickerController._directoryContentCache[currentUri]; |
475 | var metadata = ""; | 478 | var metadata = ""; |
476 | if(!!data){ | 479 | if(!!data){ |
477 | if(data.name !== ""){ | 480 | if(data.name !== ""){ |
@@ -532,8 +535,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
532 | this.refreshButton.identifier = "refreshButton"; | 535 | this.refreshButton.identifier = "refreshButton"; |
533 | this.backArrow.identifier = "backArrow"; | 536 | this.backArrow.identifier = "backArrow"; |
534 | this.forwardArrow.identifier = "forwardArrow"; | 537 | this.forwardArrow.identifier = "forwardArrow"; |
535 | this.okButton.identifier = "okButton"; | ||
536 | this.cancelButton.identifier = "cancelButton"; | ||
537 | this.iconView.identifier = "iconView"; | 538 | this.iconView.identifier = "iconView"; |
538 | this.treeView.identifier = "treeView"; | 539 | this.treeView.identifier = "treeView"; |
539 | this.resultsArea.identifier = "resultsArea"; | 540 | this.resultsArea.identifier = "resultsArea"; |
@@ -608,8 +609,8 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||