2 # Org Unit Selector Widget :
3 # INCLUDE build_org_selector id='selector-id' name='selector-name'
4 # value=org_id show_loc_groups=1/0 can_have_vols_only=1/0
6 # NOTE: DO NOT USE PROCESS
7 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
9 PROCESS "opac/parts/misc_util.tt2";
12 BLOCK build_org_selector;
13 node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
14 inherited_vis = ctx.get_cgf('opac.org_unit.non_inherited_visibility').enabled == 'f';
24 <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
26 WHILE node_stack.size > 0;
27 node = node_stack.pop();
29 loc_grp = node.loc_grp;
34 visible = org_unit.opac_visible == 't';
36 # org and all children are invisible.
37 NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
39 IF !loc_grp; # processing an org unit
43 # add the location groups that sort below the child org units
44 FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
46 top_loc_groups.push(grp);
48 node_stack.push({org => org_unit, loc_grp => grp});
53 # add the child org units
54 FOR child IN org_unit.children.reverse;
55 node_stack.push({org => child});
58 # add the location groups that sort to the top
59 # above the child org units
60 FOR grp IN top_loc_groups;
61 node_stack.push({org => org_unit, loc_grp => grp});
66 # This org unit is not publicly visible (though its children may be).
67 NEXT UNLESS ctx.is_staff OR visible;
71 node_value = node_value _ ':' _ loc_grp.id;
72 css_class = 'class="loc_grp"';
74 css_class = 'class="org_unit"';
77 IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
78 disabled = 'disabled="disabled"';
79 ELSIF node_value == value;
80 selected = 'selected="selected"';
85 # copy loc groups appear as children of the owning org unit
86 SET pad_depth = pad_depth + 1 IF loc_grp;
88 # determine the depth by calculating the distance from the root
89 porg = ctx.get_aou(org_unit.parent_ou);
91 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
92 porg = ctx.get_aou(porg.parent_ou);
95 pad_depth = pad_depth * 2;
96 display_name = loc_grp ? loc_grp.name : org_unit.name %]
98 <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]>
99 [% ' ' FOR [0..pad_depth]; display_name | html %]