Org unit prox adjustment tweaks
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 14 Mar 2013 17:58:47 +0000 (13:58 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 27 Mar 2013 19:48:41 +0000 (15:48 -0400)
1) UI change - pre-select highest OU where user can edit

There's a dropdown in the org unit proximity adjustment interface that
affects the scope of what you can see in the table below.  Before, that
dropdown would be set to the user's home UO (say, BR1 in the example org
tree).  But you might have the permission to make changes everywhere, so
you add a proximity adjustment that affects BR3 in some way.  As soon as
you'd refresh the interface, your new proximity adjustment would not be
visible, because your scope selector would default to BR1.

So now the dropdown defaults to the first context where you have the
permission, which in all but eccentric setups should be the highest OU
(and therefore broadest scope) where you have the permission.

This could also improve other interfaces in the future.  Anything that
invokes openils.User.buildPermOrgSelector() can pass -1 as the third
parameter to get the new behavior.

2) Change UNIQUE index at DB layer.

This prevents the creation of rows that would give the hold targeter
conflicting directives.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/005.schema.actors.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aoupa-unique-constraint.sql [new file with mode: 0644]
Open-ILS/src/templates/conify/global/config/org_unit_proximity_adjustment.tt2
Open-ILS/web/js/dojo/openils/User.js

index c92ede4..8d63430 100644 (file)
@@ -393,7 +393,15 @@ CREATE TABLE actor.org_unit_proximity_adjustment (
     circ_mod            TEXT,       -- REFERENCES config.circ_modifier (code),
     CONSTRAINT prox_adj_criterium CHECK (COALESCE(item_circ_lib::TEXT,item_owning_lib::TEXT,copy_location::TEXT,hold_pickup_lib::TEXT,hold_request_lib::TEXT,circ_mod) IS NOT NULL)
 );
-CREATE UNIQUE INDEX prox_adj_once_idx ON actor.org_unit_proximity_adjustment (item_circ_lib,item_owning_lib,copy_location,hold_pickup_lib,hold_request_lib,circ_mod);
+CREATE UNIQUE INDEX prox_adj_once_idx ON actor.org_unit_proximity_adjustment (
+    COALESCE(item_circ_lib, -1),
+    COALESCE(item_owning_lib, -1),
+    COALESCE(copy_location, -1),
+    COALESCE(hold_pickup_lib, -1),
+    COALESCE(hold_request_lib, -1),
+    COALESCE(circ_mod, ''),
+    pos
+);
 CREATE INDEX prox_adj_circ_lib_idx ON actor.org_unit_proximity_adjustment (item_circ_lib);
 CREATE INDEX prox_adj_owning_lib_idx ON actor.org_unit_proximity_adjustment (item_owning_lib);
 CREATE INDEX prox_adj_copy_location_idx ON actor.org_unit_proximity_adjustment (copy_location);
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aoupa-unique-constraint.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aoupa-unique-constraint.sql
new file mode 100644 (file)
index 0000000..1f5221d
--- /dev/null
@@ -0,0 +1,17 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+DROP INDEX actor.prox_adj_once_idx;
+
+CREATE UNIQUE INDEX prox_adj_once_idx ON actor.org_unit_proximity_adjustment (
+    COALESCE(item_circ_lib, -1),
+    COALESCE(item_owning_lib, -1),
+    COALESCE(copy_location, -1),
+    COALESCE(hold_pickup_lib, -1),
+    COALESCE(hold_request_lib, -1),
+    COALESCE(circ_mod, ''),
+    pos
+);
+
+COMMIT;
index 6a0c67b..9f6f32f 100644 (file)
@@ -72,7 +72,7 @@
             new openils.User().buildPermOrgSelector(
                 "ADMIN_PROXIMITY_ADJUSTMENT",
                 context_org_selector,
-                null,
+                -1, /* high OU where permission held */
                 function() {
                     context_org_selector.onChange =
                         reload_grid_from_ou_selector;
index 60e5f91..ef17bf8 100644 (file)
@@ -306,17 +306,18 @@ if(!dojo._hasResource["openils.User"]) {
          * using the orgs where the user has the requested permission.
          * @param perm The permission to check
          * @param selector The pre-created dijit.form.FilteringSelect object.  
+         * @param selectedOrg org to select in FilteringSelect object. null defaults to user ws_ou, -1 will select the first OU where the perm is held, typically the top of a [sub]tree.
          */
         buildPermOrgSelector : function(perm, selector, selectedOrg, onload) {
             var _u = this;
     
             dojo.require('dojo.data.ItemFileReadStore');
 
-            function hookupStore(store) {
+            function hookupStore(store, useOrg) {
                 selector.store = store;
                 selector.startup();
-                if(selectedOrg != null)
-                    selector.setValue(selectedOrg);
+                if(useOrg != null)
+                    selector.setValue(useOrg);
                 else
                     selector.setValue(_u.user.ws_ou());
                 if(onload) onload();
@@ -324,7 +325,10 @@ if(!dojo._hasResource["openils.User"]) {
 
             function buildTreePicker(orgList) {
                 var store = new dojo.data.ItemFileReadStore({data:aou.toStoreData(orgList)});
-                hookupStore(store);
+                if (selectedOrg == -1 && orgList[0])
+                    selectedOrg = orgList[0].id();
+
+                hookupStore(store, selectedOrg);
                 _u.permOrgStoreCache[perm] = store;
             }