From: Bill Erickson Date: Mon, 19 Mar 2012 21:12:45 +0000 (-0400) Subject: custom org tree : tpac X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bc8227ebd892b7bd122e93fb4d8598948da729c8;p=evergreen%2Fequinox.git custom org tree : tpac Signed-off-by: Bill Erickson --- 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 a39fb35277..1dddfb881a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -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; } } diff --git a/Open-ILS/src/templates/opac/parts/org_selector.tt2 b/Open-ILS/src/templates/opac/parts/org_selector.tt2 index 49775c4da7..878a2ebdaa 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,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 %]