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
5 # can_have_users_only=1/0 valid_org_list=[1,2,3] show_lassos=1/0
7 # NOTE: DO NOT USE PROCESS
8 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
10 PROCESS "opac/parts/misc_util.tt2";
13 BLOCK build_org_selector;
14 node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
15 inherited_vis = ctx.get_cgf('opac.org_unit.non_inherited_visibility').enabled == 'f';
24 # if the selected org unit is out of hiding scope,
25 # disable the ou-hide scoping altogether.
26 hiding_disabled = ctx.org_hiding_disabled(value);
28 # Some setup for Library Groups
30 base_value = value.split(':').0;
34 <select [% IF id %] id='[% id %]' [% END -%]
35 title='[% arialabel || l("Select Library") %]'
38 [% IF show_lassos AND ctx.lassos.size > 0;
39 %] <optgroup label="[% l('Library Groups') %]"> [%
40 FOR lasso IN ctx.lassos;
41 opt_value = base_value _ ':lasso(' _ lasso.id _ ')';
43 IF !lasso_selected AND ctx.search_lasso == lasso.id;
45 selected = 'selected="selected"';
47 <option value='[% opt_value %]' [% selected %]>
48 [% lasso.name | html %]
52 <optgroup label="[% l('Libraries') %]">
55 WHILE node_stack.size > 0;
56 node = node_stack.pop();
58 loc_grp = node.loc_grp;
63 visible = org_unit.opac_visible == 't';
65 # org and all children are invisible.
66 NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
68 IF !loc_grp; # processing an org unit
72 # add the location groups that sort below the child org units
73 FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
75 top_loc_groups.push(grp);
77 node_stack.push({org => org_unit, loc_grp => grp});
82 # add the child org units
83 FOR child IN org_unit.children.reverse;
84 node_stack.push({org => child});
87 # add the location groups that sort to the top
88 # above the child org units
89 FOR grp IN top_loc_groups;
90 node_stack.push({org => org_unit, loc_grp => grp});
95 # org is not publicly visible (though its children may be).
96 NEXT UNLESS ctx.is_staff OR visible;
98 # org is not within hiding scope (though its children may be).
99 NEXT UNLESS hiding_disabled OR ctx.org_within_hiding_scope(ou_id);
103 node_value = node_value _ ':' _ loc_grp.id;
104 css_class = 'class="loc_grp"';
106 css_class = 'class="org_unit"';
109 IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
110 disabled = 'disabled="disabled"';
111 ELSIF !lasso_selected AND node_value == value;
112 selected = 'selected="selected"';
115 IF can_have_users_only AND org_unit.ou_type.can_have_users != 't';
116 disabled = 'disabled="disabled"';
117 ELSIF !lasso_selected AND node_value == value;
118 selected = 'selected="selected"';
121 IF hold_pickup_lib AND ctx.get_org_setting(
122 org_unit.id, 'opac.holds.org_unit_not_pickup_lib');
123 disabled = 'disabled="disabled"';
126 # caller provided a list of valid org units.
127 # all orgs not in the list are marked invalid.
128 IF valid_org_list AND
129 !valid_org_list.grep('^' _ org_unit.id _ '$').size;
130 disabled = 'disabled="disabled"';
136 # copy loc groups appear as children of the owning org unit
137 SET pad_depth = pad_depth + 1 IF loc_grp;
139 # determine the depth by calculating the distance from the root
140 porg = ctx.get_aou(org_unit.parent_ou);
142 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
143 porg = ctx.get_aou(porg.parent_ou);
146 pad_depth = pad_depth * 2;
147 display_name = loc_grp ? loc_grp.name : org_unit.name %]
149 <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]>
150 [% ' ' FOR [0..pad_depth]; display_name | html %]
155 [%- IF show_lassos AND ctx.lassos.size > 0 -%]
161 BLOCK build_scope_selector;
169 ou_id = ctx.search_ou;
170 context_org = ctx.get_aou(ou_id);
172 # if the selected org unit is out of hiding scope,
173 # disable the ou-hide scoping altogether.
174 hiding_disabled = ctx.org_hiding_disabled(value);
175 hiding_depth = ctx.get_org_setting(ou_id, 'opac.org_unit_hiding.depth') -%]
177 <select [% IF id %] id='[% id %]' [% END -%]
178 title='[% arialabel || l("Select scoping restrictions") %]'
180 <option value=''>[% l('No Restrictions') | html %]</option>
182 <optgroup label="[% l('Search Scope') %]"> [%
183 FOR d IN ctx.sorted_aout_list(); # sorts by depth and opac_label
184 NEXT IF !hiding_disabled AND hiding_depth > 0 AND d.depth < hiding_depth;
185 NEXT IF d.depth > context_org.ou_type.depth; # only show ancestors-and-self
186 opt_value = 'depth(' _ d.depth _ ')';
188 IF value == opt_value; selected = 'selected="selected"'; END %]
189 <option value='[% opt_value %]' [% selected %]>
190 [% d.opac_label | html %]
195 [% IF show_lassos AND ctx.lassos.size > 0;
196 %] <optgroup label="[% l('Library Groups') %]"> [%
197 FOR lasso IN ctx.lassos;
198 opt_value = 'lasso(' _ lasso.id _ ')';
200 IF value == opt_value; selected = 'selected="selected"'; END %]
201 <option value='[% opt_value %]' [% selected %]>
202 [% lasso.name | html %]
208 IF show_loc_groups AND ctx.copy_location_groups.size > 0;
209 %] <optgroup label="[% l('Location Groups') %]"> [%
210 FOR lc_ou_id IN ctx.copy_location_groups.keys;
211 FOR grp IN ctx.copy_location_groups.$lc_ou_id;
212 opt_value = 'location_groups(' _ grp.id _ ')';
214 IF value == opt_value; selected = 'selected="selected"'; END %]
215 <option value='[% opt_value %]' [% selected %]>
216 [% grp.name | html %]