From 21604aee487a1c78981e9bdecffc272885886693 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 12 Aug 2014 12:03:05 -0400 Subject: [PATCH] LP#1287370: apply filter/offset persistence to the fund search page This patch completes the AutoGrid work and applies the filter & offset persistence to the fund search page. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton Signed-off-by: Erica Rohlfs Signed-off-by: Mike Rylander Signed-off-by: Ben Shum --- Open-ILS/src/templates/acq/fund/list.tt2 | 1 + Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 67 +++++++++++++++------- .../web/js/ui/default/acq/financial/list_funds.js | 20 ++++++- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/Open-ILS/src/templates/acq/fund/list.tt2 b/Open-ILS/src/templates/acq/fund/list.tt2 index ab6de7b539..17e6ee3861 100644 --- a/Open-ILS/src/templates/acq/fund/list.tt2 +++ b/Open-ILS/src/templates/acq/fund/list.tt2 @@ -163,6 +163,7 @@ fmClass='acqf' showLoadFilter='true' showPaginator='true' + urlNavigation='true' editOnEnter='true'> diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 8dac610f65..873bb244d3 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -38,7 +38,12 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { showLoadFilter : true, onItemReceived : null, suppressLinkedFields : null, // list of fields whose linked display data should not be fetched from the server - urlBasedFilterPaging : false, + urlNavigation : false, + + // When using urlNavigation, this is a stash where the + // caller can place arbitrary data to be passed around + // between pages. + urlUserData : {}, /* by default, don't show auto-generated (sequence) fields */ showSequenceFields : false, @@ -61,6 +66,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { this.overrideEditWidgets = {}; this.overrideEditWidgetClass = {}; this.overrideWidgetArgs = {}; + this.extractUrlOps(); this.nls = dojo.i18n.getLocalization('openils.widget', 'AutoFieldWidget'); @@ -86,14 +92,21 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }); - // TODO: support self.urlBasedFilterPaging + // TODO: support self.urlNavigation var forw = dojo.create('a', { innerHTML : self.nls.NEXT, style : 'padding-right:6px;', href : 'javascript:void(0);', onclick : function() { self.cachedQueryOpts.offset = self.displayOffset += self.displayLimit; - self.refresh(); + if (self.urlNavigation) { + self.applyAndExecuteUrlOps( + self.cachedQueryOpts.offset, + self.cachedQuerySearch + ); + } else { + self.refresh(); + } } }); @@ -115,8 +128,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { {fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields}) self.filterDialog.onApply = function(filter) { - if (self.urlBasedFilterPaging) { // TODO: grid config - self.applyFilterByPage(0, filter); + if (self.urlNavigation) { + self.applyAndExecuteUrlOps(0, filter); } else { self.cachedQuerySearch = filter; @@ -147,10 +160,12 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }, - applyFilterByPage : function(offset, filter) { + // set URL options then jump to the new URL + applyAndExecuteUrlOps : function(offset, filter) { var ops = { filter : filter, // TODO: load from query cache on offset-only change - offset : offset || 0 + offset : offset || 0, + userData : this.urlUserData } var encoded = dojox.encoding.base64.encode( @@ -164,19 +179,19 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { location.href = cgi.url(); }, - extractFilterByPage : function() { - // these should only be extracted once per page - if (this.urlFiltersExtracted) return; - this.urlFiltersExtracted = true; - + // extract options encoded in the URL + extractUrlOps : function() { var ops = new openils.CGI().param('djgridops'); if (!ops) return; - return JSON2js( + ops = JSON2js( dojox.encoding.base64.decode(ops) .map(function(b) {return String.fromCharCode(b)}) .join("") ); + + this.urlOps = ops; + this.urlUserData = ops.userData; }, hideLoadProgressIndicator : function() { @@ -624,16 +639,26 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { if (!filter_triggered || !this.preFilterSearch) this.preFilterSearch = dojo.clone( this.cachedQuerySearch ); - var url_ops = this.extractFilterByPage(); - if (url_ops) { - opts.offset = url_ops.offset; - search = dojo.mixin(search || {}, url_ops.filter); + if (this.urlNavigation) { + if (!this.urlOpsApplied) { + this.urlOpsApplied = true; + // on the first page load, apply the ops from the URL + if (this.urlOps) { + console.log('applying url ops: ' + js2JSON(this.urlOps)); + opts.offset = self.displayOffset = this.urlOps.offset; + search = dojo.mixin(search || {}, this.urlOps.filter); + } + } else { + // subsequent calls to loadAll() suggest changing + // filters / paging / etc, propagate new values + // to the new URL + return this.applyAndExecuteUrlOps( + this.displayOffset, + this.cachedQuerySearch + ); + } } - // TODO: remove these debug lines - console.log('search = ' + js2JSON(search)); - console.log('opts = ' + js2JSON(opts)); - if(search) new openils.PermaCrud().search(this.fmClass, search, opts); else diff --git a/Open-ILS/web/js/ui/default/acq/financial/list_funds.js b/Open-ILS/web/js/ui/default/acq/financial/list_funds.js index 09a47d55d8..dfd47702f1 100644 --- a/Open-ILS/web/js/ui/default/acq/financial/list_funds.js +++ b/Open-ILS/web/js/ui/default/acq/financial/list_funds.js @@ -37,6 +37,10 @@ var cachedFunds = []; function initPage() { contextOrg = openils.User.user.ws_ou(); + // Propagate the context org from the URL data into our org selector. + if (lfGrid.urlUserData && lfGrid.urlUserData.contextOrg) + contextOrg = lfGrid.urlUserData.contextOrg; + /* Reveal controls for rollover without money if org units say ok. * Actual ability to do the operation is controlled in the database, of * course. */ @@ -59,6 +63,9 @@ function initPage() { dojo.byId('oils-acq-rollover-ctxt-org').innerHTML = fieldmapper.aou.findOrgUnit(contextOrg).shortname(); rolloverMode = false; + // tell the grid to pass the context org info along + // with the encoded URL data so we can re-propagate + lfGrid.displayOffset = 0; // new org means a new search gridDataLoader(); } ); @@ -82,7 +89,8 @@ function initPage() { function(list) { adminPermOrgs = list; loadFundGrid( - new openils.CGI().param('year') + lfGrid.urlUserData.year + || new openils.CGI().param('year') || new Date().getFullYear().toString()); }, true, true @@ -128,6 +136,9 @@ function loadFundGrid(year) { }); } + lfGrid.urlUserData.year = year; + lfGrid.urlUserData.contextOrg = contextOrg; + lfGrid.loadAll( { flesh : 1, @@ -157,13 +168,18 @@ function loadYearSelector() { fundFilterYearSelect.store = new dojo.data.ItemFileWriteStore({data:yearStore}); // default to this year - fundFilterYearSelect.setValue(new Date().getFullYear().toString()); + fundFilterYearSelect.setValue( + // propagate year from URL if available + lfGrid.urlUserData.year || + new Date().getFullYear().toString() + ); dojo.connect( fundFilterYearSelect, 'onChange', function() { rolloverMode = false; + lfGrid.displayOffset = 0; gridDataLoader(); } ); -- 2.11.0