paging kinda works, but sorting is not right. not sure what to blame yet
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Mar 2012 21:54:56 +0000 (17:54 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Mar 2012 21:54:56 +0000 (17:54 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/openils/FlattenerStore.js

index 28b1212..f5c0fc1 100644 (file)
@@ -44,6 +44,19 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
             this._current_items = {};
         },
 
+        /* turn dojo-style sort into flattener-style sort */
+        "_prepare_sort": function(dsort) {
+            if (!dsort)
+                return [];
+            return dsort.map(
+                function(d) {
+                    var o = {};
+                    o[d.attribute] = d.descending ? "desc" : "asc";
+                    return o;
+                }
+            );
+        },
+
         "_prepare_flattener_params": function(req) {
             var limit = (!isNaN(req.count) && req.count != Infinity) ?
                 req.count : this.limit;
@@ -55,7 +68,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
                 "ses": openils.User.authtoken,
                 "where": dojo.toJson(req.query),
                 "slo": dojo.toJson({
-                    "sort": req.sort,   /* XXX TODO translate from dojo sort format to flattener format - easy */
+                    "sort": this._prepare_sort(req.sort),
                     "limit": limit,
                     "offset": offset
                 })
@@ -183,7 +196,9 @@ 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
+            //                  that this call to fetch() *could* have
+            //                  returned, with a higher limit. We do
+            //                  tricks with this.
             //      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
@@ -219,10 +234,14 @@ if (!dojo._hasResource["openils.FlattenerStore"]) {
                 if (when < self._last_fetch) /* Stale response. Discard. */
                     return;
 
-                console.log(dojo.toJson(obj));
                 if (typeof req.onBegin == "function") {
-                    console.debug("onBegin(" + obj.length + ", ...)");
-                    req.onBegin.call(callback_scope, obj.length, req);
+
+                    var might_be_a_lie = obj.length;
+                    if (obj.length >= req.count)
+                        might_be_a_lie += req.count;
+
+                    console.debug("onBegin(" + might_be_a_lie + ", ...)");
+                    req.onBegin.call(callback_scope, might_be_a_lie, req);
                 }
 
                 dojo.forEach(