column picker onSortChange support added to flattener grid flattener-grid-sorting
authorBill Erickson <berick@esilibrary.com>
Fri, 30 Mar 2012 18:00:36 +0000 (14:00 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 30 Mar 2012 18:00:36 +0000 (14:00 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js

index 1d7ca1f..ae98d26 100644 (file)
@@ -214,22 +214,45 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) {
                             null, this.columnPersistKey, this);
                     this.columnPicker.onLoad = dojo.hitch(
                         this, function(opts) { this._finishStartup(opts.sortFields) });
+
+                    this.columnPicker.onSortChange = dojo.hitch(this,
+                        /* directly after, this.update() is called by the
+                           column picker, causing a re-fetch */
+                        function(fields) {
+                            this.store.baseSort = this._mapCPSortFields(fields)
+                        }
+                    );
+
                     this.columnPicker.load();
                 }
 
                 this.inherited(arguments);
             },
 
-            "_finishStartup": function() {
+            /*  Maps ColumnPicker sort fields to the correct format.
+                If no sort fields specified, falls back to defaultSort */
+            "_mapCPSortFields": function(sortFields) {
+                var sort = this.defaultSort;
+                if (sortFields.length) {
+                    sort = sortFields.map(function(f) {
+                        a = {};
+                        a[f.field] = f.direction;
+                        return a;
+                    });
+                }
+                return sort;
+            },
+
+            "_finishStartup": function(sortFields) {
 
-                this.setStore( /* this exact method chosen intentionally */
+                this.setStore(
                     new openils.FlattenerStore({
                         "fmClass": this.fmClass,
                         "fmIdentifier": this.fmIdentifier,
                         "mapClause": (this.mapClause ||
                             this._cleanMapForStore(this._generateMap())),
                         "baseSort": this.baseSort,
-                        "defaultSort": this.defaultSort
+                        "defaultSort": this._mapCPSortFields(sortFields)
                     }), this.query
                 );