make a custom dijit that subclasses combobox and uses autosuggeststore
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 20 Jan 2012 22:06:03 +0000 (17:06 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 23 Jan 2012 17:27:00 +0000 (12:27 -0500)
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 <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js [new file with mode: 0644]
Open-ILS/web/opac/skin/default/js/search_bar.js

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 (file)
index 0000000..8709704
--- /dev/null
@@ -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);
+            }
+        }
+    );
+}
index b600603..82e3700 100644 (file)
@@ -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) {