From: Bill Erickson Date: Mon, 19 Mar 2012 20:31:08 +0000 (-0400) Subject: Custom Org Tree : tpac X-Git-Tag: sprint4-merge-nov22~4307 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0ea00f3eef4aa1da707563784386fb73a170e1ce;p=working%2FEvergreen.git Custom Org Tree : tpac If configured and active, the tpac will now use the custom 'opac' tree for the org unit selectors. This will be true in both the public catalog and the staff client catalog. The staff client catalog will continue to display hidden org units. If the opac.org_unit.non_inheritied_visibility global flag is set, the public catalog will display child nodes of hidden org units in the custom tree. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index f46587f551..3fd9983c43 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -122,6 +122,47 @@ sub init_ro_object_cache { return [ values %{$cache{map}{aou}} ]; }; + $ro_object_subs->{aouct_tree} = sub { + + # fetch the org unit tree + unless(exists $cache{aouct_tree}) { + $cache{aouct_tree} = undef; + + my $tree_id = $e->search_actor_org_unit_custom_tree( + {purpose => 'opac', active => 't'}, + {idlist => 1} + )->[0]; + + if ($tree_id) { + my $node_tree = $e->search_actor_org_unit_custom_tree_node([ + {parent_node => undef, tree => $tree_id}, + { flesh => -1, + 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; + } + } + + return $cache{aouct_tree}; + }; # turns an ISO date into something TT can understand $ro_object_subs->{parse_datetime} = sub { diff --git a/Open-ILS/src/templates/opac/parts/org_selector.tt2 b/Open-ILS/src/templates/opac/parts/org_selector.tt2 index 49775c4da7..3e32040f08 100644 --- a/Open-ILS/src/templates/opac/parts/org_selector.tt2 +++ b/Open-ILS/src/templates/opac/parts/org_selector.tt2 @@ -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,22 @@ 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; + SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff; + 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 %]