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 BLOCK build_org_selector;
10 node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
11 inherited_vis = ctx.get_cgf('opac.org_unit.non_inherited_visibility').enabled == 'f';
15 IF show_loc_groups; name = 'locg'; END;
18 value = ctx.search_ou;
20 value = CGI.param('locg') || ctx.search_ou;
25 <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
27 WHILE node_stack.size > 0;
28 node = node_stack.pop();
30 loc_grp = node.loc_grp;
35 visible = org_unit.opac_visible == 't';
37 # org and all children are invisible.
38 NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
40 IF !loc_grp; # processing an org unit
44 # add the location groups that sort below the child org units
45 FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
47 top_loc_groups.push(grp);
49 node_stack.push({org => org_unit, loc_grp => grp});
54 # add the child org units
55 FOR child IN org_unit.children.reverse;
56 node_stack.push({org => child});
59 # add the location groups that sort to the top
60 # above the child org units
61 FOR grp IN top_loc_groups;
62 node_stack.push({org => org_unit, loc_grp => grp});
67 # This org unit is not publicly visible (though its children may be).
68 NEXT UNLESS ctx.is_staff OR visible;
72 node_value = node_value _ ':' _ loc_grp.id;
73 css_class = 'class="loc_grp"';
75 css_class = 'class="org_unit"';
78 IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
79 disabled = 'disabled="disabled"';
80 ELSIF node_value == value;
81 selected = 'selected="selected"';
86 # copy loc groups appear as children of the owning org unit
87 SET pad_depth = pad_depth + 1 IF loc_grp;
89 # determine the depth by calculating the distance from the root
90 porg = ctx.get_aou(org_unit.parent_ou);
92 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
93 porg = ctx.get_aou(porg.parent_ou);
96 pad_depth = pad_depth * 2;
97 display_name = loc_grp ? loc_grp.name : org_unit.name %]
99 <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]>
100 [% ' ' FOR [0..pad_depth]; display_name | html %]