LP#1254918 limit ACQ batch update fund retrieval by perms
authorBill Erickson <berick@esilibrary.com>
Fri, 9 May 2014 18:32:14 +0000 (14:32 -0400)
committerBen Shum <bshum@biblio.org>
Thu, 10 Jul 2014 19:59:28 +0000 (15:59 -0400)
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 <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 384607a..c98cec4 100644 (file)
@@ -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);
             }
         );