From 22777c962eb71049b42198ecacdb14793a507740 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 28 Mar 2012 11:25:27 -0400 Subject: [PATCH] Auto sorting from column picker in AutoGrid Signed-off-by: Bill Erickson --- Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 82 ++++++++++++++++--------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 4b8e7483ff..c1021e74bc 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -49,6 +49,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { }, startup : function() { + var _this = this; this.selectionMode = 'single'; this.sequence = openils.widget.AutoGrid.sequence++; openils.widget.AutoGrid.gridCache[this.sequence] = this; @@ -58,28 +59,6 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { this.setStore(this.buildAutoStore()); this.cachedQueryOpts = {}; this._showing_create_pane = false; - - if(this.showColumnPicker) { - if(!this.columnPersistKey) { - console.error("No columnPersistKey defined"); - } else { - var picker = new openils.widget.GridColumnPicker( - openils.User.authtoken, this.columnPersistKey, this); - - var _this = this; - picker.onSortChange = function(fields) { - if (_this.onSortChange) - _this.onSortChange(fields) - }; - - if(openils.User.authtoken) { - picker.load(); - } else { - openils.Util.addOnLoad(function() { picker.load() }); - } - } - } - this.overrideEditWidgets = {}; this.overrideEditWidgetClass = {}; this.overrideWidgetArgs = {}; @@ -138,10 +117,10 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { href : 'javascript:void(0);', onclick : function() { if (!self.filterDialog) { - self.filterDialog = new openils.widget.PCrudFilterDialog({fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields}) + self.filterDialog = new openils.widget.PCrudFilterDialog( + {fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields}) self.filterDialog.onApply = function(filter) { - self.resetStore(); - self.loadAll(self.cachedQueryOpts, filter); + self.refresh(self.cachedQueryOpts, filter); }; self.filterDialog.startup(); } @@ -597,19 +576,66 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { this.setStore(this.buildAutoStore()); }, - refresh : function() { + refresh : function(opts, search) { + opts = opts || this.cachedQueryOpts; + search = search || this.cachedQuerySearch; this.resetStore(); if (this.dataLoader) this.dataLoader() else - this.loadAll(this.cachedQueryOpts, this.cachedQuerySearch); + this._loadAll(opts, search); + }, + + // called after a sort change occurs within the column picker + cpSortHandler : function(fields) { + console.log("AutoGrod cpSortHandler(): " + fields); + // user-defined sort handler + if (this.onSortChange) { + this.onSortChange(fields) + + // default sort handler + } else { + if (!this.cachedQueryOpts) + this.cachedQueryOpts = {}; + this.cachedQueryOpts.order_by = {}; + this.cachedQueryOpts.order_by[this.fmClass] = fields.join(','); + this.refresh(); + } }, loadAll : function(opts, search) { + var _this = this; + + // first we have to load the column picker to determine the sort fields. + + if(this.showColumnPicker && !this.columnPicker) { + if(!this.columnPersistKey) { + console.error("No columnPersistKey defined"); + this.columnPicker = {}; + } else { + this.columnPicker = new openils.widget.GridColumnPicker( + openils.User.authtoken, this.columnPersistKey, this); + this.columnPicker.onSortChange = function(fields) {_this.cpSortHandler(fields)}; + this.columnPicker.onLoad = function(cpOpts) { + _this.cachedQueryOpts = opts; + _this.cachedQuerySearch = search; + _this.cpSortHandler(cpOpts.sortFields); // calls refresh() -> _loadAll() + }; + this.columnPicker.load(); + return; + } + } + + // column picker not wanted or already loaded + this._loadAll(opts, search); + }, + + _loadAll : function(opts, search) { + var self = this; + dojo.require('openils.PermaCrud'); if(this.loadProgressIndicator) dojo.style(this.loadProgressIndicator, 'visibility', 'visible'); - var self = this; opts = dojo.mixin( {limit : this.displayLimit, offset : this.displayOffset}, opts || {} -- 2.11.0