Grid column picker sort direction
authorBill Erickson <berick@esilibrary.com>
Wed, 28 Mar 2012 16:26:05 +0000 (12:26 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 28 Mar 2012 16:35:16 +0000 (12:35 -0400)
Added support for specifying a descending sort direction.  Selecting a
positive sort priority results in an ascending sort.  A negative sort
priority resutls in a descending sort.

Sort order is still determined by the (absolute) value of the sort
priority.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js

index c1021e7..c3d5afc 100644 (file)
@@ -588,7 +588,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
 
             // called after a sort change occurs within the column picker
             cpSortHandler : function(fields) {
-                console.log("AutoGrod cpSortHandler(): " + fields);
+                console.log("AutoGrod cpSortHandler(): " + js2JSON(fields));
                 // user-defined sort handler
                 if (this.onSortChange) { 
                     this.onSortChange(fields)
@@ -597,8 +597,13 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 } else { 
                     if (!this.cachedQueryOpts) 
                         this.cachedQueryOpts = {};
+                    var order_by = '';
+                    dojo.forEach(fields, function(f) {
+                        if (order_by) order_by += ',';
+                        order_by += f.field + ' ' + f.direction
+                    });
                     this.cachedQueryOpts.order_by = {};
-                    this.cachedQueryOpts.order_by[this.fmClass] = fields.join(',');
+                    this.cachedQueryOpts.order_by[this.fmClass] = order_by;
                     this.refresh();
                 }
             },
index 0959e58..add99ad 100644 (file)
@@ -104,14 +104,20 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
                 "<th width='23%'>Auto Width</th><th width='23%'>Sort Priority</th></tr></thead>" +
                 "<tbody />"});
 
-            var tDiv = dojo.create('div', {style : 'height:400px; overflow-y:auto'});
+            var tDiv = dojo.create('div', {style : 'height:400px; overflow-y:auto;'});
             tDiv.appendChild(table);
 
             var bDiv = dojo.create('div', {style : 'text-align:right; width:100%;',
                 innerHTML : "<span name='cancel_button'></span><span name='save_button'></span>"});
+
+            var textDiv = dojo.create('div', {style : 'padding:5px; margin-top:5px; border-top:1px solid #333', 
+                innerHTML :
+                    "<i>A Sort Priority of '0' means no sorting is applied.<br/>" +
+                    "<i>Apply a negative Sort Priority for descending sort."});
             
             var wrapper = dojo.create('div');
             wrapper.appendChild(tDiv);
+            wrapper.appendChild(textDiv);
             wrapper.appendChild(bDiv);
             dialog.containerNode.appendChild(wrapper);
 
@@ -192,7 +198,7 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
 
                 // this must be added after its parent node is inserted into the DOM.
                 var ns = new dijit.form.NumberSpinner(
-                    {   constraints : {min : 0, places : 0}, 
+                    {   constraints : {places : 0}, 
                         value : cell._sort || 0,
                         style : 'width:4em',
                         name : 'sort'
@@ -248,14 +254,17 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) {
         // extract cells that have sorting applied, order lowest to highest
         buildSortList : function() {
             var sortList = this.cells.filter(
-                function(cella) { return cella._sort > 0 }
+                function(cella) { return cella._sort != 0 }
             ).sort( 
                 function(a, b) { 
-                    if (a._sort < b._sort) return -1; 
+                    if (Math.abs(a._sort) < Math.abs(b._sort)) return -1; 
                     return 1; 
                 }
             );
-            return sortList.map(function(f){return f.field});
+            return sortList.map(function(f){
+                var dir = f._sort < 0 ? 'desc' : 'asc';
+                return {field : f.field, direction : dir};
+            });
         },
 
         // save me as a user setting