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]
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);
30 <select [% IF id %] id='[% id %]' [% END -%]
31 title='[% arialabel || l("Select Library") %]'
32 name='[% name %]' class="form-control w-100">
34 WHILE node_stack.size > 0;
35 node = node_stack.pop();
37 loc_grp = node.loc_grp;
42 visible = org_unit.opac_visible == 't';
44 # org and all children are invisible.
45 NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
47 IF !loc_grp; # processing an org unit
51 # add the location groups that sort below the child org units
52 FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
54 top_loc_groups.push(grp);
56 node_stack.push({org => org_unit, loc_grp => grp});
61 # add the child org units
62 FOR child IN org_unit.children.reverse;
63 node_stack.push({org => child});
66 # add the location groups that sort to the top
67 # above the child org units
68 FOR grp IN top_loc_groups;
69 node_stack.push({org => org_unit, loc_grp => grp});
74 # org is not publicly visible (though its children may be).
75 NEXT UNLESS ctx.is_staff OR visible;
77 # org is not within hiding scope (though its children may be).
78 NEXT UNLESS hiding_disabled OR ctx.org_within_hiding_scope(ou_id);
82 node_value = node_value _ ':' _ loc_grp.id;
83 css_class = 'class="loc_grp"';
85 css_class = 'class="org_unit"';
88 IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
89 disabled = 'disabled="disabled"';
90 ELSIF node_value == value;
91 selected = 'selected="selected"';
94 IF can_have_users_only AND org_unit.ou_type.can_have_users != 't';
95 disabled = 'disabled="disabled"';
96 ELSIF node_value == value;
97 selected = 'selected="selected"';
100 IF hold_pickup_lib AND ctx.get_org_setting(
101 org_unit.id, 'opac.holds.org_unit_not_pickup_lib');
102 disabled = 'disabled="disabled"';
105 # caller provided a list of valid org units.
106 # all orgs not in the list are marked invalid.
107 IF valid_org_list AND
108 !valid_org_list.grep('^' _ org_unit.id _ '$').size;
109 disabled = 'disabled="disabled"';
115 # copy loc groups appear as children of the owning org unit
116 SET pad_depth = pad_depth + 1 IF loc_grp;
118 # determine the depth by calculating the distance from the root
119 porg = ctx.get_aou(org_unit.parent_ou);
121 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
122 porg = ctx.get_aou(porg.parent_ou);
125 pad_depth = pad_depth * 2;
126 display_name = loc_grp ? loc_grp.name : org_unit.name %]
128 <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]>
129 [% ' ' FOR [0..pad_depth]; display_name | html %]
136 [% # PINES Customization for Carousels
137 # Build org selector that refreshes page with carousel_loc set to control which carousels display
139 BLOCK build_org_selector_carousel;
140 node_stack = [{org => org_unit || ctx.aouct_tree || ctx.aou_tree}];
141 inherited_vis = ctx.get_cgf('opac.org_unit.non_inherited_visibility').enabled == 'f';
150 # if the selected org unit is out of hiding scope,
151 # disable the ou-hide scoping altogether.
152 hiding_disabled = ctx.org_hiding_disabled(value);
156 <select id='carousel_selector'
157 title='[% arialabel || l("Select Library") %]'
158 class="org_selector_dropdown"
159 onchange="location = '/eg/opac/home?carousel_loc=' +
160 this.options[this.selectedIndex].value">
161 <option value="" class="org_unit" disabled selected="selected">[% l("Choose a library to see newly purchased items") %]</option>
163 WHILE node_stack.size > 0;
164 node = node_stack.pop();
166 loc_grp = node.loc_grp;
171 visible = org_unit.opac_visible == 't';
173 # org and all children are invisible.
174 NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
176 IF !loc_grp; # processing an org unit
180 # add the location groups that sort below the child org units
181 FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
183 top_loc_groups.push(grp);
185 node_stack.push({org => org_unit, loc_grp => grp});
190 # add the child org units
191 FOR child IN org_unit.children.reverse;
192 node_stack.push({org => child});
195 # add the location groups that sort to the top
196 # above the child org units
197 FOR grp IN top_loc_groups;
198 node_stack.push({org => org_unit, loc_grp => grp});
203 # org is not publicly visible (though its children may be).
204 NEXT UNLESS ctx.is_staff OR visible;
206 # org is not within hiding scope (though its children may be).
207 NEXT UNLESS hiding_disabled OR ctx.org_within_hiding_scope(ou_id);
211 node_value = node_value _ ':' _ loc_grp.id;
212 css_class = 'class="loc_grp"';
214 css_class = 'class="org_unit"';
217 IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
218 disabled = 'disabled="disabled"';
219 ELSIF node_value == value;
220 selected = 'selected="selected"';
223 IF can_have_users_only AND org_unit.ou_type.can_have_users != 't';
224 disabled = 'disabled="disabled"';
225 ELSIF node_value == value;
226 selected = 'selected="selected"';
229 IF hold_pickup_lib AND ctx.get_org_setting(
230 org_unit.id, 'opac.holds.org_unit_not_pickup_lib');
231 disabled = 'disabled="disabled"';
234 # caller provided a list of valid org units.
235 # all orgs not in the list are marked invalid.
236 IF valid_org_list AND
237 !valid_org_list.grep('^' _ org_unit.id _ '$').size;
238 disabled = 'disabled="disabled"';
244 # copy loc groups appear as children of the owning org unit
245 SET pad_depth = pad_depth + 1 IF loc_grp;
247 # determine the depth by calculating the distance from the root
248 porg = ctx.get_aou(org_unit.parent_ou);
250 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
251 porg = ctx.get_aou(porg.parent_ou);
254 pad_depth = pad_depth * 5;
255 display_name = loc_grp ? loc_grp.name : org_unit.name %]
256 [% IF node_value == 1 %]
257 [% display_name = "All PINES Libraries" %]
260 <option value='[% org_unit.id %]' [% selected %] [% disabled %] [% css_class %]>
261 [% ' ' FOR [0..pad_depth]; display_name | html %]