]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
LP#1815815: Library Groups
[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]
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     -%]
29
30     <select [% IF id %] id='[% id %]' [% END -%]
31             title='[% arialabel || l("Select Library") %]' 
32             name='[% name %]'>
33     [%- 
34         WHILE node_stack.size > 0; 
35             node = node_stack.pop();
36             org_unit = node.org;
37             loc_grp = node.loc_grp;
38             ou_id = org_unit.id;
39             css_class = '';
40             disabled = '';
41             selected = '';
42             visible = org_unit.opac_visible == 't';
43
44             # org and all children are invisible.
45             NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
46
47             IF !loc_grp; # processing an org unit
48
49                 top_loc_groups = [];
50                 IF show_loc_groups;
51                     # add the location groups that sort below the child org units
52                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
53                         IF grp.top == 't';
54                             top_loc_groups.push(grp);
55                         ELSE;
56                             node_stack.push({org => org_unit, loc_grp => grp});
57                         END;
58                     END;
59                 END;
60
61                 # add the child org units
62                 FOR child IN org_unit.children.reverse;
63                     node_stack.push({org => child});
64                 END;
65
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});
70                 END;
71
72             END;
73
74             # org is not publicly visible (though its children may be).
75             NEXT UNLESS ctx.is_staff OR visible;
76             
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);
79
80             node_value = ou_id;
81             IF loc_grp;
82                 node_value = node_value _ ':' _ loc_grp.id; 
83                 css_class = 'class="loc_grp"';
84             ELSE;
85                 css_class = 'class="org_unit"';
86             END;
87
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"';
92             END; 
93
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"';
98             END; 
99
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"';
103             END;
104
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"';
110                 selected = '';
111             END;
112
113             pad_depth = 0;
114
115             # copy loc groups appear as children of the owning org unit
116             SET pad_depth = pad_depth + 1 IF loc_grp;
117
118             # determine the depth by calculating the distance from the root
119             porg = ctx.get_aou(org_unit.parent_ou);
120             WHILE porg;
121                 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
122                 porg = ctx.get_aou(porg.parent_ou);
123             END;
124
125             pad_depth = pad_depth * 2;
126             display_name = loc_grp ? loc_grp.name : org_unit.name %]
127
128             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
129                 [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]
130             </option> 
131
132         [%- END %]
133     </select>
134 [%- END;
135
136 BLOCK build_scope_selector;
137     IF !name; 
138         name = id;
139     END;
140     IF !value;
141         value = loc_value;
142     END;
143
144     ou_id = ctx.search_ou;
145     context_org = ctx.get_aou(ou_id);
146
147     # if the selected org unit is out of hiding scope, 
148     # disable the ou-hide scoping altogether.
149     hiding_disabled = ctx.org_hiding_disabled(value);
150     hiding_depth = ctx.get_org_setting(ou_id, 'opac.org_unit_hiding.depth') -%]
151
152     <select [% IF id %] id='[% id %]' [% END -%]
153             title='[% arialabel || l("Select Library") %]' 
154             name='[% name %]'>
155             <option value=''>[% l('No Restrictions') | html %]</option>
156
157         <optgroup label="[% l('Search Scope') %]"> [%
158         FOR d IN ctx.sorted_aout_list(); # sorts by depth and opac_label
159             NEXT IF !hiding_disabled AND hiding_depth > 0 AND d.depth < hiding_depth;
160             NEXT IF d.depth > context_org.ou_type.depth; # only show ancestors-and-self
161             opt_value = 'depth(' _ d.depth _ ')';
162             selected = '';
163             IF value == opt_value; selected = 'selected="selected"'; END %]
164             <option value='[% opt_value %]' [% selected %]> 
165                 [% d.opac_label | html %]
166             </option>
167         [% END %]
168         </optgroup>
169
170         [% IF ctx.lassos.size > 0;
171             %] <optgroup label="[% l('Library Groups') %]"> [%
172             FOR lasso IN ctx.lassos;
173                 opt_value = 'lasso(' _ lasso.id _ ')';
174                 selected = '';
175                 IF value == opt_value; selected = 'selected="selected"'; END %]
176                 <option value='[% opt_value %]' [% selected %]> 
177                     [% lasso.name | html %]
178                 </option>
179             [% END %]
180             </optgroup>
181         [% END;
182
183         IF show_loc_groups AND ctx.copy_location_groups.size > 0;
184             %] <optgroup label="[% l('Location Groups') %]"> [%
185             FOR lc_ou_id IN ctx.copy_location_groups.keys;
186                 FOR grp IN ctx.copy_location_groups.$lc_ou_id;
187                     opt_value = 'location_groups(' _ grp.id _ ')';
188                     selected = '';
189                     IF value == opt_value; selected = 'selected="selected"'; END %]
190                     <option value='[% opt_value %]' [% selected %]> 
191                         [% grp.name | html %]
192                     </option>
193                 [% END %]
194             [% END %]
195             </optgroup>
196         [% END %]
197
198     </select>
199 [%- END %]