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>"
);
},
/* 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 + ")");
},
"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()");
},
"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");
},
"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()");
/* 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 + ")");
},
"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 + ")");
},
"isItemLoaded": function(/* anything */ something) {
- // summary:
// Return true if *something* is an item. It's always
// "loaded" in this store.
// console.log("isItemLoaded()");
},
"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 + ")");
},
"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");
},
"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
// 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);
"url": url,
"handleAs": "json",
"sync": false,
- "preventCache": false, /* XXX is this what we want? */
+ "preventCache": true,
"headers": {"Accept": "application/json"},
"load": process_fetch
}
/* *** 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 + "])");
},
"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()");
},
"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