From 71241c749e2cabc1d620783a7921133fef1ac162 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 31 Jul 2014 16:50:17 -0400 Subject: [PATCH] LP#1351317 ACQ fund selector filters cont. To improve load times, limit the funds we attempt to retrieve for various fund selectors to those the user has permission to use. Interfaces affected include the following: * Purchase order copy grid * Purchase order "New Charge" interface * Invoice "Add charge..." interface * Distribution formula configuration interface. Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- .../web/js/ui/default/acq/common/li_table.js | 34 ++++++++++++------- .../web/js/ui/default/acq/invoice/view.js | 16 +++++++++ .../web/js/ui/default/acq/po/item_table.js | 7 ++++ .../conify/global/acq/distribution_formula.js | 15 +++++++- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 1f48b08f9c..af9e29ad42 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -29,6 +29,7 @@ var fundLabelFormat = [ '${1} (${2})', 'id', 'code', 'year' ]; var fundSearchFormat = ['${0} (${1})', 'code', 'year']; +var fundSearchFilter = {active : 't'}; function nodeByName(name, context) { return dojo.query('[name='+name+']', context)[0]; @@ -160,13 +161,24 @@ function AcqLiTable() { dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')}; dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')}; + this.setFundSearchFilter = function(callback) { + new openils.User().getPermOrgList( + ['CREATE_PURCHASE_ORDER', 'MANAGE_FUND'], + function(orgs) { + fundSearchFilter.org = orgs; + if (callback) callback(); + }, + true, true // descendants, id_list + ); + } + this.afwCopyFieldArgs = function(field, perms) { return { "fmField" : field, "fmClass": 'acqlid', "labelFormat": (field == 'fund') ? fundLabelFormat : null, "searchFormat": (field == 'fund') ? fundSearchFormat : null, - "searchFilter": (field == 'fund') ? {"active": "t"} : null, + "searchFilter": (field == 'fund') ? fundSearchFilter : null, "orgLimitPerms": [perms], "dijitArgs": { "required": false, @@ -250,16 +262,13 @@ function AcqLiTable() { // The list of funds can be huge. Before fetching // funds for PO modification, see where the user has // perms and limit the retreived funds accordingly. - // Note: this code only runs once per page load, so - // no caching is required. - new openils.User().getPermOrgList( - ['CREATE_PURCHASE_ORDER', 'MANAGE_FUND'], - function(orgs) { - args.searchFilter.org = orgs; - buildOneBatchWidget(field, args); - }, - true, true // descendants, id_list - ); + // Note: This is the first instance of fund list + // retrieval. All future fund list retrievals will + // benefit directly from having applied the fund + // search filter org units here. + self.setFundSearchFilter(function() { + buildOneBatchWidget(field, args); + }); return; } @@ -2318,6 +2327,7 @@ function AcqLiTable() { searchFilter = (copy.fund() ? {"-or": {"active": "t", "id": copy.fund()}} : {"active" : "t"}); + searchFilter.org = fundSearchFilter.org; } else { searchFilter = null; } @@ -3308,7 +3318,7 @@ function AcqLiTable() { selfReference : true, labelFormat : fundLabelFormat, searchFormat : fundSearchFormat, - searchFilter : {"active": "t"}, + searchFilter : fundSearchFilter, parentNode : dojo.byId('acq-lit-batch-fund-selector'), orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'], dijitArgs : { "required": true, "labelType": "html" }, diff --git a/Open-ILS/web/js/ui/default/acq/invoice/view.js b/Open-ILS/web/js/ui/default/acq/invoice/view.js index f447f182b6..3d42e4359f 100644 --- a/Open-ILS/web/js/ui/default/acq/invoice/view.js +++ b/Open-ILS/web/js/ui/default/acq/invoice/view.js @@ -20,6 +20,7 @@ var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq'); var fundLabelFormat = ['${0} (${1})', 'code', 'year']; var fundSearchFormat = ['${0} (${1})', 'code', 'year']; +var fundSearchFilter = {}; var cgi = new openils.CGI(); var pcrud = new openils.PermaCrud(); @@ -48,6 +49,19 @@ function nodeByName(name, context) { } function init() { + // before rendering any fund selectors, limit the funds to + // attempt to retrieve to those the user can actually use. + new openils.User().getPermOrgList( + ['ADMIN_INVOICE','CREATE_INVOICE','MANAGE_FUND'], + function(orgs) { + fundSearchFilter.org = orgs; + init2(); + }, + true, true // descendants, id_list + ); +} + +function init2() { attachLi = cgi.param('attach_li') || []; if (!dojo.isArray(attachLi)) @@ -101,6 +115,7 @@ function init() { searchFilter : {active : 't'}, labelFormat : fundLabelFormat, searchFormat : fundSearchFormat, + searchFilter : fundSearchFilter, dijitArgs : {required : true}, parentNode : dojo.byId('acq-invoice-extra-copies-fund') }); @@ -613,6 +628,7 @@ function addInvoiceItem(item) { fmField : 'fund', labelFormat : fundLabelFormat, searchFormat : fundSearchFormat, + searchFilter : fundSearchFilter, readOnly : invoice && openils.Util.isTrue(invoice.complete()), dijitArgs : {required : true}, parentNode : nodeByName('fund', row) diff --git a/Open-ILS/web/js/ui/default/acq/po/item_table.js b/Open-ILS/web/js/ui/default/acq/po/item_table.js index 3c1f9a55c5..4ed9a722c0 100644 --- a/Open-ILS/web/js/ui/default/acq/po/item_table.js +++ b/Open-ILS/web/js/ui/default/acq/po/item_table.js @@ -26,6 +26,13 @@ function PoItemTable() { "noCache": true }; + // limit funds fetched to those the user can use + new openils.User().getPermOrgList( + ['CREATE_PURCHASE_ORDER', 'MANAGE_FUND'], + function(orgs) { self.fundAWArgs.searchFilter.org = orgs }, + true, true // descendants, id_list + ); + this.reset(); }; diff --git a/Open-ILS/web/js/ui/default/conify/global/acq/distribution_formula.js b/Open-ILS/web/js/ui/default/conify/global/acq/distribution_formula.js index a2d5eece93..41bac335de 100644 --- a/Open-ILS/web/js/ui/default/conify/global/acq/distribution_formula.js +++ b/Open-ILS/web/js/ui/default/conify/global/acq/distribution_formula.js @@ -14,6 +14,7 @@ var virtualId = -1; var pcrud; var _collection_code_textboxes = []; var _collection_code_kludge_active = false; +var fundSearchFilter = {active : 't'}; function gridDataLoader() { fListGrid.resetStore(); @@ -38,13 +39,24 @@ function gridDataLoader() { ); } +function setFundSearchFilter(callback) { + new openils.User().getPermOrgList( + ['ADMIN_ACQ_DISTRIB_FORMULA'], + function(orgs) { + fundSearchFilter.org = orgs; + if (callback) callback(); + }, + true, true // descendants, id_list + ); +} + function draw() { pcrud = new openils.PermaCrud(); if(formulaId) { openils.Util.hide('formula-list-div'); - drawFormulaSummary(); + setFundSearchFilter(drawFormulaSummary); } else { openils.Util.hide('formula-entry-div'); @@ -153,6 +165,7 @@ function addEntry(entry) { fmField : field, fmObject : entry, fmClass : 'acqdfe', + searchFilter : (field == 'fund') ? fundSearchFilter : null, parentNode : byName(row, field), orgDefaultsToWs : true, orgLimitPerms : ['ADMIN_ACQ_DISTRIB_FORMULA'], -- 2.43.2