teach flattenergrid/store a new trick called softFieldReMap,
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 2 Apr 2012 17:46:06 +0000 (13:46 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 2 Apr 2012 17:46:06 +0000 (13:46 -0400)
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 <lebbeous@esilibrary.com>
Open-ILS/src/templates/circ/hold_pull_list.tt2
Open-ILS/web/js/dojo/openils/FlattenerStore.js
Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js

index 09fd3d9..e64a12d 100644 (file)
         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="{}">
         <thead>
             <tr>
index e5cbdd7..c3af728 100644 (file)
@@ -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
                         })
index e86460d..f7e7832 100644 (file)
@@ -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