]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
LP1615805 No inputs after submit in patron search (AngularJS)
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / org_selector.tt2
1 [%
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
6 #
7 # NOTE: DO NOT USE PROCESS
8 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
9
10 PROCESS "opac/parts/misc_util.tt2";
11 PROCESS get_library;
12
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';
16
17     IF !name; 
18         name = loc_name;
19     END;
20     IF !value;
21         value = loc_value;
22     END;
23
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);
27
28     # Some setup for Library Groups
29     lasso_selected = 0;
30     base_value = value.split(':').0;
31
32     -%]
33
34     <select [% IF id %] id='[% id %]' [% END -%]
35             title='[% arialabel || l("Select Library") %]' 
36             name='[% name %]'>
37
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 _ ')';
42                 selected = '';
43                 IF !lasso_selected AND ctx.search_lasso == lasso.id;
44                     lasso_selected = 1;
45                     selected = 'selected="selected"';
46                 END %]
47                 <option value='[% opt_value %]' [% selected %]> 
48                     [% lasso.name | html %]
49                 </option>
50             [% END %]
51             </optgroup>
52             <optgroup label="[% l('Libraries') %]">
53         [% END;
54
55         WHILE node_stack.size > 0; 
56             node = node_stack.pop();
57             org_unit = node.org;
58             loc_grp = node.loc_grp;
59             ou_id = org_unit.id;
60             css_class = '';
61             disabled = '';
62             selected = '';
63             visible = org_unit.opac_visible == 't';
64
65             # org and all children are invisible.
66             NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
67
68             IF !loc_grp; # processing an org unit
69
70                 top_loc_groups = [];
71                 IF show_loc_groups;
72                     # add the location groups that sort below the child org units
73                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
74                         IF grp.top == 't';
75                             top_loc_groups.push(grp);
76                         ELSE;
77                             node_stack.push({org => org_unit, loc_grp => grp});
78                         END;
79                     END;
80                 END;
81
82                 # add the child org units
83                 FOR child IN org_unit.children.reverse;
84                     node_stack.push({org => child});
85                 END;
86
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});
91                 END;
92
93             END;
94
95             # org is not publicly visible (though its children may be).
96             NEXT UNLESS ctx.is_staff OR visible;
97             
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);
100
101             node_value = ou_id;
102             IF loc_grp;
103                 node_value = node_value _ ':' _ loc_grp.id; 
104                 css_class = 'class="loc_grp"';
105             ELSE;
106                 css_class = 'class="org_unit"';
107             END;
108
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"';
113             END; 
114
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"';
119             END; 
120
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"';
124             END;
125
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"';
131                 selected = '';
132             END;
133
134             pad_depth = 0;
135
136             # copy loc groups appear as children of the owning org unit
137             SET pad_depth = pad_depth + 1 IF loc_grp;
138
139             # determine the depth by calculating the distance from the root
140             porg = ctx.get_aou(org_unit.parent_ou);
141             WHILE porg;
142                 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
143                 porg = ctx.get_aou(porg.parent_ou);
144             END;
145
146             pad_depth = pad_depth * 2;
147             display_name = loc_grp ? loc_grp.name : org_unit.name %]
148
149             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
150                 [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]
151             </option> 
152
153         [%- END -%]
154
155         [%- IF show_lassos AND ctx.lassos.size > 0 -%]
156             </optgroup>
157         [%- END %]
158     </select>
159 [%- END;
160
161 BLOCK build_scope_selector;
162     IF !name; 
163         name = id;
164     END;
165     IF !value;
166         value = loc_value;
167     END;
168
169     ou_id = ctx.search_ou;
170     context_org = ctx.get_aou(ou_id);
171
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') -%]
176
177     <select [% IF id %] id='[% id %]' [% END -%]
178             title='[% arialabel || l("Select scoping restrictions") %]' 
179             name='[% name %]'>
180             <option value=''>[% l('No Restrictions') | html %]</option>
181
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 _ ')';
187             selected = '';
188             IF value == opt_value; selected = 'selected="selected"'; END %]
189             <option value='[% opt_value %]' [% selected %]> 
190                 [% d.opac_label | html %]
191             </option>
192         [% END %]
193         </optgroup>
194
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 _ ')';
199                 selected = '';
200                 IF value == opt_value; selected = 'selected="selected"'; END %]
201                 <option value='[% opt_value %]' [% selected %]> 
202                     [% lasso.name | html %]
203                 </option>
204             [% END %]
205             </optgroup>
206         [% END;
207
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 _ ')';
213                     selected = '';
214                     IF value == opt_value; selected = 'selected="selected"'; END %]
215                     <option value='[% opt_value %]' [% selected %]> 
216                         [% grp.name | html %]
217                     </option>
218                 [% END %]
219             [% END %]
220             </optgroup>
221         [% END %]
222
223     </select>
224 [%- END %]