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;
"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
})
// 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
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(