diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js index dd9a8ee470144c5fb9fec9dc8781cbf8560e6d78..c7f6160d9151e143072872395ab746cd9d13e190 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js @@ -31,6 +31,7 @@ $.extend(DefaultProfile.prototype, { // DEFAULTS, TYPICALLY DON'T TOUCH IF YOU DON'T KNOW WHAT YOU DO // + this.searchDomains = [ { "@id" : -1, "@type" : "GobalSearch", label : "Global", name : "global"}]; this.ELNExperiments = ["SYSTEM_EXPERIMENT"]; this.notShowTypes = ["SYSTEM_EXPERIMENT"]; this.inventorySpaces = []; @@ -68,6 +69,10 @@ $.extend(DefaultProfile.prototype, { "isEnabled" : false }; + this.getSearchDomains = function() { + return this.searchDomains; + } + this.getDefaultDataStoreCode = function() { var dataStoreCode = null; if(this.allDataStores.length > 0) { @@ -493,6 +498,18 @@ $.extend(DefaultProfile.prototype, { ); } + this.initSearchDomains = function(callback) { + var _this = this; + this.serverFacade.listSearchDomains(function(data) { + if(data && data.result) { + for(var i = 0; i < data.result.length; i++) { + _this.searchDomains.push(data.result[i]); + } + } + callback(); + }); + } + // // Initializes // @@ -501,7 +518,9 @@ $.extend(DefaultProfile.prototype, { this.initPropertyTypes(function(){ _this.initVocabulariesForSampleTypes(function() { - callbackWhenDone(); + _this.initSearchDomains(function() { + callbackWhenDone(); + }); }); }); } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js index 835199ebf7bafec1d29f74a674ded48fd1917002..72cb8f7ee08c95c37929c5972c8c71eb2ab7634e 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js @@ -154,6 +154,13 @@ function ServerFacade(openbisServer) { } } + this.listSearchDomains = function(callbackFunction) { + if(this.openbisServer.listAvailableSearchDomains) { + this.openbisServer.listAvailableSearchDomains(callbackFunction); + } else { + callbackFunction(); + } + } // // Others // diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js index 5f799655695ec6143ecc0f72fee4af8facd3a3a3..a201b85cd9bdea1504844fa68e46fa6e49d73d86 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js @@ -20,6 +20,48 @@ var FormUtil = new function() { // Standard Form Fields // + this.getDropDownToogleWithSelectedFeedback = function(prefixElement, labelWithEvents, isSelectedFeedback) { + var $dropDownToogle = $('<span>', { class : 'dropdown' }); + if(prefixElement) { + $dropDownToogle.append(prefixElement); + } + $dropDownToogle.append($('<a>', { 'href' : '#', 'data-toggle' : 'dropdown', 'class' : 'dropdown-toggle btn btn-default'}).append($('<b>', { 'class' : 'caret' }))); + + var $dropDownToogleOptions = $('<ul>', { class : 'dropdown-menu', 'role' : 'menu' }); + $dropDownToogle.append($dropDownToogleOptions); + + for(var i = 0; i < labelWithEvents.length; i++) { + + var selectedFeedback = $('<span>', { 'id' : 'dropdown-' + labelWithEvents[i].id }); + + if(isSelectedFeedback && i === 0) { + selectedFeedback.append("<span class='glyphicon glyphicon-ok'></span>"); + } + + var $a = $('<a>', { class : '', 'title' : labelWithEvents[i].title }).append(selectedFeedback).append(' ').append(labelWithEvents[i].title); + + var clickFunction = function(labelWithEvents, selectedIndex, isSelectedFeedback) { + return function() { + if(isSelectedFeedback) { + for(var j = 0; j < labelWithEvents.length; j++) { + if(j === selectedIndex) { + $("#" + 'dropdown-' + labelWithEvents[j].id).append("<span class='glyphicon glyphicon-ok'></span>"); + } else { + $("#" + 'dropdown-' + labelWithEvents[j].id).empty(); + } + } + } + + labelWithEvents[selectedIndex].href(); + }; + } + + $a.click(clickFunction(labelWithEvents, i, isSelectedFeedback)); + $dropDownToogleOptions.append($('<li>', { 'role' : 'presentation' }).append($a)); + } + return $dropDownToogle; + } + this.getDefaultBenchDropDown = function(id, isRequired) { var $storageDropDown = this.getDefaultStoragesDropDown(id, isRequired); if(!$storageDropDown) { diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js index 88034e3de679451929b5530e14e0c49bdc9aa3f2..3c14e8c493f96568ad29a9a091621e5d9c5cbe39 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js @@ -393,9 +393,50 @@ function SideMenuWidget(mainController, containerId, serverFacade) { .append($("<span>", { "class" : "glyphicon glyphicon-resize-horizontal" })) ); + var dropDownSearch = ""; + var searchDomains = profile.getSearchDomains(); + + if(searchDomains.length > 1) { + //Default Selected for the prefix + var defaultSelected = ""; + if(searchDomains[0].label.length > 3) { + defaultSelected = searchDomains[0].label.substring(0, 2) + "."; + } else { + defaultSelected = searchDomains[0].label.label; + } + + //Prefix function + var selectedFunction = function(selectedSearchDomain) { + return function() { + var $component = $("#prefix-selected-search-domain"); + $component.empty(); + if(selectedSearchDomain.label.length > 3) { + $component.append(selectedSearchDomain.label.substring(0, 2) + "."); + } else { + $component.append(selectedSearchDomain.label); + } + $component.attr('selected-name', selectedSearchDomain.name); + }; + } + + //Dropdown elements + var dropDownComponents = []; + for(var i = 0; i < searchDomains.length; i++) { + dropDownComponents.push({ + href : selectedFunction(searchDomains[i]), + title : searchDomains[i].label, + id : searchDomains[i].name + }); + } + + dropDownSearch = FormUtil.getDropDownToogleWithSelectedFeedback($('<span>', { id : 'prefix-selected-search-domain', class : 'btn btn-default disabled', 'selected-name' : searchDomains[0].name }).append(defaultSelected),dropDownComponents, true); + } + var $searchForm = $("<li>") .append($("<form>", { "class" : "navbar-form", "onsubmit" : "return false;"}) .append($("<input>", { "id" : "search", "type" : "text", "onkeyup" : "mainController.changeView(\"showSearchPage\", event.target.value);", "class" : "form-control search-query", "placeholder" : "Search"})) + .append(' ') + .append(dropDownSearch) ); var logoutButton = $("<a>", { "id" : "logout-button", "href" : "" }).append($("<span>", { "class" : "glyphicon glyphicon-off"}));