From 2986646c02712197449e9c15474088f57b138753 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 May 2014 14:32:14 -0400 Subject: [PATCH] LP#1254918 limit ACQ batch update fund retrieval by perms In the ACQ batch update bar along the top of the PO page, limit the number of funds which require permission checks on the server by limiting the fund search to those at org units where the requesting user has the CREATE_PURCHSE_ORDER or MANAGE_FUND permissions. In other words, if a user only has create-po perms at Branch 1, we can specifically request funds at that branch (or below) for display so that the server (PCRUD) does not have to inspect unrelated funds for permissibility. This speeds up fund retrieval. Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- .../web/js/ui/default/acq/common/li_table.js | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 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 384607ac00..c98cec4a54 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 @@ -217,32 +217,53 @@ function AcqLiTable() { } ); + function buildOneBatchWidget(field, args) { + (new openils.widget.AutoFieldWidget(args)).build( + function(w, aw) { + if (field == "fund") { + dojo.connect( + w, "onChange", function(val) { + self._updateFundSelectorStyle(aw, val); + } + ); + if (w.store) + self._ensureCSSFundClasses(w.store); + } + + dojo.style(w.domNode, {"width": "10em"}); + w.attr( + "disabled", + dojo.indexOf(disabled_fields, field) != -1 + ); + self.batchUpdateWidgets[field] = w; + } + ); + } + dojo.forEach( ["owning_lib","location","collection_code","circ_modifier","fund"], function(field) { var args = self.afwCopyFieldArgs(field,"CREATE_PURCHASE_ORDER"); args.parentNode = dojo.byId("acq-bu-" + field); - (new openils.widget.AutoFieldWidget(args)).build( - function(w, aw) { - if (field == "fund") { - dojo.connect( - w, "onChange", function(val) { - self._updateFundSelectorStyle(aw, val); - } - ); - if (w.store) - self._ensureCSSFundClasses(w.store); - } + if (field == 'fund') { + // 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 + ); + return; + } - dojo.style(w.domNode, {"width": "10em"}); - w.attr( - "disabled", - dojo.indexOf(disabled_fields, field) != -1 - ); - self.batchUpdateWidgets[field] = w; - } - ); + buildOneBatchWidget(field, args); } ); -- 2.43.2