]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
Vandelay-based record matching and import for Acquisitions
[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 #
6 # NOTE: DO NOT USE PROCESS
7 # Use of PROCESS results in internal variables, such as value or org_unit, to "leak" out
8
9 BLOCK build_org_selector;
10     node_stack = [{org => org_unit || ctx.aou_tree}];
11     IF !name; 
12         name = 'loc';
13         IF show_loc_groups; name = 'locg'; END;
14     END;
15     IF !value;
16         value = ctx.search_ou;
17         IF show_loc_groups; 
18             value = CGI.param('locg') || ctx.search_ou;
19         END;
20     END;
21     %]
22
23     <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
24     [% 
25         WHILE node_stack.size > 0; 
26             node = node_stack.pop();
27             org_unit = node.org;
28             loc_grp = node.loc_grp;
29             ou_id = org_unit.id;
30             css_class = '';
31             disabled = '';
32             selected = '';
33
34             NEXT UNLESS ctx.is_staff || org_unit.opac_visible == 't';
35
36             IF !loc_grp; # processing an org unit
37
38                 top_loc_groups = [];
39                 IF show_loc_groups;
40                     # add the location groups that sort below the child org units
41                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
42                         IF grp.top == 't';
43                             top_loc_groups.push(grp);
44                         ELSE;
45                             node_stack.push({org => org_unit, loc_grp => grp});
46                         END;
47                     END;
48                 END;
49
50                 # add the child org units
51                 FOR child IN org_unit.children.reverse;
52                     node_stack.push({org => child});
53                 END;
54
55                 # add the location groups that sort to the top
56                 # above the child org units
57                 FOR grp IN top_loc_groups;
58                     node_stack.push({org => org_unit, loc_grp => grp});
59                 END;
60             END;
61
62             node_value = ou_id;
63             IF loc_grp; node_value = node_value _ ':' _ loc_grp.id; END;
64             IF loc_grp;
65                 css_class = 'class="loc_grp"';
66             ELSE;
67                 css_class = 'class="org_unit"';
68             END;
69
70             IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
71                 disabled = 'disabled="disabled"';
72             ELSIF node_value == value;
73                 selected = 'selected="selected"';
74             END %] 
75
76             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
77             [%
78                 # loc_grp's are displayed as children of the current org
79                 depth = org_unit.ou_type.depth;
80                 IF loc_grp; depth = depth + 1; END;
81                 pad = depth * 2;
82                 FOR idx IN [0..pad]; '&nbsp;'; END;
83                 loc_grp ? loc_grp.name : org_unit.name | html ;
84             %]
85             </option> 
86             [%
87         END;
88     %]
89     </select>
90 [% END %]