From 23a882dc5fa2432baa3316a7346e16b1553426be Mon Sep 17 00:00:00 2001 From: erickson Date: Sun, 16 Aug 2009 15:49:12 +0000 Subject: [PATCH] added support to autogrid for loading paged data via callback for UIs that load their own data. added paging to fund list page. added paging options to fund by org fetcher git-svn-id: svn://svn.open-ils.org/ILS/trunk@13843 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Financials.pm | 20 +++++++-- Open-ILS/web/js/dojo/openils/widget/AutoGrid.js | 19 +++++++- .../web/js/ui/default/acq/financial/list_funds.js | 42 +++++++++++------ .../templates/default/acq/financial/list_funds.tt2 | 52 ++++++---------------- 4 files changed, 75 insertions(+), 58 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm index 2ac090f31..4c843f489 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm @@ -286,19 +286,31 @@ __PACKAGE__->register_method( ); sub retrieve_org_funds { - my($self, $conn, $auth, $org_id_list, $options) = @_; + my($self, $conn, $auth, $filter, $options) = @_; my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; + $filter ||= {}; $options ||= {}; my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUND'; return OpenILS::Event->new('BAD_PARAMS') unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/; - my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list : + $filter->{org} = $filter->{org} || $U->user_has_work_perm_at($e, $limit_perm, {descendants =>1}); - return undef unless @$org_ids; - my $funds = $e->search_acq_fund({org => $org_ids}); + return undef unless @{$filter->{org}}; + + + my $query = [ + $filter, + { + limit => $$options{limit} || 50, + offset => $$options{offset} || 0, + order_by => $$options{order_by} || {acqf => 'name'} + } + ]; + + my $funds = $e->search_acq_fund($query); for my $fund (@$funds) { $fund->summary(retrieve_fund_summary_impl($e, $fund)) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js index 3e845056b..f903d7ac6 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js @@ -38,6 +38,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { this.initAutoEnv(); this.attr('structure', this._compileStructure()); this.setStore(this.buildAutoStore()); + this.cachedQueryOpts = {}; if(this.showColumnPicker) { if(!this.columnPickerPrefix) { @@ -82,7 +83,10 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { onclick : function() { self.resetStore(); self.cachedQueryOpts.offset = self.displayOffset -= self.displayLimit; - self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch); + if(self.dataLoader) + self.dataLoader() + else + self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch); } }); @@ -93,7 +97,10 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { onclick : function() { self.resetStore(); self.cachedQueryOpts.offset = self.displayOffset += self.displayLimit; - self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch); + if(self.dataLoader) + self.dataLoader() + else + self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch); } }); @@ -108,6 +115,14 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) { } }, + hideLoadProgressIndicator : function() { + dojo.style(this.loadProgressIndicator, 'visibility', 'hidden'); + }, + + showLoadProgressIndicator : function() { + dojo.style(this.loadProgressIndicator, 'visibility', 'visible'); + }, + /* Don't allow sorting on the selector column */ canSort : function(rowIdx) { if(rowIdx == 1 && !this.hideSelector) 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 947756f2a..50f65ac52 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 @@ -25,14 +25,29 @@ function getBalanceInfo(rowIndex, item) { return 0; } -function loadFundGrid() { +function loadFundGrid(year) { var yearStore = {identifier:'year', name:'year', items:[]}; var yearsAdded = {}; /* don't duplicate the years in the selector */ + lfGrid.resetStore(); + + if(!year) year = new Date().getFullYear().toString(); + + lfGrid.dataLoader = function() { loadFundGrid(year); }; fieldmapper.standardRequest( [ 'open-ils.acq', 'open-ils.acq.fund.org.retrieve'], { async: true, - params: [openils.User.authtoken, null, {flesh_summary:1}], + + params: [ + openils.User.authtoken, + {year:year}, + { + flesh_summary:1, + limit: lfGrid.displayLimit, + offset: lfGrid.displayOffset + } + ], + onresponse : function(r) { if(lf = openils.Util.readResponse(r)) { openils.acq.Fund.cache[lf.id()] = lf; @@ -44,28 +59,29 @@ function loadFundGrid() { } } }, + oncomplete : function(r) { - // sort the unique list of years and set the selector to "now" if possible yearStore.items = yearStore.items.sort().reverse(); fundFilterYearSelect.store = new dojo.data.ItemFileReadStore({data:yearStore}); var today = new Date().getFullYear().toString(); + if(today in yearsAdded) fundFilterYearSelect.setValue(today); + + lfGrid.hideLoadProgressIndicator(); + + dojo.connect( + fundFilterYearSelect, + 'onChange', + function() { + loadFundGrid(fundFilterYearSelect.getValue()); + } + ); } } ); } -function filterGrid() { - var year = fundFilterYearSelect.getValue(); - console.log(year); - if(year) - lfGrid.setQuery({year:year}); - else - lfGrid.setQuery({id:'*'}); - - lfGrid.update(); -} openils.Util.addOnLoad(loadFundGrid); diff --git a/Open-ILS/web/templates/default/acq/financial/list_funds.tt2 b/Open-ILS/web/templates/default/acq/financial/list_funds.tt2 index 7041744a1..1d2c4833f 100644 --- a/Open-ILS/web/templates/default/acq/financial/list_funds.tt2 +++ b/Open-ILS/web/templates/default/acq/financial/list_funds.tt2 @@ -3,45 +3,18 @@ - - - -
-
Funds
-
- - -
-
- -
- Year -
+ + + + + + +
Funds + Year + + +
-- 2.11.0