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