diff options
Diffstat (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js')
-rwxr-xr-x[-rw-r--r--] | js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index 299d44f5..eec7c8e8 100644..100755 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | |||
@@ -209,26 +209,27 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
209 | this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly | 209 | this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly |
210 | this.backArrow.addEventListener("click", this, false); | 210 | this.backArrow.addEventListener("click", this, false); |
211 | this.forwardArrow.addEventListener("click", this, false); | 211 | 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 | 212 | ||
229 | var renderedWidth = this.getComputedWidth(filtersDD); | 213 | //populate filters if in file selection mode |
230 | this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; | 214 | if(this.pickerModel.inFileMode === true){ |
215 | var filtersDD = this.element.querySelector(".filters .dropdown"); | ||
216 | if(!!this.pickerModel.fileFilters | ||
217 | && (typeof this.pickerModel.fileFilters === "object") | ||
218 | && ('splice' in this.pickerModel.fileFilters) | ||
219 | && ('join' in this.pickerModel.fileFilters)){ | ||
220 | this.pickerModel.fileFilters.forEach(function(aFilter){ | ||
221 | var newDiv = document.createElement("div"); | ||
222 | newDiv.innerHTML = aFilter; | ||
223 | filtersDD.appendChild(newDiv); | ||
224 | newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); | ||
225 | }, this); | ||
226 | } | ||
231 | 227 | ||
228 | var renderedWidth = this.getComputedWidth(filtersDD); | ||
229 | this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; | ||
230 | }else{ | ||
231 | this.filters.style.display = "none"; | ||
232 | } | ||
232 | /** | 233 | /** |
233 | * attach click event listeners to the addressbar dropdown arrows | 234 | * attach click event listeners to the addressbar dropdown arrows |
234 | */ | 235 | */ |
@@ -263,11 +264,11 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
263 | } | 264 | } |
264 | }, | 265 | }, |
265 | 266 | ||
266 | //TODO: add uri pattern validation | 267 | cleanupUri:{ |
267 | validateUri:{ | ||
268 | writable: false, | 268 | writable: false, |
269 | enumerable:true, | 269 | enumerable:true, |
270 | value: function(folderUri){ | 270 | value: function(folderUri){ |
271 | 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 | 272 | //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 !== "/")){ | 273 | if(((folderUri.charAt(folderUri.length - 1) === "/") || (folderUri.charAt(folderUri.length - 1) === "\\")) && (folderUri !== "/")){ |
273 | folderUri = folderUri.substring(0, (folderUri.length - 1)); | 274 | folderUri = folderUri.substring(0, (folderUri.length - 1)); |
@@ -324,7 +325,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
324 | writable:false, | 325 | writable:false, |
325 | enumerable:true, | 326 | enumerable:true, |
326 | value:function(uri){ | 327 | value:function(uri){ |
327 | uri = this.validateUri(uri); | 328 | uri = this.cleanupUri(uri); |
328 | var arr = []; | 329 | var arr = []; |
329 | var temp = new String(uri); | 330 | var temp = new String(uri); |
330 | while(temp.indexOf("/") != -1){ | 331 | while(temp.indexOf("/") != -1){ |
@@ -532,8 +533,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
532 | this.refreshButton.identifier = "refreshButton"; | 533 | this.refreshButton.identifier = "refreshButton"; |
533 | this.backArrow.identifier = "backArrow"; | 534 | this.backArrow.identifier = "backArrow"; |
534 | this.forwardArrow.identifier = "forwardArrow"; | 535 | this.forwardArrow.identifier = "forwardArrow"; |
535 | this.okButton.identifier = "okButton"; | ||
536 | this.cancelButton.identifier = "cancelButton"; | ||
537 | this.iconView.identifier = "iconView"; | 536 | this.iconView.identifier = "iconView"; |
538 | this.treeView.identifier = "treeView"; | 537 | this.treeView.identifier = "treeView"; |
539 | this.resultsArea.identifier = "resultsArea"; | 538 | this.resultsArea.identifier = "resultsArea"; |
@@ -651,7 +650,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
651 | 650 | ||
652 | if(this.addressBarUri.value !== ""){ | 651 | if(this.addressBarUri.value !== ""){ |
653 | var uri = this.addressBarUri.value; | 652 | var uri = this.addressBarUri.value; |
654 | uri = this.validateUri(uri); | 653 | uri = this.cleanupUri(uri); |
655 | 654 | ||
656 | this.currentURI = uri; | 655 | this.currentURI = uri; |
657 | var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view | 656 | var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view |
@@ -676,7 +675,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
676 | value: function(evt){ | 675 | value: function(evt){ |
677 | if(evt.keyCode === 13 ){ | 676 | if(evt.keyCode === 13 ){ |
678 | var uri = this.addressBarUri.value; | 677 | var uri = this.addressBarUri.value; |
679 | uri = this.validateUri(uri); | 678 | uri = this.cleanupUri(uri); |
680 | 679 | ||
681 | this.currentURI = uri; | 680 | this.currentURI = uri; |
682 | 681 | ||
@@ -699,7 +698,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
699 | handleRefreshButtonClick:{ | 698 | handleRefreshButtonClick:{ |
700 | value:function(evt){ | 699 | value:function(evt){ |
701 | var uri = this.addressBarUri.value; | 700 | var uri = this.addressBarUri.value; |
702 | uri = this.validateUri(uri); | 701 | uri = this.cleanupUri(uri); |
703 | 702 | ||
704 | var status = this.pickerViews()[this.selectedPickerView].call(this, uri, false);//dynamically calls the update function of the current picker view | 703 | var status = this.pickerViews()[this.selectedPickerView].call(this, uri, false);//dynamically calls the update function of the current picker view |
705 | 704 | ||
@@ -768,22 +767,22 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
768 | } | 767 | } |
769 | }, | 768 | }, |
770 | 769 | ||
771 | handleOkButtonClick : { | 770 | handleOkButtonAction : { |
772 | value: function(evt){ | 771 | value: function(evt){ |
773 | alert("selected "+ this.selectedItems.toString()); | 772 | console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); |
774 | var success = true; | 773 | var success = true; |
775 | if(!!this.pickerModel.callback && (this.selectedItems.length > 0)){//call the callback if it is available | 774 | if(!!this.pickerModel.callback && !!this.pickerModel.callbackScope && (this.selectedItems.length > 0)){//call the callback if it is available |
776 | try{ | 775 | try{ |
777 | this.pickerModel.callback({"uri":this.selectedItems}); | 776 | this.pickerModel.callback.call(this.pickerModel.callbackScope, {"uri":this.selectedItems}); |
778 | }catch(e){ | 777 | }catch(e){ |
779 | success = false; | 778 | success = false; |
780 | console.log("[ERROR] File IO failed to open URIs: "+ this.selectedItems.toString()); | 779 | console.log(e.stack); |
781 | } | 780 | } |
782 | }else{//else send an event with the selected files | 781 | }else{//else send an event with the selected files |
783 | var pickerSelectionEvent = document.createEvent("Events"); | 782 | var pickerSelectionEvent = document.createEvent("Events"); |
784 | pickerSelectionEvent.initEvent("pickerSelectionsDone", false, false); | 783 | pickerSelectionEvent.initEvent("pickerSelectionsDone", false, false); |
785 | pickerSelectionEvent.selectedItems = this.selectedItems; | 784 | pickerSelectionEvent.selectedItems = this.selectedItems; |
786 | document.dispatchEvent(pickerSelectionEvent);//TODO: use eventManager when it is available | 785 | this.eventManager.dispatchEvent(pickerSelectionEvent); |
787 | } | 786 | } |
788 | 787 | ||
789 | //store last opened/saved folder, and view after IO is successful | 788 | //store last opened/saved folder, and view after IO is successful |
@@ -813,7 +812,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
813 | } | 812 | } |
814 | }, | 813 | }, |
815 | 814 | ||
816 | handleCancelButtonClick :{ | 815 | handleCancelButtonAction :{ |
817 | value:function(evt){ | 816 | value:function(evt){ |
818 | //clean up memory | 817 | //clean up memory |
819 | this.cleanup(); | 818 | this.cleanup(); |
@@ -1005,8 +1004,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { | |||
1005 | this.refreshButton.removeEventListener("click", this, false);//refresh - gets from file system directly | 1004 | this.refreshButton.removeEventListener("click", this, false);//refresh - gets from file system directly |
1006 | this.backArrow.removeEventListener("click", this, false); | 1005 | this.backArrow.removeEventListener("click", this, false); |
1007 | this.forwardArrow.removeEventListener("click", this, false); | 1006 | this.forwardArrow.removeEventListener("click", this, false); |
1008 | this.okButton.removeEventListener("click", this, false); | ||
1009 | this.cancelButton.removeEventListener("click", this, false); | ||
1010 | this.iconView.removeEventListener("click", this, false); | 1007 | this.iconView.removeEventListener("click", this, false); |
1011 | this.treeView.removeEventListener("click", this, false); | 1008 | this.treeView.removeEventListener("click", this, false); |
1012 | this.element.removeEventListener("drawTree", this, false); | 1009 | this.element.removeEventListener("drawTree", this, |