custom org tree : tpac
authorBill Erickson <berick@esilibrary.com>
Mon, 19 Mar 2012 21:12:45 +0000 (17:12 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 21 Mar 2012 18:19:36 +0000 (14:19 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/org_selector.tt2

index a39fb35..1dddfb8 100644 (file)
@@ -128,19 +128,36 @@ sub init_ro_object_cache {
         unless(exists $cache{aouct_tree}) {
             $cache{aouct_tree} = undef;
 
-            my $tree_id = $e->json_querysearch_actor_org_unit_custom_tree([
+            my $tree_id = $e->search_actor_org_unit_custom_tree(
                 {purpose => 'opac', active => 't'},
                 {idlist => 1}
-            ])->[0];
+            )->[0];
 
             if ($tree_id) {
-                $cache{aouct_tree} = $e->search_actor_org_unit_custom_tree_node([
-                               {   parent => undef, tree => $tree_id}, 
+                my $node_tree = $e->search_actor_org_unit_custom_tree_node([
+                               {   parent_node => undef, tree => $tree_id}, 
                     {   flesh        => -1,
-                                       flesh_fields => {aou    =>  ['children']},
+                                       flesh_fields => {aouctn =>  ['children', 'org_unit']},
                                        order_by     => {aouctn => 'sibling_order'}
                                }
                        ])->[0];
+
+                # tree-ify the org units.  note that since the orgs are fleshed 
+                # upon retrieval, this org tree will not clobber ctx->{aou_tree}.
+                my @nodes = ($node_tree);
+                while (my $node = shift(@nodes)) {
+                    my $aou = $node->org_unit;
+                    $aou->children([]);
+                    for my $cnode (@{$node->children}) {
+                        my $child_org = $cnode->org_unit;
+                        $child_org->parent_ou($aou->id);
+                        $child_org->ou_type( $ro_object_subs->{get_aout}->($child_org->ou_type) );
+                        push(@{$aou->children}, $child_org);
+                        push(@nodes, $cnode);
+                    }
+                }
+
+                $cache{aouct_tree} = $node_tree->org_unit;
             }
         }
 
index 49775c4..878a2eb 100644 (file)
@@ -7,7 +7,7 @@
 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
 
 BLOCK build_org_selector;
-    node_stack = [{org => org_unit || ctx.aou_tree}];
+    node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
     inherited_vis = ctx.get_cgf('opac.org_unit.non_inheritied_visibility').enabled == 'f';
 
     IF !name; 
@@ -79,26 +79,23 @@ BLOCK build_org_selector;
                 disabled = 'disabled="disabled"';
             ELSIF node_value == value;
                 selected = 'selected="selected"';
-            END;
+            END; 
 
-            pad_depth = org_unit.ou_type.depth;
+            pad_depth = 0;
 
-            # copy loc groups appear as children of the owner (current) org
+            # copy loc groups appear as children of the owning org unit
             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;
+            # determine the depth by calculating the distance from the root
+            porg = ctx.get_aou(org_unit.parent_ou);
+            WHILE porg;
+                NEXT IF porg.opac_visible == 'f' AND !ctx.is_staff;
+                SET pad_depth = pad_depth + 1;
+                porg = ctx.get_aou(porg.parent_ou);
             END;
 
             pad_depth = pad_depth * 2;
-            display_name = loc_grp ? loc_grp.name : org_unit.name;
-            
-            %] 
+            display_name = loc_grp ? loc_grp.name : org_unit.name %]
 
             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
                 [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]