From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- .../pickerNavigator.reel/pickerNavigator.js | 67 +++++++++++----------- 1 file changed, 32 insertions(+), 35 deletions(-) mode change 100644 => 100755 js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js old mode 100644 new mode 100755 index 299d44f5..eec7c8e8 --- 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, { this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly this.backArrow.addEventListener("click", this, false); this.forwardArrow.addEventListener("click", this, false); - this.okButton.addEventListener("click", this, false); - this.cancelButton.addEventListener("click", this, false); - - //populate filters - var filtersDD = this.element.querySelector(".filters .dropdown"); - if(!!this.pickerModel.fileFilters - && (typeof this.pickerModel.fileFilters === "object") - && ('splice' in this.pickerModel.fileFilters) - && ('join' in this.pickerModel.fileFilters)){ - this.pickerModel.fileFilters.forEach(function(aFilter){ - var newDiv = document.createElement("div"); - newDiv.innerHTML = aFilter; - filtersDD.appendChild(newDiv); - newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); - }, this); - } - var renderedWidth = this.getComputedWidth(filtersDD); - this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; + //populate filters if in file selection mode + if(this.pickerModel.inFileMode === true){ + var filtersDD = this.element.querySelector(".filters .dropdown"); + if(!!this.pickerModel.fileFilters + && (typeof this.pickerModel.fileFilters === "object") + && ('splice' in this.pickerModel.fileFilters) + && ('join' in this.pickerModel.fileFilters)){ + this.pickerModel.fileFilters.forEach(function(aFilter){ + var newDiv = document.createElement("div"); + newDiv.innerHTML = aFilter; + filtersDD.appendChild(newDiv); + newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); + }, this); + } + var renderedWidth = this.getComputedWidth(filtersDD); + this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; + }else{ + this.filters.style.display = "none"; + } /** * attach click event listeners to the addressbar dropdown arrows */ @@ -263,11 +264,11 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { } }, - //TODO: add uri pattern validation - validateUri:{ + cleanupUri:{ writable: false, enumerable:true, value: function(folderUri){ + folderUri = folderUri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces //remove unnecessary / from end - for Win and Mac .... don't trim for the root if(((folderUri.charAt(folderUri.length - 1) === "/") || (folderUri.charAt(folderUri.length - 1) === "\\")) && (folderUri !== "/")){ folderUri = folderUri.substring(0, (folderUri.length - 1)); @@ -324,7 +325,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { writable:false, enumerable:true, value:function(uri){ - uri = this.validateUri(uri); + uri = this.cleanupUri(uri); var arr = []; var temp = new String(uri); while(temp.indexOf("/") != -1){ @@ -532,8 +533,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.refreshButton.identifier = "refreshButton"; this.backArrow.identifier = "backArrow"; this.forwardArrow.identifier = "forwardArrow"; - this.okButton.identifier = "okButton"; - this.cancelButton.identifier = "cancelButton"; this.iconView.identifier = "iconView"; this.treeView.identifier = "treeView"; this.resultsArea.identifier = "resultsArea"; @@ -651,7 +650,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { if(this.addressBarUri.value !== ""){ var uri = this.addressBarUri.value; - uri = this.validateUri(uri); + uri = this.cleanupUri(uri); this.currentURI = uri; 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, { value: function(evt){ if(evt.keyCode === 13 ){ var uri = this.addressBarUri.value; - uri = this.validateUri(uri); + uri = this.cleanupUri(uri); this.currentURI = uri; @@ -699,7 +698,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { handleRefreshButtonClick:{ value:function(evt){ var uri = this.addressBarUri.value; - uri = this.validateUri(uri); + uri = this.cleanupUri(uri); var status = this.pickerViews()[this.selectedPickerView].call(this, uri, false);//dynamically calls the update function of the current picker view @@ -768,22 +767,22 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { } }, - handleOkButtonClick : { + handleOkButtonAction : { value: function(evt){ - alert("selected "+ this.selectedItems.toString()); + console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); var success = true; - if(!!this.pickerModel.callback && (this.selectedItems.length > 0)){//call the callback if it is available + if(!!this.pickerModel.callback && !!this.pickerModel.callbackScope && (this.selectedItems.length > 0)){//call the callback if it is available try{ - this.pickerModel.callback({"uri":this.selectedItems}); + this.pickerModel.callback.call(this.pickerModel.callbackScope, {"uri":this.selectedItems}); }catch(e){ success = false; - console.log("[ERROR] File IO failed to open URIs: "+ this.selectedItems.toString()); + console.log(e.stack); } }else{//else send an event with the selected files var pickerSelectionEvent = document.createEvent("Events"); pickerSelectionEvent.initEvent("pickerSelectionsDone", false, false); pickerSelectionEvent.selectedItems = this.selectedItems; - document.dispatchEvent(pickerSelectionEvent);//TODO: use eventManager when it is available + this.eventManager.dispatchEvent(pickerSelectionEvent); } //store last opened/saved folder, and view after IO is successful @@ -813,7 +812,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { } }, - handleCancelButtonClick :{ + handleCancelButtonAction :{ value:function(evt){ //clean up memory this.cleanup(); @@ -1005,8 +1004,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.refreshButton.removeEventListener("click", this, false);//refresh - gets from file system directly this.backArrow.removeEventListener("click", this, false); this.forwardArrow.removeEventListener("click", this, false); - this.okButton.removeEventListener("click", this, false); - this.cancelButton.removeEventListener("click", this, false); this.iconView.removeEventListener("click", this, false); this.treeView.removeEventListener("click", this, false); this.element.removeEventListener("drawTree", this, false); -- cgit v1.2.3 From 92161460a6cbbdebfd1b0263ec6eb790091920a9 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:18:21 -0800 Subject: Moving changes from Gerrit, on 1/27, to the github branch: - added file existence check and validation to save as dialog - minor css fix for file picker, new file dialog Signed-off-by: Ananya Sen --- .../ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 11 +++++++++++ 1 file changed, 11 insertions(+) mode change 100755 => 100644 js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js old mode 100755 new mode 100644 index eec7c8e8..268ec41a --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -621,6 +621,16 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.currentSelectedNode = evt.target; }else{ + + + //test: highlight non-selectable icons too + if(!evt.target.classList.contains("selected")){ + evt.target.classList.add("selected"); + } + this.currentSelectedNode = evt.target; + //end- test + + //disable OK if(!this.okButton.hasAttribute("disabled")){ this.okButton.setAttribute("disabled", "true"); @@ -776,6 +786,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.pickerModel.callback.call(this.pickerModel.callbackScope, {"uri":this.selectedItems}); }catch(e){ success = false; + console.log("[Error] Failed to open "+ this.selectedItems.toString()); console.log(e.stack); } }else{//else send an event with the selected files -- cgit v1.2.3 From 7618cabe1945acc6392c48f3b57820f67f7973b0 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 10:22:26 -0800 Subject: removed using montage button, since it has changed in Montafe 0.6 Signed-off-by: Ananya Sen --- js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index 268ec41a..d7a19c14 100644 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -245,6 +245,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.resultsArea.addEventListener("click", function(evt){that.handleResultsAreaClick(evt);}, false); this.element.addEventListener("click", function(evt){that.handlePickerNavClick(evt);}, false); + this.okButton.addEventListener("click", function(evt){that.handleOkButtonAction(evt);}, false); + this.cancelButton.addEventListener("click", function(evt){that.handleCancelButtonAction(evt);}, false); + //ready to show picker now this.element.style.visibility = "visible"; } -- cgit v1.2.3 From ad0ee69be3512325ede94738f23597086a141a3e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 01:55:30 -0800 Subject: file open and file new integrated again Signed-off-by: Ananya Sen --- .../pickerNavigator.reel/pickerNavigator.js | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index d7a19c14..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 var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), - filePickerControllerModule = require("js/components/ui/FilePicker/file-picker-controller"), treeModule = require("js/components/ui/tree-basic/tree.reel"); var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { @@ -335,7 +334,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { temp = temp.substring(0, temp.lastIndexOf("/")); //populate dropdown irrespective of validity -// if(!!filePickerControllerModule.FilePickerController._directoryContentCache[temp]){//check if it is a valid location +// if(!!this.application.ninja.filePickerController._directoryContentCache[temp]){//check if it is a valid location // arr.push(temp); // }else{ // break; @@ -358,7 +357,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value:function(element, uri){ if(!!element){ var tree = treeModule.Tree.create(); - tree.treeViewDataObject = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + tree.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); //console.log("renderTree() for "+ uri); //console.log(tree.treeViewDataObject); tree.element = element; @@ -374,10 +373,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { var status = true; var iconViewContainer = this.element.querySelector(".iconViewContainer"); if((typeof fromCache === 'undefined') || (fromCache === true)){ - this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); } else{ - this.newContent = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); + this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); } if(!!this.newContent && this.newContent.length > 0){ //clear selection @@ -423,10 +422,10 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { if(!!treeViewContainer){ var data = []; if((typeof fromCache === 'undefined') || (fromCache === true)){ - data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel); + data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); } else{ - data = filePickerControllerModule.FilePickerController.prepareContentList(uri, this.pickerModel, false); + data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); } if(data.length > 0){ @@ -475,7 +474,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { enumerable: false, writable:false, value:function(currentUri){ - var data = filePickerControllerModule.FilePickerController._directoryContentCache[currentUri]; + var data = this.application.ninja.filePickerController._directoryContentCache[currentUri]; var metadata = ""; if(!!data){ if(data.name !== ""){ @@ -610,8 +609,8 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.currentSelectedNode = null; } //enable OK button if the selection is valid as per the picker mode - if((this.pickerModel.inFileMode && (filePickerControllerModule.FilePickerController._directoryContentCache[uri].type === "file")) - || (!this.pickerModel.inFileMode && (filePickerControllerModule.FilePickerController._directoryContentCache[uri].type === "directory"))){ + if((this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "file")) + || (!this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "directory"))){ this.okButton.removeAttribute("disabled"); //put into selectedItems..currently single selection is supported @@ -784,9 +783,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value: function(evt){ console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); var success = true; - if(!!this.pickerModel.callback && !!this.pickerModel.callbackScope && (this.selectedItems.length > 0)){//call the callback if it is available + if(!!this.pickerModel.callback && (this.selectedItems.length > 0)){//call the callback if it is available try{ - this.pickerModel.callback.call(this.pickerModel.callbackScope, {"uri":this.selectedItems}); + this.pickerModel.callback({"uri":this.selectedItems}); }catch(e){ success = false; console.log("[Error] Failed to open "+ this.selectedItems.toString()); @@ -803,12 +802,12 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { var dataStore = window.sessionStorage; try { if(this.pickerModel.pickerMode === "write"){ - filePickerControllerModule.FilePickerController._lastSavedFolderURI.lastSavedFolderUri_local = this.currentURI; dataStore.setItem('lastSavedFolderURI',escape(""+this.currentURI)); } - else{ - filePickerControllerModule.FilePickerController._lastOpenedFolderURI.lastFolderUri_local = this.currentURI; - dataStore.setItem('lastOpenedFolderURI',escape(""+this.currentURI)); + else if(this.pickerModel.inFileMode === true){ + dataStore.setItem('lastOpenedFolderURI_fileSelection',escape(""+this.currentURI)); + }else if(this.pickerModel.inFileMode === false){ + dataStore.setItem('lastOpenedFolderURI_folderSelection',escape(""+this.currentURI)); } } catch(e){ @@ -962,9 +961,9 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { handlePickerNavRefreshTreeSegment:{ value: function(evt){ -// if(filePickerControllerModule.FilePickerController.checkIfStale(evt.uri)){ +// if(this.application.ninja.filePickerController.checkIfStale(evt.uri)){ // //update tree segment if was stale -// evt.treeSegment.treeViewDataObject = filePickerControllerModule.FilePickerController.prepareContentList(evt.uri, this.pickerModel, true, false); +// evt.treeSegment.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(evt.uri, this.pickerModel, true, false); // } } }, @@ -1007,7 +1006,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { value:function(){ //clear memory - TODO:check for more memory leaks this.pickerModel = null; - filePickerControllerModule.FilePickerController._directoryContentCache = {}; + this.application.ninja.filePickerController._directoryContentCache = {}; //remove listeners this.element.removeEventListener("openFolder", this, false);//add icon double click event listener to reload iconList with new set of data this.element.removeEventListener("selectedItem", this, false);//for single selection only -- cgit v1.2.3 From a6948e635389768fc316f1fb86df2524b482b47c Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 13 Feb 2012 18:48:18 -0800 Subject: added logical drive selection to file picker Signed-off-by: Ananya Sen --- .../ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index ff9c7073..6b0d92f7 100644 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -149,6 +149,12 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { leftNav.appendChild(newDiv); if(dirObj.uri === this.pickerModel.currentRoot){ newDiv.classList.add("highlighted"); + //enable ok for logical drive selections, when in directory selection mode + if(this.pickerModel.inFileMode === false){ + this.okButton.removeAttribute("disabled"); + //put into selectedItems..currently single selection is supported + this.selectedItems = [dirObj.uri]; + } } newDiv.addEventListener("click", function(evt){that.handleTopLevelDirectoryClicks(evt, dirObj);}, false); @@ -571,6 +577,13 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { if(!evt.target.classList.contains("highlighted")){ evt.target.classList.add("highlighted"); } + + //enable ok for logical drive selections, when in directory selection mode + if(this.pickerModel.inFileMode === false){ + this.okButton.removeAttribute("disabled"); + //put into selectedItems..currently single selection is supported + this.selectedItems = [dirObj.uri]; + } } }, -- cgit v1.2.3 From 4937b39fb0cf542f57cdadc7d1e2ed9798f7ef87 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 15 Feb 2012 16:09:14 -0800 Subject: fixes to document tabbing Signed-off-by: Ananya Sen --- js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index 6b0d92f7..edc24a2c 100644 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -794,7 +794,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { handleOkButtonAction : { value: function(evt){ - console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); + //console.log("$$$ File Picker : selected "+ this.selectedItems.toString()); var success = true; if(!!this.pickerModel.callback && (this.selectedItems.length > 0)){//call the callback if it is available try{ -- cgit v1.2.3 From 2e766c9eaa98fa20f311b3eb2f892a1a240e90cf Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 16 Feb 2012 06:43:33 -0800 Subject: file picker: Enable ok if user double clicks folder and enter it. Validate path if user enter it manually in addressbar. Signed-off-by: Ananya Sen --- .../pickerNavigator.reel/pickerNavigator.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js index edc24a2c..411386f9 100644 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js @@ -203,6 +203,13 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.pickerModel.storeHistory(this.pickerModel.currentRoot);//populate history this.updateMetadata(this.currentURI); + + //for directory selection, selected url is the folder entered + if(!this.pickerModel.inFileMode ){ + this.okButton.removeAttribute("disabled"); + //put into selectedItems..currently single selection is supported + this.selectedItems = [this.pickerModel.currentRoot]; + } } this.element.addEventListener("openFolder", function(evt){that.handlePickerNavOpenFolder(evt);}, false);//add icon double click event listener to reload iconList with new set of data @@ -211,6 +218,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.element.addEventListener("updateMetadata", function(evt){that.handlePickerNavUpdateMetadata(evt);}, false);//show metadata on click of icon //this.addressGo.addEventListener("click", this, false); this.addressBarUri.addEventListener("keydown", this, false); + this.addressBarUri.addEventListener("keyup", this, false); this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly this.backArrow.addEventListener("click", this, false); this.forwardArrow.addEventListener("click", this, false); @@ -608,6 +616,13 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.backArrow.classList.remove("disable"); } + //for directory selection, selected url is the folder entered + if(!this.pickerModel.inFileMode ){ + this.okButton.removeAttribute("disabled"); + //put into selectedItems..currently single selection is supported + this.selectedItems = [evt.folderUri]; + } + } }, @@ -720,6 +735,21 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { } }, + handleAddressBarUriKeyup:{ + value: function(evt){ + //disable ok if user enters an invalid uri + if(!this.application.ninja.coreIoApi.isValidUri(this.addressBarUri.value)){ + //disable OK + if(!this.okButton.hasAttribute("disabled")){ + this.okButton.setAttribute("disabled", "true"); + } + }else{ + this.okButton.removeAttribute("disabled"); + this.selectedItems = [this.addressBarUri.value]; + } + } + }, + handleRefreshButtonClick:{ value:function(evt){ var uri = this.addressBarUri.value; -- cgit v1.2.3 From a9c369c2e5d8f6fc8d936f7e1e6b84f693226ddf Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 16 Feb 2012 13:11:48 -0800 Subject: moved file picker in file io Signed-off-by: Ananya Sen --- .../pickerNavigator.reel/pickerNavigator.js | 1072 -------------------- 1 file changed, 1072 deletions(-) delete mode 100644 js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js (limited to 'js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js') diff --git a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js b/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js deleted file mode 100644 index 411386f9..00000000 --- a/js/components/ui/FilePicker/pickerNavigator.reel/pickerNavigator.js +++ /dev/null @@ -1,1072 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ - -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - iconsListModule = require("js/components/ui/icon-list-basic/iconsList.reel"), - treeModule = require("js/components/ui/tree-basic/tree.reel"); - -var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { - - popup:{ - enumerable: false, - writable: true, - value: null - }, - - mainContentData:{ - enumerable:false, - writable:true, - value:null - }, - - _firstTime: { - enumerable: false, - value: true - }, - - firstTime:{ - get: function(){}, - set: function(){} - }, - - pickerCallback:{ - enumerable:false, - writable:true, - value:null - }, - - selectedItems:{//passed to pickerCallback on click of OK - enumerable:false, - writable:true, - value:[] - }, - - /** - * store a reference to the currently selected node... for single selection - */ - currentSelectedNode:{ - enumerable:false, - writable:true, - value:null - }, - - currentURI:{ - enumerable:false, - writable:true, - value:null - }, - - iconsViewDrawnOnce:{ - enumerable:false, - writable:true, - value:false - }, - - /** - * for tree view only - * will store folder uri vs tree instance map - */ - treeRefHash:{ - enumerable:false, - writable:true, - value:{ - - } - }, - - selectedPickerView:{ - enumerable:false, - writable:true, - value:null - }, - - /** - * Contains the different Views and their update handlers - */ - pickerViews:{ - enumerable:false, - writable:true, - value: function(){ - var that = this; - return { - "iconView":that.updateIconView, - "treeView":that.updateTreeView - } - } - }, - - pickerModel:{ - enumerable:false, - writable:true, - value:null - }, - - willDraw: { - enumerable: false, - value: function() { - - } - }, - draw: { - enumerable: false, - value: function() { - this.filterVal.innerHTML = this.pickerModel.currentFilter; - - if(this.pickerModel.fatalError !== null){ - this.error.innerHTML = this.pickerModel.fatalError; - } - - } - }, - didDraw: { - enumerable: false, - value: function() { - - var that = this; - this.iconList = null; - this.newContent = null; - this.spanEl = null; - - this.addIdentifiers(); - - var topLevelDirs = this.pickerModel.topLevelDirectories; - var leftNav = this.leftNav; - //draw left nav - if(!!topLevelDirs - && (typeof topLevelDirs === "object") - && ('splice' in topLevelDirs) - && ('join' in topLevelDirs) - &&(topLevelDirs.length > 0)){ - - topLevelDirs.forEach(function(dirObj){ - var newDiv = document.createElement("div"); - newDiv.className = "driversList"; - newDiv.innerHTML = dirObj.name; - leftNav.appendChild(newDiv); - if(dirObj.uri === this.pickerModel.currentRoot){ - newDiv.classList.add("highlighted"); - //enable ok for logical drive selections, when in directory selection mode - if(this.pickerModel.inFileMode === false){ - this.okButton.removeAttribute("disabled"); - //put into selectedItems..currently single selection is supported - this.selectedItems = [dirObj.uri]; - } - } - - newDiv.addEventListener("click", function(evt){that.handleTopLevelDirectoryClicks(evt, dirObj);}, false); - }, that); - }else{ - console.error("need at least 1 valid top level directory"); - } - - //Draw icon view list - //TODO: check the default view and draw the appropriate view - if(this.mainContentData !== null){ - - this.currentURI = this.pickerModel.currentRoot; - - //draw the IconsList if icons view container is on - if(this.iconViewContainer.style.display === "block"){ - this.iconList = iconsListModule.IconsList.create(); - //console.log(this.mainContentData); - this.iconList.iconsViewDataObject = this.mainContentData; - this.iconList.element = this.iconViewContainer; - this.iconList.needsDraw = true; - this.iconsViewDrawnOnce = true; - this.selectedPickerView = "iconView"; - - if(!this.iconView.classList.contains("viewSelected")){ - this.iconView.classList.add("viewSelected") - } - if(this.treeView.classList.contains("viewSelected")){ - this.treeView.classList.remove("viewSelected"); - } - - }else if(this.treeViewContainer.style.display === "block"){ - //else draw the Tree if tree view container is on - this.renderTree(this.treeViewContainer, this.currentURI); - this.selectedPickerView = "treeView"; - - if(!this.treeView.classList.contains("viewSelected")){ - this.treeView.classList.add("viewSelected") - } - if(this.iconView.classList.contains("viewSelected")){ - this.iconView.classList.remove("viewSelected"); - } - } - - this.updateAddressBar(this.pickerModel.currentRoot); - this.pickerModel.storeHistory(this.pickerModel.currentRoot);//populate history - - this.updateMetadata(this.currentURI); - - //for directory selection, selected url is the folder entered - if(!this.pickerModel.inFileMode ){ - this.okButton.removeAttribute("disabled"); - //put into selectedItems..currently single selection is supported - this.selectedItems = [this.pickerModel.currentRoot]; - } - } - - this.element.addEventListener("openFolder", function(evt){that.handlePickerNavOpenFolder(evt);}, false);//add icon double click event listener to reload iconList with new set of data - this.element.addEventListener("selectedItem", function(evt){that.handlePickerNavSelectedItem(evt);}, false);//for single selection only - this.element.addEventListener("showMetadata", function(evt){that.handlePickerNavShowMetadata(evt);}, false);//show metadata on hover of icon - this.element.addEventListener("updateMetadata", function(evt){that.handlePickerNavUpdateMetadata(evt);}, false);//show metadata on click of icon - //this.addressGo.addEventListener("click", this, false); - this.addressBarUri.addEventListener("keydown", this, false); - this.addressBarUri.addEventListener("keyup", this, false); - this.refreshButton.addEventListener("click", this, false);//refresh - gets from file system directly - this.backArrow.addEventListener("click", this, false); - this.forwardArrow.addEventListener("click", this, false); - - //populate filters if in file selection mode - if(this.pickerModel.inFileMode === true){ - var filtersDD = this.element.querySelector(".filters .dropdown"); - if(!!this.pickerModel.fileFilters - && (typeof this.pickerModel.fileFilters === "object") - && ('splice' in this.pickerModel.fileFilters) - && ('join' in this.pickerModel.fileFilters)){ - this.pickerModel.fileFilters.forEach(function(aFilter){ - var newDiv = document.createElement("div"); - newDiv.innerHTML = aFilter; - filtersDD.appendChild(newDiv); - newDiv.addEventListener("click", function(evt){that.handleFilterClick(evt, aFilter, filtersDD)}, false); - }, this); - } - - var renderedWidth = this.getComputedWidth(filtersDD); - this.filters.style.width = "" + (parseInt((renderedWidth.substring(0, (renderedWidth.length - 2)))) + 20) + "px"; - }else{ - this.filters.style.display = "none"; - } - /** - * attach click event listeners to the addressbar dropdown arrows - */ - var dropDownArrows = this.element.getElementsByClassName("dropdownArrow"); - for(var x=0; x0){ - arr.push(temp); - }else{//for unix root / - arr.push("/"); - } - - } - //console.log(arr); - return arr; - } - }, - - renderTree:{ - writable:false, - enumerable:true, - value:function(element, uri){ - if(!!element){ - var tree = treeModule.Tree.create(); - tree.treeViewDataObject = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); - //console.log("renderTree() for "+ uri); - //console.log(tree.treeViewDataObject); - tree.element = element; - tree.needsDraw = true; - } - } - }, - - updateIconView:{ - writable:false, - enumerable:true, - value:function(uri, fromCache){ - var status = true; - var iconViewContainer = this.element.querySelector(".iconViewContainer"); - if((typeof fromCache === 'undefined') || (fromCache === true)){ - this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); - } - else{ - this.newContent = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); - } - if(!!this.newContent && this.newContent.length > 0){ - //clear selection - this.clearSelection(); - this.spanEl = iconViewContainer.querySelector(".noResults"); - if(!!this.spanEl){ - this.spanEl.style.display = "none"; - } - this.iconList.iconsViewDataObject = this.newContent; - }else{ - this.iconList.iconsViewDataObject = []; - this.spanEl = iconViewContainer.querySelector(".noResults"); - if(!!this.spanEl){ - this.spanEl.style.display = "block"; - }else{ - this.spanEl = document.createElement("span"); - this.spanEl.className = "noResults"; - this.spanEl.innerHTML = "no results"; - this.spanEl.style.display = "block"; - iconViewContainer.appendChild(this.spanEl); - } - status = false; //for no match - } - this.updateMetadata(uri); - - return status; - } - }, - - updateTreeView:{ - writable:false, - enumerable:true, - value:function(uri, fromCache){ - var status = true; - //need to draw every time since an expanded tree won't update with just bound data update - var treeViewContainer = this.element.querySelector(".treeViewContainer"); - //first clean up treeViewContainer - while(treeViewContainer.hasChilden){ - treeViewContainer.removeChild(treeViewContainer.lastChild); - } - //now draw the unexpanded tree with the current uri data - - if(!!treeViewContainer){ - var data = []; - if((typeof fromCache === 'undefined') || (fromCache === true)){ - data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel); - } - else{ - data = this.application.ninja.filePickerController.prepareContentList(uri, this.pickerModel, false); - } - - if(data.length > 0){ - - //clear selection - this.clearSelection(); - this.spanEl = this.element.querySelector(".treeViewContainer").querySelector(".noResults"); - if(!!this.spanEl){ - this.spanEl.style.display = "none"; - } - - var tree = treeModule.Tree.create(); - tree.treeViewDataObject = data; - tree.element = treeViewContainer; - tree.needsDraw = true; - - }else{ - - var treeUl = treeViewContainer.getElementsByTagName("ul")[0]; - if(!!treeUl){ - treeUl.style.display = "none"; - } - - this.spanEl = this.element.querySelector(".treeViewContainer").querySelector(".noResults"); - if(!!this.spanEl){ - this.spanEl.style.display = "block"; - }else{ - this.spanEl = document.createElement("span"); - this.spanEl.className = "noResults"; - this.spanEl.innerHTML = "no results"; - this.spanEl.style.display = "block"; - this.element.querySelector(".treeViewContainer").appendChild(this.spanEl); - } - - status = false; //for no match - } - - this.updateMetadata(uri); - - return status; - } - } - }, - - updateMetadata:{ - enumerable: false, - writable:false, - value:function(currentUri){ - var data = this.application.ninja.filePickerController._directoryContentCache[currentUri]; - var metadata = ""; - if(!!data){ - if(data.name !== ""){ - metadata = "Name: "+data.name; - } - metadata = metadata + "
" + "Type: "+data.type; - if(data.size){metadata = metadata + "
" + "Size: "+data.size;} - if(data.creationDate){metadata = metadata + "
" + "Creation date: "+ this.formatTimestamp(data.creationDate);} - if(data.modifiedDate){metadata = metadata + "
" + "Modified date: "+ this.formatTimestamp(data.modifiedDate);} - } - this.element.getElementsByClassName("right-bottom")[0].innerHTML = metadata; - } - }, - - isOutside:{ - enumerable:true, - value:function(el, targetEl){ - var isOutside = true; - if(el){ - var childElements = el.getElementsByTagName("*");//get a flat NodeList of all the child elements - if(childElements != null){ - for(var i=0; i< childElements.length; i++){ - if(childElements[i] === targetEl){//targetEl matches with an element inside the menu - isOutside = false; - break; - } - } - } - } - return isOutside; - } - }, - /** - * convert timestamp to human readable form - * - * @param: timestamp - UTC milliseconds - */ - formatTimestamp:{ - writable:false, - enumerable: false, - value: function(timestamp) { - var aDate = new Date(); - timestamp = timestamp - (aDate.getTimezoneOffset()*60*1000);//convert from GMT to local timestamp - aDate = new Date(timestamp); - return aDate.toLocaleString(); - } - }, - - /** - * Event Listners - */ - - addIdentifiers:{ - value: function(){ - this.element.identifier = "pickerNav"; - //this.addressGo.identifier = "addressGo"; - this.addressBarUri.identifier = "addressBarUri"; - this.refreshButton.identifier = "refreshButton"; - this.backArrow.identifier = "backArrow"; - this.forwardArrow.identifier = "forwardArrow"; - this.iconView.identifier = "iconView"; - this.treeView.identifier = "treeView"; - this.resultsArea.identifier = "resultsArea"; - } - }, - - handleTopLevelDirectoryClicks : { - enumerable: true, - writable: false, - value : function(evt, dirObj){ - this.currentURI = dirObj.uri; - - var status = this.pickerViews()[this.selectedPickerView].call(this, dirObj.uri);//dynamically calls the update function of the current picker view - - this.updateAddressBar(dirObj.uri); - this.pickerModel.currentRoot = dirObj.uri; - - //populate history - this.pickerModel.storeHistory(dirObj.uri); - //disable forward button for explicit new urls - if(!this.forwardArrow.classList.contains("disable")){ - this.forwardArrow.classList.add("disable"); - } - //enable back button if required - if((this.pickerModel.currentHistoryPointer === 1) && this.backArrow.classList.contains("disable")){ - this.backArrow.classList.remove("disable"); - } - - //dehighlight current selection and highlight new selection - var currentHighlighted = evt.target.parentNode.querySelector(".highlighted"); - if(!!currentHighlighted){ - currentHighlighted.classList.remove("highlighted"); - } - if(!evt.target.classList.contains("highlighted")){ - evt.target.classList.add("highlighted"); - } - - //enable ok for logical drive selections, when in directory selection mode - if(this.pickerModel.inFileMode === false){ - this.okButton.removeAttribute("disabled"); - //put into selectedItems..currently single selection is supported - this.selectedItems = [dirObj.uri]; - } - } - }, - - handlePickerNavOpenFolder: { - value: function(evt){ - this.currentURI = evt.folderUri; - var status = this.pickerViews()[this.selectedPickerView].call(this, evt.folderUri);//dynamically calls the update function of the current picker view - - //update address-bar - this.updateAddressBar(evt.folderUri); - - //populate history - this.pickerModel.storeHistory(evt.folderUri); - - //disable forward button for explicit new urls - if(!this.forwardArrow.classList.contains("disable")){ - this.forwardArrow.classList.add("disable"); - } - - //enable back button if required - if((this.pickerModel.currentHistoryPointer === 1) && this.backArrow.classList.contains("disable")){ - this.backArrow.classList.remove("disable"); - } - - //for directory selection, selected url is the folder entered - if(!this.pickerModel.inFileMode ){ - this.okButton.removeAttribute("disabled"); - //put into selectedItems..currently single selection is supported - this.selectedItems = [evt.folderUri]; - } - - } - }, - - - handlePickerNavSelectedItem: { - value:function(evt){ - var uri = evt.uri; - - //handle deselection of other icons for single selection - if((this.currentSelectedNode !== null) && (this.currentSelectedNode !== evt.target) && (this.currentSelectedNode.classList.contains("selected"))){ - this.currentSelectedNode.classList.remove("selected"); - this.currentSelectedNode = null; - } - //enable OK button if the selection is valid as per the picker mode - if((this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "file")) - || (!this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "directory"))){ - this.okButton.removeAttribute("disabled"); - - //put into selectedItems..currently single selection is supported - this.selectedItems = [uri]; - - if(!evt.target.classList.contains("selected")){ - evt.target.classList.add("selected"); - } - - this.currentSelectedNode = evt.target; - - }else{ - - - //test: highlight non-selectable icons too - if(!evt.target.classList.contains("selected")){ - evt.target.classList.add("selected"); - } - this.currentSelectedNode = evt.target; - //end- test - - - //disable OK - if(!this.okButton.hasAttribute("disabled")){ - this.okButton.setAttribute("disabled", "true"); - } - } - } - }, - - handlePickerNavShowMetadata: { - value: function(evt){ - //update matadata only if nothing is already selected - if(this.currentSelectedNode == null){ - //console.log("handle showmetadata - true"); - this.metadataSection.innerHTML = evt.metadata; - } - } - }, - - handlePickerNavUpdateMetadata:{ - value: function(evt){ - this.metadataSection.innerHTML = evt.metadata; - } - }, - - handleAddressGoClick :{ - value: function(evt){ - - if(this.addressBarUri.value !== ""){ - var uri = this.addressBarUri.value; - uri = this.cleanupUri(uri); - - this.currentURI = uri; - var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view - - //populate history - this.pickerModel.storeHistory(uri); - - //disable forward button for explicit new urls - if(!this.forwardArrow.classList.contains("disable")){ - this.forwardArrow.classList.add("disable"); - } - - //enable back button if required - if((this.pickerModel.currentHistoryPointer === 1) && this.backArrow.classList.contains("disable")){ - this.backArrow.classList.remove("disable"); - } - } - } - }, - - handleAddressBarUriKeydown:{ - value: function(evt){ - if(evt.keyCode === 13 ){ - var uri = this.addressBarUri.value; - uri = this.cleanupUri(uri); - - this.currentURI = uri; - - var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view - - //populate history - this.pickerModel.storeHistory(uri); - //disable forward button for explicit new urls - if(!this.forwardArrow.classList.contains("disable")){ - this.forwardArrow.classList.add("disable"); - } - //enable back button if required - if((this.pickerModel.currentHistoryPointer === 1) && this.backArrow.classList.contains("disable")){ - this.backArrow.classList.remove("disable"); - } - } - } - }, - - handleAddressBarUriKeyup:{ - value: function(evt){ - //disable ok if user enters an invalid uri - if(!this.application.ninja.coreIoApi.isValidUri(this.addressBarUri.value)){ - //disable OK - if(!this.okButton.hasAttribute("disabled")){ - this.okButton.setAttribute("disabled", "true"); - } - }else{ - this.okButton.removeAttribute("disabled"); - this.selectedItems = [this.addressBarUri.value]; - } - } - }, - - handleRefreshButtonClick:{ - value:function(evt){ - var uri = this.addressBarUri.value; - uri = this.cleanupUri(uri); - - var status = this.pickerViews()[this.selectedPickerView].call(this, uri, false);//dynamically calls the update function of the current picker view - - } - }, - - handleBackArrowClick :{ - value:function(evt){ - var uri = ""; - //console.log("*** backArrow: pointer ="+this.pickerModel.currentHistoryPointer); - if(this.pickerModel.currentHistoryPointer >0){ - uri = this.pickerModel._history[this.pickerModel.currentHistoryPointer -1]; - //console.log("*** back uri= "+ uri); - //console.log(this.pickerModel._history); - - this.currentURI = uri; - var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view - - //update address-bar - this.updateAddressBar(uri); - - this.pickerModel.currentHistoryPointer -= 1; - - //disable back button if it is at the beginning - if((this.pickerModel.currentHistoryPointer === 0) && (!evt.target.classList.contains("disable"))){ - evt.target.classList.add("disable"); - } - //enable forward button if required - if((this.pickerModel.currentHistoryPointer < (this.pickerModel._history.length -1) && (this.forwardArrow.classList.contains("disable")))){ - this.forwardArrow.classList.remove("disable"); - } - } - //console.log("***new backArrow: pointer ="+this.pickerModel.currentHistoryPointer); - } - }, - - handleForwardArrowClick: { - value:function(evt){ - var uri = ""; - //console.log("*** forwardArrow: pointer ="+this.pickerModel.currentHistoryPointer); - if(this.pickerModel.currentHistoryPointer < (this.pickerModel._history.length -1)){ - uri = this.pickerModel._history[this.pickerModel.currentHistoryPointer + 1]; - //console.log("*** forward uri= "+ uri); - //console.log(this.pickerModel._history); - - this.currentURI = uri; - var status = this.pickerViews()[this.selectedPickerView].call(this, uri);//dynamically calls the update function of the current picker view - - //update address-bar - this.updateAddressBar(uri); - - this.pickerModel.currentHistoryPointer += 1; - - //disable forward button if pointer is at the end - if((this.pickerModel.currentHistoryPointer === (this.pickerModel._history.length -1)) && (!evt.target.classList.contains("disable"))){ - evt.target.classList.add("disable"); - } - - //enable back button if required - if((this.pickerModel.currentHistoryPointer > 0) && (this.backArrow.classList.contains("disable"))){ - this.backArrow.classLi