progress, still doesn't page past first set of results yet
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Mar 2012 21:33:41 +0000 (17:33 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Mar 2012 21:33:41 +0000 (17:33 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/openils/FlattenerStore.js
Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js

index 4b36e39..28b1212 100644 (file)
@@ -36,6 +36,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
         "mapClause": null,
         "sloClause": null,
         "limit": 25,
+        "offset": 0,
 
 
         "constructor": function(/* object */ args) {
@@ -46,22 +47,18 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
         "_prepare_flattener_params": function(req) {
             var limit = (!isNaN(req.count) && req.count != Infinity) ?
                 req.count : this.limit;
+            var offset = (!isNaN(req.start) && req.start != Infinity) ?
+                req.start : this.offset;
 
-            //            XXX TODO
-            //            get offset(start) too, mixing base sort if any, check
-            //            grid sorting (multicolumn)
-//            var slo = dojo.clone(this.sloClause);
-//            slo.limit = limit;
-//
-            var slo = {"limit": limit, "sort": "barcode"};
-
-            // XXX offset
             var content = {
                 "hint": this.fmClass,
                 "ses": openils.User.authtoken,
                 "where": dojo.toJson(req.query),
-                "slo": dojo.toJson(slo)
-                //"identifier": this.fmIdentifier
+                "slo": dojo.toJson({
+                    "sort": req.sort,   /* XXX TODO translate from dojo sort format to flattener format - easy */
+                    "limit": limit,
+                    "offset": offset
+                })
             };
 
             if (this.mapKey) { /* XXX TODO, get a map key */
@@ -88,7 +85,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
             /* object */ item,
             /* string */ attribute,
             /* anything */ defaultValue) {
-            console.log("getValue(" + lazy(item) + ", " + attribute + ", " + defaultValue + ")")
+            //console.log("getValue(" + lazy(item) + ", " + attribute + ", " + defaultValue + ")")
             if (!this.isItem(item))
                 throw new FlattenerStoreError("getValue(): bad item " + item);
             else if (typeof attribute != "string")
@@ -138,7 +135,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
         },
 
         "isItem": function(/* anything */ something) {
-            console.log("isItem(" + lazy(something) + ")");
+            //console.log("isItem(" + lazy(something) + ")");
             if (typeof something != "object" || something === null)
                 return false;
 
@@ -160,15 +157,13 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
 
         "close": function(/* object */ request) { /* no-op */ return; },
 
-        /* =========== not dealt with at all below here yet ============ */
-
         "getLabel": function(/* object */ item) {
             console.log("getLabel(" + item + ")");
-            return "match";
+            return "XXX TODO";
         },
         "getLabelAttributes": function(/* object */ item) {
             console.log("getLabelAttributes(" + item + ")");
-            return ["match"];
+            return ["XXX TODO"];
         },
 
         "loadItem": function(/* object */ keywordArgs) {
@@ -188,8 +183,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
             //                  translation for our server-side service
             //      count    an int
             //      onBegin  a callback that takes the number of items
-            //                  that this call to fetch() will return, but
-            //                  we always give it -1 (i.e. unknown)
+            //                  that this call to fetch() will return
             //      onItem   a callback that takes each item as we get it
             //      onComplete  a callback that takes the list of items
             //                      after they're all fetched
@@ -226,16 +220,19 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
                     return;
 
                 console.log(dojo.toJson(obj));
-                if (typeof req.onBegin == "function")
+                if (typeof req.onBegin == "function") {
+                    console.debug("onBegin(" + obj.length + ", ...)");
                     req.onBegin.call(callback_scope, obj.length, req);
+                }
 
                 dojo.forEach(
                     obj,
                     function(item) {
-                        self._current_items[item.id] = item;
+                        self._current_items[item[self.fmIdentifier]] = item;
 
-                        if (typeof req.onItem == "function")
+                        if (typeof req.onItem == "function") {
                             req.onItem.call(callback_scope, item, req);
+                        }
                     }
                 );
 
@@ -277,15 +274,20 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
             if (!this.isItem(item))
                 throw new FlattenerStoreError("not an item");
 
-            return item.id;
+            return item[this.fmIdentifier];
         },
 
         "getIdentityAttributes": function(/* object */ item) {
             console.log("getIdentityAttributes(" + item + ")");
-            return ["id"];
+            return [this.fmIdentifier];
         },
 
         "fetchItemByIdentity": function(/* object */ keywordArgs) {
+
+            /* XXX This almost certainly needs attention, and/or
+             * needs to be able to call fetch() or to talk to the
+             * web service directly. */
+
             console.log("fetchItemByIdentity(" + dojo.toJson(keywordArgs)+ ")");
             if (keywordArgs.identity == undefined)
                 return null; // Identity API spec unclear whether error callback
index 62dc592..a5621ae 100644 (file)
@@ -64,6 +64,7 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) {
                 if (!this.store) {
                     this.store = new openils.FlattenerStore({
                         "fmClass": this.fmClass,
+                        "fmIdentifier": this.fmIdentifier,
                         "mapClause": (this.mapClause || this._generate_map())
                     });
                 }