From 56b6582a7938db1c1ee50cb19a0d22bba5362cce Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 26 Mar 2012 17:54:56 -0400 Subject: [PATCH] paging kinda works, but sorting is not right. not sure what to blame yet Signed-off-by: Lebbeous Fogle-Weekley --- Open-ILS/web/js/dojo/openils/FlattenerStore.js | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/FlattenerStore.js b/Open-ILS/web/js/dojo/openils/FlattenerStore.js index 28b121277f..f5c0fc170e 100644 --- a/Open-ILS/web/js/dojo/openils/FlattenerStore.js +++ b/Open-ILS/web/js/dojo/openils/FlattenerStore.js @@ -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( -- 2.11.0