From: Lebbeous Fogle-Weekley Date: Thu, 26 Jan 2012 22:41:22 +0000 (-0500) Subject: Excise hard dependency on openils.widget.Search, any dependency on fieldmapper X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=759a413c007059677ee28edf23916dde36527b13;p=evergreen%2Fequinox.git Excise hard dependency on openils.widget.Search, any dependency on fieldmapper Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 0b34e5af40..6473bd52dc 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -42,21 +42,20 @@ [%- END %] [%- IF want_dojo; -%] +[%# See whether we can get away with killing this line - LFW %] [% IF use_autosuggest.enabled == "t"; %] [% END; # use_autosuggest %] diff --git a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js index dab271f562..97f4de6063 100644 --- a/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js +++ b/Open-ILS/web/js/dojo/openils/AutoSuggestStore.js @@ -40,41 +40,90 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) { "constructor": function(/* object */ args) { dojo.mixin(this, args); /* XXX very sloppy */ this._current_items = {}; + this._setup_config_metabib_caches(); }, - "_label_field": function(field_id) { - /* It seems to be possible (well, I think I got it to happen once) - * to catch openils.widget.Searcher while it's still loading. - * So let's be gentle with it when we ask for its cached cmc and - * cmf objects. */ - if (!_cmf_cache) { - try { - _cmf_cache = openils.widget.Searcher._cache.obj.cmf; - } catch (E) { - console.log("o.w.Searcher's cmf cache not ready:" + E); - return field_id; - } + "_setup_config_metabib_cache": function(key, field_list, oncomplete) { + var self = this; + + if (this.cm_cache[key]) return; + + var cookie = dojo.cookie("OILS_AS" + key); + if (cookie) { + this.cm_cache[key] = dojo.fromJson(cookie); + return oncomplete(); } - if (!_cmc_cache) { - try { - _cmc_cache = openils.widget.Searcher._cache.obj.cmc; - } catch (E) { - console.log("o.w.Searcher's cmc cache not ready:" + E); - return _cmf_cache[field_id].label; - } + /* now try to get it from open-ils.searcher */ + try { + /* openils.widget.Searcher may not even be loaded; + * that's ok; just try. */ + this.cm_cache[key] = + openils.widget.Searcher._cache.obj[key]; + /* Don't try to set a cookie here; o.w.Searcher has + * tried and failed. */ + } catch (E) { + void(0); } - var mfield = _cmf_cache[field_id]; - var mclass = _cmc_cache[mfield.field_class]; - return mfield.label + " (" + mclass.label + ")"; + if (this.cm_cache[key]) return oncomplete(); + + /* now try talking to fielder ourselves, and cache the result */ + (new OpenSRF.ClientSession("open-ils.fielder"))({ + "method": "open-ils.fielder." + key + ".atomic", + "params": [ + {"query": {"id": {"!=": null}, "fields": field_list}} + ], + "async": true, + "oncomplete": function(r) { + /* XXX check for failure? */ + var result_arr = r.recv().content(); + + self.cm_cache[key] = {}; + dojo.forEach( + result_arr, + function(o) { self.cm_cache[key][o.id] = o; } + ); + dojo.cookie( + "OILS_AS" + key, dojo.toJson(self.cm_cache[key]) + ); + console.log("finished fetching " + key + " from fielder"); + oncomplete(); + } + }).send(); + }, + + "_setup_config_metabib_caches": function() { + var self = this; + + this.cm_cache = {}; + + var field_lists = { + "cmf": ["id", "field_class", "name", "label"], + "cmc": ["id", "name", "label"] + }; + var class_list = openils.Util.objectProperties(field_lists); + + var _is_done = function(k) { return Boolean(self.cm_cache[k]); }; + + dojo.forEach( + class_list, function(key) { + self._setup_config_metabib_cache( + key, field_lists[key], function() { + if (dojo.every(class_list, _is_done)) { + self.cm_cache._is_done = true; + } + } + ) + } + ); }, "_prepare_match_for_display": function(match, field) { return ( "
" + match + "
" + - this._label_field(field) + "
" + this.get_field_label(field) + "" ); }, @@ -108,6 +157,12 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) { return "/opac/extras/autosuggest?" + params.join("&"); }, + "get_field_label": function(field_id) { + var mfield = this.cm_cache.cmf[field_id]; + var mclass = this.cm_cache.cmc[mfield.field_class]; + return mfield.label + " (" + mclass.label + ")"; + }, + /* *** Begin dojo.data.api.Read methods *** */ "getValue": function( @@ -207,6 +262,12 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) { // callback to the *req* object for the caller's use, but // the one we provide does nothing but issue an alert(). + if (!this.cm_cache._is_done) { + if (typeof req.onComplete == "function") + req.onComplete.call(callback_scope, [], req); + return; + } + this._current_items = {}; var callback_scope = req.scope || dojo.global; diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js b/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js index c4c025d386..d57d898e30 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js @@ -3,7 +3,6 @@ if (!dojo._hasResource["openils.widget.AutoSuggest"]) { dojo._hasResource["openils.widget.AutoSuggest"] = true; dojo.require("dijit.form.ComboBox"); - dojo.require("openils.widget.Searcher"); dojo.require("openils.AutoSuggestStore"); dojo.declare( @@ -23,19 +22,15 @@ if (!dojo._hasResource["openils.widget.AutoSuggest"]) { "store_args": {}, "_update_search_type_selector": function(id) { /* cmf id */ - /* Fail somewhat gracefully if a race condition, which I'm not - * /certain/ actually exists, lets us get here before - * openils.widget.Search has fully initialized. */ - var f; - try { - f = openils.widget.Searcher._cache.obj.cmf[id]; - } catch (E) { - console.log( - "o.w.Searcher couldn't help us with field #" + id + if (!this.store.cm_cache) { + console.warn( + "can't update search type selector; " + + "store doesn't have config.metabib_* caches available" ); return; } + var f = this.store.cm_cache.cmf[id]; var selector = this.type_selector; var search_class = f.field_class + "|" + f.name; var exact = dojo.indexOf(