From 46f430b8b267fb4b7100e5cb795cd1c8874a7de1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 28 Mar 2012 12:26:05 -0400 Subject: [PATCH] Grid column picker sort direction 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 --- Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 9 +++++++-- .../web/js/dojo/openils/widget/GridColumnPicker.js | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index c1021e74bc..c3d5afcb30 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -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(); } }, diff --git a/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js b/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js index 0959e58191..add99ade7f 100644 --- a/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js +++ b/Open-ILS/web/js/dojo/openils/widget/GridColumnPicker.js @@ -104,14 +104,20 @@ if(!dojo._hasResource["openils.widget.GridColumnPicker"]) { "Auto WidthSort Priority" + ""}); - 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 : ""}); + + var textDiv = dojo.create('div', {style : 'padding:5px; margin-top:5px; border-top:1px solid #333', + innerHTML : + "A Sort Priority of '0' means no sorting is applied.
" + + "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 -- 2.11.0