From: Lebbeous Fogle-Weekley Date: Fri, 20 Jan 2012 22:06:03 +0000 (-0500) Subject: make a custom dijit that subclasses combobox and uses autosuggeststore X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=726418c631ec8381941c0dae0d344cf3c5d1d89e;p=evergreen%2Fequinox.git make a custom dijit that subclasses combobox and uses autosuggeststore In theory you could now use markup based dojo declarations to turn a given text input into an autosuggesting dijit. But we need to be able to turn autosuggest on/off by a switch, and how would we make dojo markup-based declarations respond to conditionals? Incidentally, this commit does also take care of populating the value of the search box after issuing a search. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js b/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js new file mode 100644 index 0000000000..8709704610 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js @@ -0,0 +1,26 @@ +if (!dojo._hasResource["openils.widget.AutoSuggest"]) { + dojo.provide("openils.widget.AutoSuggest"); + dojo._hasResource["openils.widget.AutoSuggest"] = true; + + dojo.require("dijit.form.ComboBox"); + dojo.require("openils.AutoSuggestStore"); + + dojo.declare( + "openils.widget.AutoSuggest", [dijit.form.ComboBox], { + + "labelAttr": "match", + "labelType": "html", + "searchAttr": "term", + "hasDownArrow": false, + "autoComplete": false, + "searchDelay": 200, + + "postMixInProperties": function() { + this.inherited(arguments); + + if (this.storeArgs) + this.store = new openils.AutoSuggestStore(this.storeArgs); + } + } + ); +} diff --git a/Open-ILS/web/opac/skin/default/js/search_bar.js b/Open-ILS/web/opac/skin/default/js/search_bar.js index b60060336e..82e3700c0f 100644 --- a/Open-ILS/web/opac/skin/default/js/search_bar.js +++ b/Open-ILS/web/opac/skin/default/js/search_bar.js @@ -13,8 +13,7 @@ G.evt.common.init.push(searchBarInit); var newSearchLocation; var newSearchDepth = null; -dojo.require("dijit.form.ComboBox"); -dojo.require("openils.AutoSuggestStore"); +dojo.require("openils.widget.AutoSuggest"); function updateSearchTypeSelector(id) { /* Fail somewhat gracefully if a race condition, which I'm not /certain/ @@ -49,21 +48,9 @@ function updateSearchTypeSelector(id) { } function autoSuggestInit() { - var as_store = new openils.AutoSuggestStore( + var widg = new openils.widget.AutoSuggest( { - "type_selector": G.ui.searchbar.type_selector - } - ); - - var widg = new dijit.form.ComboBox( - { - "store": as_store, - "labelAttr": "match", - "labelType": "html", - "searchAttr": "term", - "hasDownArrow": false, - "autoComplete": false, - "searchDelay": 200, + "storeArgs": {"type_selector": G.ui.searchbar.type_selector}, "onChange": function(value) { if (typeof value.field == "number") updateSearchTypeSelector(value.field); @@ -72,7 +59,8 @@ function autoSuggestInit() { if (event.charOrCode == dojo.keys.ENTER) searchBarSubmit(); }, - "style": dojo.attr("search_box", "style") + "style": dojo.attr("search_box", "style"), + "value": ((getTerm() != null) ? getTerm() : "") }, "search_box" ); @@ -114,7 +102,7 @@ function searchBarInit() { setSelector($('opac.result.sort'), getSort()+'.'+getSortDir()); } - autoSuggestInit(); /* XXX TODO make this conditional. OU setting? */ + autoSuggestInit(); /* XXX TODO make this conditional by global flag */ } function searchBarSubmit(isFilterSort) {