TPac: non-inherited org unit visibility
authorBill Erickson <berick@esilibrary.com>
Mon, 12 Mar 2012 16:22:22 +0000 (12:22 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 2 Apr 2012 17:39:01 +0000 (13:39 -0400)
Adds support for displaying org units that are children of hidden org
units in the tpac org unit selector.  A new global flag was added to
control this behavior called "opac.org_unit.non_inheritied_visibility" /
"Org Units Do Not Inherit Visibility".

To avoid confusion / distorted org unit trees, children of hidden org
units are left-padded one less for each hidden parent org unit.  For
example, in the stock org tree, if Sys2 is opac_visible=false (and the
global flag is enabled), the tree in the tpac would appear like so:

Cons
- Sys 1
-- BR1
--- SL1
-- BR2
- BR3
- BR4

Similarly, if CONS was also hidden, the whole tree would be shifted left
by 1 pad depth.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_opac_vis_and_sorting.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/org_selector.tt2

index 6c97858..2d3c8ec 100644 (file)
@@ -11541,3 +11541,15 @@ INSERT INTO action_trigger.environment (event_def, path)
 INSERT INTO actor.toolbar(org,label,layout) VALUES
     ( 1, 'circ', '["circ_checkout","circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","patron_search","patron_register","toolbarspacer.3","hotkeys_toggle"]' ),
     ( 1, 'cat', '["circ_checkin","toolbarseparator.1","search_opac","copy_status","toolbarseparator.2","create_marc","authority_manage","retrieve_last_record","toolbarspacer.3","hotkeys_toggle"]' );
+
+INSERT INTO config.global_flag (name, enabled, label) 
+    VALUES (
+        'opac.org_unit.non_inheritied_visibility',
+        FALSE,
+        oils_i18n_gettext(
+            'opac.org_unit.non_inheritied_visibility',
+            'Org Units Do Not Inherit Visibility',
+            'cgf',
+            'label'
+        )
+    );
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_opac_vis_and_sorting.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_unit_opac_vis_and_sorting.sql
new file mode 100644 (file)
index 0000000..115613a
--- /dev/null
@@ -0,0 +1,24 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO config.global_flag (name, enabled, label) 
+    VALUES (
+        'opac.org_unit.non_inheritied_visibility',
+        FALSE,
+        oils_i18n_gettext(
+            'opac.org_unit.non_inheritied_visibility',
+            'Org Units Do Not Inherit Visibility',
+            'cgf',
+            'label'
+        )
+    );
+
+COMMIT;
+
+/* UNDO
+BEGIN;
+DELETE FROM config.global_flag WHERE name = 'opac.org_unit.non_inheritied_visibility';
+COMMIT;
+*/
+
index fd9c8c0..49775c4 100644 (file)
@@ -8,6 +8,8 @@
 
 BLOCK build_org_selector;
     node_stack = [{org => org_unit || ctx.aou_tree}];
+    inherited_vis = ctx.get_cgf('opac.org_unit.non_inheritied_visibility').enabled == 'f';
+
     IF !name; 
         name = 'loc';
         IF show_loc_groups; name = 'locg'; END;
@@ -30,8 +32,10 @@ BLOCK build_org_selector;
             css_class = '';
             disabled = '';
             selected = '';
+            visible = org_unit.opac_visible == 't';
 
-            NEXT UNLESS ctx.is_staff || org_unit.opac_visible == 't';
+            # org and all children are invisible.
+            NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
 
             IF !loc_grp; # processing an org unit
 
@@ -57,11 +61,15 @@ BLOCK build_org_selector;
                 FOR grp IN top_loc_groups;
                     node_stack.push({org => org_unit, loc_grp => grp});
                 END;
+
             END;
 
+            # This org unit is not publicly visible (though its children may be).
+            NEXT UNLESS ctx.is_staff OR visible;
+
             node_value = ou_id;
-            IF loc_grp; node_value = node_value _ ':' _ loc_grp.id; END;
             IF loc_grp;
+                node_value = node_value _ ':' _ loc_grp.id; 
                 css_class = 'class="loc_grp"';
             ELSE;
                 css_class = 'class="org_unit"';
@@ -71,20 +79,31 @@ BLOCK build_org_selector;
                 disabled = 'disabled="disabled"';
             ELSIF node_value == value;
                 selected = 'selected="selected"';
-            END %] 
+            END;
+
+            pad_depth = org_unit.ou_type.depth;
+
+            # copy loc groups appear as children of the owner (current) org
+            SET pad_depth = pad_depth + 1 IF loc_grp;
+
+            # for each parent org unit that is hidden, decrease the pad depth by one.  
+            IF !ctx.is_staff; 
+                porg = ctx.get_aou(org_unit.parent_ou);
+                WHILE porg;
+                    SET pad_depth = pad_depth - 1 IF porg.opac_visible == 'f';
+                    porg = ctx.get_aou(porg.parent_ou);
+                END;
+            END;
+
+            pad_depth = pad_depth * 2;
+            display_name = loc_grp ? loc_grp.name : org_unit.name;
+            
+            %] 
 
             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
-            [%
-                # loc_grp's are displayed as children of the current org
-                depth = org_unit.ou_type.depth;
-                IF loc_grp; depth = depth + 1; END;
-                pad = depth * 2;
-                FOR idx IN [0..pad]; '&nbsp;'; END;
-                loc_grp ? loc_grp.name : org_unit.name | html ;
-            %]
+                [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]
             </option> 
-            [%
-        END;
-    %]
+
+        [% END %]
     </select>
 [% END %]