From ec0a8603cf35e63fe48047e580c3f04a5f49ab55 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 19 Jan 2012 16:13:31 -0500 Subject: [PATCH] some changes since last time: * 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 --- Open-ILS/examples/fm_IDL.xml | 3 +- Open-ILS/web/js/dojo/openils/AutoSuggestStore.js | 67 +++++++++++------------- Open-ILS/web/opac/skin/default/js/search_bar.js | 4 +- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 3ce71dcc31..f92a2f04c9 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2064,7 +2064,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + @@ -2094,6 +2094,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js index 99599023b3..aa31242aad 100644 --- a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js +++ b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js @@ -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 ( "
" + - match + "
" + field + - "
" + match + "
" + + this._label_field(field) + "
" ); }, @@ -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 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 fbff91a01f..2e76bfdc1b 100644 --- a/Open-ILS/web/opac/skin/default/js/search_bar.js +++ b/Open-ILS/web/opac/skin/default/js/search_bar.js @@ -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() { -- 2.11.0