some changes since last time:
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 19 Jan 2012 21:13:31 +0000 (16:13 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 23 Jan 2012 17:26:59 +0000 (12:26 -0500)
    * IDL omission fixed
    * shows class name/field in autosuggest popup
    * filteringselect widget never shows invalid now

TODO
    * fix Go button, which isn't working
    * stop the widget from forcing selection to something in the list
    * every thing in previous commit's todo list not otherwise covered
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/web/js/dojo/openils/AutoSuggestStore.js
Open-ILS/web/opac/skin/default/js/search_bar.js

index 3ce71dc..f92a2f0 100644 (file)
@@ -2064,7 +2064,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Name" name="name" reporter:datatype="text"/>
                        <field reporter:label="Label" name="label" reporter:datatype="text" oils_persist:i18n="true"/>
                        <field reporter:label="Bouyant?" name="bouyant" reporter:datatype="bool" />
-                       <field reporter:label="Restrict" name="restrict" reporter:datatype="bool" />
+                       <field reporter:label="Restrict?" name="restrict" reporter:datatype="bool" />
                        <field reporter:label="Fields" name="fields" reporter:datatype="link" oils_persist:virtual="true"/>
                </fields>
                <links>
@@ -2094,6 +2094,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Facet XPath" name="facet_xpath" reporter:datatype="text" />
                        <field reporter:label="Browse Field" name="browse_field" reporter:datatype="bool" />
                        <field reporter:label="Browse XPath" name="browse_xpath" reporter:datatype="text" />
+                       <field reporter:label="Restrict?" name="restrict" reporter:datatype="bool" />
                </fields>
                <links>
                        <link field="field_class" reltype="has_a" key="name" map="" class="cmc"/>
index 9959902..aa31242 100644 (file)
@@ -20,11 +20,38 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             this._current_items = {};
         },
 
+        "_label_field": function(field_id) {
+            /* It seems to be possible to catch openils.widget.Searcher
+             * in various states of unreadiness, so we have to be gentle with
+             * it if we want to ask for its cached cmc and cmf objects.
+             */
+            var cmf_cache, cmc_cache;
+            try {
+                cmf_cache = openils.widget.Searcher._cache.obj.cmf;
+            } catch (E) {
+                console.log("openils.widget.Searcher cmf cache not ready:" + E);
+                return field_id;
+            }
+
+            try {
+                cmc_cache = openils.widget.Searcher._cache.obj.cmc;
+            } catch (E) {
+                console.log("openils.widget.Searcher cmc cache not ready:" + E);
+                return cmf_cache[field_id].label;
+            }
+
+            var mfield, mclass;
+
+            mfield = cmf_cache[field_id];
+            mclass = cmc_cache[mfield.field_class];
+            return mfield.label + " (" + mclass.label + ")";
+        },
+
         "_prepare_match_for_display": function(match, field) {
             return (
                 "<div class='oils_AS_match'><div class='oils_AS_match_term'>" +
-                match + "</div><div class='oils_AS_match_field'>" + field +
-                "</div></div>"
+                match + "</div><div class='oils_AS_match_field'>" +
+                this._label_field(field) + "</div></div>"
             );
         },
 
@@ -52,7 +79,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             /* object */ item,
             /* string */ attribute,
             /* anything */ defaultValue) {
-            //  summary:
             //      Given an *item* and the name of an *attribute* on that item,
             //      return that attribute's value.
 //            console.log("getValue(" + item + ", " + attribute + ")");
@@ -67,7 +93,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "getValues": function(/* object */ item, /* string */ attribute) {
-            //  summary:
             //      Same as getValue(), except the result is always an array
             //      and there is no way to specify a default value.
 //            console.log("getValues()");
@@ -79,9 +104,7 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "getAttributes": function(/* object */ item) {
-            //  summary:
             //      Return an array of all of the given *item*'s *attribute*s.
-            //      This is done by consulting fieldmapper.
 //            console.log("getAttributes()");
             if (!this.isItem(item))
                 throw new AutoSuggestStoreError("getAttributes(): bad arguments");
@@ -90,7 +113,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "hasAttribute": function(/* object */ item, /* string */ attribute) {
-            //  summary:
             //      Return true or false based on whether *item* has an
             //      attribute by the name specified in *attribute*.
 //            console.log("hasAttribute()");
@@ -105,7 +127,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             /* object */ item,
             /* string */ attribute,
             /* anything */ value) {
-            //  summary:
             //      Return true or false based on whether *item* has any value
             //      matching *value* for *attribute*.
 //            console.log("containsValue(" + item + ", " + attribute + ", " + value + ")");
@@ -118,7 +139,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "isItem": function(/* anything */ something) {
-            //  summary:
             //      Return true if *something* is an item (loaded or not
             //      because to use everything is loaded, really.
 //            console.log("isItem(" + something + ")");
@@ -134,7 +154,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "isItemLoaded": function(/* anything */ something) {
-            //  summary:
             //      Return true if *something* is an item.  It's always
             //      "loaded" in this store.
 //            console.log("isItemLoaded()");
@@ -148,7 +167,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "getLabel": function(/* object */ item) {
-            //  summary:
             //      Return the name of the attribute that should serve as the
             //      label for objects of the same class as *item*.
 //            console.log("getLabel(" + item + ")");
@@ -156,22 +174,13 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "getLabelAttributes": function(/* object */ item) {
-            //  summary:
-            //      XXX !?
 //            console.log("getLabelAttributes(" + item + ")");
             return ["match"];
         },
 
         "loadItem": function(/* object */ keywordArgs) {
-            //  summary:
             //      Fully load the item specified in the *item* property of
             //      *keywordArgs*
-            //
-            //  description:
-            //      This ultimately just returns the same object it's given.
-            //      That's because everything fetched is always fully loaded
-            //      with this store implementation.  So this method only
-            //      exists for API completeness.
 //            console.log("loadItem(" + dojo.toJson(keywordArgs) + ")");
             if (!this.isItem(keywordArgs.item))
                 throw new AutoSuggestStoreError("that's not an item; can't load it");
@@ -181,11 +190,9 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "fetch": function(/* request-object */ req) {
-            //  summary:
             //      Basically, fetch objects matching the *query* property of
             //      the *req* parameter.
             //
-            //  description:
             //      Translate the *query* into a call we make to the
             //      autosuggest webserver module, which yields JSON for us,
             //      and translate those results into items, storing them
@@ -208,7 +215,7 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             //      The Read API also charges this method with adding an abort
             //      callback to the *req* object for the caller's use, but
             //      the one we provide does nothing but issue an alert().
-            console.log("fetch(" + dojo.toJson(openils.Util.objectProperties(req)) + ")");
+            //console.log("fetch(" + dojo.toJson(openils.Util.objectProperties(req)) + ")");
 
             var callback_scope = req.scope || dojo.global;
             var url = this._prepare_autosuggest_url(req);
@@ -269,7 +276,7 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
                     "url": url,
                     "handleAs": "json",
                     "sync": false,
-                    "preventCache": false,  /* XXX is this what we want? */
+                    "preventCache": true,
                     "headers": {"Accept": "application/json"},
                     "load": process_fetch
                 }
@@ -283,7 +290,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         /* *** Begin dojo.data.api.Identity methods *** */
 
         "getIdentity": function(/* object */ item) {
-            //  summary:
             //      Given an *item* return its unique identifier (the value
             //      of its primary key).
 //            console.log("getIdentity(" + item + " [" + item.id + "])");
@@ -294,7 +300,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "getIdentityAttributes": function(/* object */ item) {
-            //  summary:
             //      Given an *item* return the list of the name of the fields
             //      that constitute the item's unique identifier.
 //            console.log("getIdentityAttributes()");
@@ -302,16 +307,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
         },
 
         "fetchItemByIdentity": function(/* object */ keywordArgs) {
-            //  summary:
-            //      Given an *identity* property in the *keywordArgs* object,
-            //      retrieve an item, unless we already have the fully loaded
-            //      item in the store's internal memory.
-            //
-            //  description:
-            //      Once we've have the item we want one way or another, issue
-            //      the *onItem* callback from the *keywordArgs* object.  If we
-            //      tried to retrieve the item with pcrud but didn't get an item
-            //      back, issue the *onError* callback.
 //            console.log("fetchItemByIdentity(" + dojo.toJson(keywordArgs) + ")");
             if (keywordArgs.identity == undefined)
                 return null; // Identity API spec unclear whether error callback
index fbff91a..2e76bfd 100644 (file)
@@ -20,7 +20,7 @@ function autoSuggestInit() {
     var as_store = new openils.AutoSuggestStore(
         {"type_selector": G.ui.searchbar.type_selector}
     );
-    new dijit.form.FilteringSelect({
+    var widg = new dijit.form.FilteringSelect({
         "store": as_store,
         "labelAttr": "match",
         "labelType": "html",
@@ -29,6 +29,8 @@ function autoSuggestInit() {
         "autoComplete": false,
         "style": dojo.attr("search_box", "style")
     }, "search_box");
+
+    widg.validate = function() { return true; } /* sic! */
 }
 
 function searchBarInit() {