[%- END %]
[%- IF want_dojo; -%]
<script type="text/javascript">
- var locale = "[% ctx.locale %]";
var djConfig = {
- locale: locale.toLowerCase().replace("_", "-"), /* XXX ? */
+ locale: "[% ctx.locale | lower | replace('_', '-') %]",
parseOnLoad: true,
isDebug: false
}, lang, bidi;
</script>
<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/dojo.js?[% ctx.eg_cache_hash %]"></script>
<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf.js?[% ctx.eg_cache_hash %]"></script>
+[%# See whether we can get away with killing this line - LFW %]<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf_xhr.js?[% ctx.eg_cache_hash %]"></script>
<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/openils_dojo.js?[% ctx.eg_cache_hash %]"></script>
[% IF use_autosuggest.enabled == "t"; %]
<script type="text/javascript">
-dojo.require("fieldmapper.dojoData");
-dojo.require("openils.widget.AutoSuggest");
+ dojo.require("openils.widget.AutoSuggest");
</script>
[% END; # use_autosuggest %]
"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 (
"<div class='oils_AS_match'><div class='oils_AS_match_term'>" +
match + "</div><div class='oils_AS_match_field'>" +
- this._label_field(field) + "</div></div>"
+ this.get_field_label(field) + "</div></div>"
);
},
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(
// 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;
dojo._hasResource["openils.widget.AutoSuggest"] = true;
dojo.require("dijit.form.ComboBox");
- dojo.require("openils.widget.Searcher");
dojo.require("openils.AutoSuggestStore");
dojo.declare(
"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(