Correct some failings of the new cmf/cmc fetcher/cacher
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 26 Jan 2012 23:10:01 +0000 (18:10 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 26 Jan 2012 23:10:01 +0000 (18:10 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/openils/AutoSuggestStore.js
Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js

index 97f4de6..6d82651 100644 (file)
@@ -1,6 +1,10 @@
 if (!dojo._hasResource["openils.AutoSuggestStore"]) {
     dojo._hasResource["openils.AutoSuggestStore"] = true;
+
     dojo.provide("openils.AutoSuggestStore");
+
+    dojo.require("dojo.cookie");
+    dojo.require("DojoSRF");
     dojo.require("openils.Util");
 
     /* Here's an exception class specific to openils.AutoSuggestStore */
@@ -17,7 +21,6 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
     TermString.prototype.substr=function(){return this.str.substr(arguments);};
 
     var _autosuggest_fields = ["id", "match", "term", "field"];
-    var _cmf_cache, _cmc_cache;
 
     dojo.declare(
         "openils.AutoSuggestStore", null, {
@@ -69,11 +72,13 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
             if (this.cm_cache[key]) return oncomplete();
 
             /* now try talking to fielder ourselves, and cache the result */
-            (new OpenSRF.ClientSession("open-ils.fielder"))({
+            var pkey = field_list[0];
+            var query = {};
+            query[pkey] = {"!=": null};
+
+            (new OpenSRF.ClientSession("open-ils.fielder")).request({
                 "method": "open-ils.fielder." + key + ".atomic",
-                "params": [
-                    {"query": {"id": {"!=": null}, "fields": field_list}}
-                ],
+                "params": [{"query": query, "fields": field_list}],
                 "async": true,
                 "oncomplete": function(r) {
                     /* XXX check for failure? */
@@ -82,12 +87,11 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
                     self.cm_cache[key] = {};
                     dojo.forEach(
                         result_arr,
-                        function(o) { self.cm_cache[key][o.id] = o; }
+                        function(o) { self.cm_cache[key][o[pkey]] = o; }
                     );
                     dojo.cookie(
                         "OILS_AS" + key, dojo.toJson(self.cm_cache[key])
                     );
-                    console.log("finished fetching " + key + " from fielder");
                     oncomplete();
                 }
             }).send();
@@ -100,18 +104,18 @@ if (!dojo._hasResource["openils.AutoSuggestStore"]) {
 
             var field_lists = {
                 "cmf": ["id", "field_class", "name", "label"],
-                "cmc": ["id", "name", "label"]
+                "cmc": ["name", "label"]
             };
             var class_list = openils.Util.objectProperties(field_lists);
 
-            var _is_done = function(k) { return Boolean(self.cm_cache[k]); };
+            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;
+                            if (dojo.every(class_list, is_done)) {
+                                self.cm_cache.is_done = true;
                             }
                         }
                     )
@@ -262,12 +266,11 @@ 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 (!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;
index d57d898..d93ab3e 100644 (file)
@@ -22,7 +22,7 @@ if (!dojo._hasResource["openils.widget.AutoSuggest"]) {
             "store_args": {},
 
             "_update_search_type_selector": function(id) {  /* cmf id */
-                if (!this.store.cm_cache) {
+                if (!this.store.cm_cache.is_done) {
                     console.warn(
                         "can't update search type selector; " +
                         "store doesn't have config.metabib_* caches available"