From 39fb2073effed0d5cabad6a0a2b562a3a0fcee40 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 11 Aug 2014 16:45:21 -0400 Subject: [PATCH] LP#1287370: allow AutoGrid to persist filter state and page offset By turning on a new AutoGrid option called urlNavigation, the current filter and offset is stored in a URL parameter called djgridops. This permits using the back button to return to an AutoGrid page at the place in the search results where the user left it. 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 --- .../web/js/dojo/openils/widget/AutoGrid.js | 65 +++++++++++++++++-- 1 file changed, 58 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 9114aa2302..8dac610f65 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -1,6 +1,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { dojo.provide('openils.widget.AutoGrid'); dojo.require('dojox.grid.DataGrid'); + dojo.require("dojox.encoding.base64"); dojo.require('dijit.layout.ContentPane'); dojo.require('openils.widget.AutoWidget'); dojo.require('openils.widget.AutoFieldWidget'); @@ -9,6 +10,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { dojo.require('openils.widget.GridColumnPicker'); dojo.require('openils.widget._GridHelperColumns'); dojo.require('openils.Util'); + dojo.require('openils.CGI'); dojo.requireLocalization('openils.widget', 'AutoFieldWidget'); dojo.declare( @@ -36,6 +38,7 @@ 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, /* by default, don't show auto-generated (sequence) fields */ showSequenceFields : false, @@ -83,6 +86,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }); + // TODO: support self.urlBasedFilterPaging var forw = dojo.create('a', { innerHTML : self.nls.NEXT, style : 'padding-right:6px;', @@ -111,13 +115,18 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { {fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields}) self.filterDialog.onApply = function(filter) { - self.cachedQuerySearch = filter; - self.resetStore(); - self.loadAll( - dojo.mixin( { offset : 0 }, self.cachedQueryOpts ), - self.cachedQuerySearch, - true - ); + if (self.urlBasedFilterPaging) { // TODO: grid config + self.applyFilterByPage(0, filter); + + } else { + self.cachedQuerySearch = filter; + self.resetStore(); + self.loadAll( + dojo.mixin( { offset : 0 }, self.cachedQueryOpts ), + self.cachedQuerySearch, + true + ); + } }; self.filterDialog.startup(); @@ -138,6 +147,38 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }, + applyFilterByPage : function(offset, filter) { + var ops = { + filter : filter, // TODO: load from query cache on offset-only change + offset : offset || 0 + } + + var encoded = dojox.encoding.base64.encode( + js2JSON(ops) + .split("") + .map(function(c) { return c.charCodeAt(0); }) + ); + + var cgi = new openils.CGI(); + cgi.param('djgridops', encoded); + location.href = cgi.url(); + }, + + extractFilterByPage : function() { + // these should only be extracted once per page + if (this.urlFiltersExtracted) return; + this.urlFiltersExtracted = true; + + var ops = new openils.CGI().param('djgridops'); + if (!ops) return; + + return JSON2js( + dojox.encoding.base64.decode(ops) + .map(function(b) {return String.fromCharCode(b)}) + .join("") + ); + }, + hideLoadProgressIndicator : function() { dojo.style(this.loadProgressIndicator, 'visibility', 'hidden'); }, @@ -583,6 +624,16 @@ 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); + } + + // 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 -- 2.43.2