From: Lebbeous Fogle-Weekley Date: Mon, 2 Apr 2012 17:46:06 +0000 (-0400) Subject: teach flattenergrid/store a new trick called softFieldReMap, X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=481016a23a1350bc940156c85dc5d93a1ec363cc;p=evergreen%2Fequinox.git teach flattenergrid/store a new trick called softFieldReMap, which enables to use one column to sort another. This is perfect for sorting call numbers by call number sortkey, which we're now doing. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/templates/circ/hold_pull_list.tt2 b/Open-ILS/src/templates/circ/hold_pull_list.tt2 index 09fd3d9974..e64a12de79 100644 --- a/Open-ILS/src/templates/circ/hold_pull_list.tt2 +++ b/Open-ILS/src/templates/circ/hold_pull_list.tt2 @@ -98,9 +98,10 @@ editStyle="pane" showLoadFilter="true" fmClass="'ahopl'" - baseSort="['copy_location_sort_order','call_number']" + defaultSort="['copy_location_sort_order','call_number_sort_key']" mapExtras="map_extras" - deferInitialFetch="true" + sortFieldReMap="{call_number: 'call_number_sort_key'}" + fetchLock="true" query="{}"> diff --git a/Open-ILS/web/js/dojo/openils/FlattenerStore.js b/Open-ILS/web/js/dojo/openils/FlattenerStore.js index e5cbdd7764..c3af728dbb 100644 --- a/Open-ILS/web/js/dojo/openils/FlattenerStore.js +++ b/Open-ILS/web/js/dojo/openils/FlattenerStore.js @@ -29,6 +29,7 @@ if (!dojo._hasResource["openils.FlattenerStore"]) { "offset": 0, "baseSort": null, "defaultSort": null, + "sortFieldReMap": null, "constructor": function(/* object */ args) { dojo.mixin(this, args); @@ -51,6 +52,32 @@ if (!dojo._hasResource["openils.FlattenerStore"]) { ); }, + "_remap_sort": function(prepared_sort) { + if (this.sortFieldReMap) { + return prepared_sort.map( + dojo.hitch( + this, function(exp) { + if (typeof exp == "object") { + var key; + for (key in exp) + break; + var newkey = (key in this.sortFieldReMap) ? + this.sortFieldReMap[key] : key; + var o = {}; + o[newkey] = exp[key]; + return o; + } else { + return (exp in this.sortFieldReMap) ? + this.sortFieldReMap[exp] : exp; + } + } + ) + ); + } else { + return prepared_sort; + } + }, + "_prepare_flattener_params": function(req) { var params = { "hint": this.fmClass, @@ -74,7 +101,9 @@ if (!dojo._hasResource["openils.FlattenerStore"]) { params, { "where": dojo.toJson(req.query), "slo": dojo.toJson({ - "sort": this._prepare_sort(req.sort), + "sort": this._remap_sort( + this._prepare_sort(req.sort) + ), "limit": limit, "offset": offset }) diff --git a/Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js b/Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js index e86460d349..f7e7832529 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js @@ -17,7 +17,7 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) { "columnReordering": true, "columnPersistKey": null, "showLoadFilter": false, /* use FlattenerFilterDialog */ - "deferInitialFetch": false, + "fetchLock": false, /* These potential constructor arguments maybe useful to * FlattenerGrid in their own right, and are passed to @@ -25,6 +25,7 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) { "fmClass": null, "fmIdentifier": null, "mapExtras": null, + "sortFieldReMap": null, "defaultSort": null, /* whatever any part of the UI says will /replace/ this */ "baseSort": null, /* will contains what the columnpicker @@ -302,13 +303,14 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) { "mapClause": (this.mapClause || this._cleanMapForStore(this._generateMap())), "baseSort": this.baseSort, - "defaultSort": this._mapCPSortFields(sortFields) + "defaultSort": this._mapCPSortFields(sortFields), + "sortFieldReMap": this.sortFieldReMap + }), this.query ); - if (!this.deferInitialFetch) { + if (!this.fetchLock) this._refresh(true); - } // pick up any column label changes this.columnPicker.reloadStructure(); @@ -365,20 +367,15 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) { }, "refresh": function() { - /* We may never need additional logic here, but I don't - * want callers to make a habit of calling _ methods directly. - */ - console.log("here (no surprise)"); + this.fetchLock = false; this._refresh(/* isRender */ true); }, - "_render": function() { - if(this.domNode.parentNode){ - this.scroller.init(this.attr('rowCount'), this.keepRows, this.rowsPerPage); - this.prerender(); - if (!this.deferInitialFetch) - this._fetch(0, true); - } + "_fetch": function() { + if (this.fetchLock) + return; + else + return this.inherited(arguments); }, /* ******** below are methods mostly copied but