]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
Add styles to org selector for loc groups
[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             css_class = '';
28             disabled = '';
29             selected = '';
30
31             NEXT UNLESS ctx.is_staff || org_unit.opac_visible == 't';
32
33             IF !loc_grp; # processing an org unit
34
35                 top_loc_groups = [];
36                 IF show_loc_groups;
37                     # add the location groups that sort below the child org units
38                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
39                         IF grp.top == 't';
40                             top_loc_groups.push(grp);
41                         ELSE;
42                             node_stack.push({org => org_unit, loc_grp => grp});
43                         END;
44                     END;
45                 END;
46
47                 # add the child org units
48                 FOR child IN org_unit.children.reverse;
49                     node_stack.push({org => child});
50                 END;
51
52                 # add the location groups that sort to the top
53                 # above the child org units
54                 FOR grp IN top_loc_groups;
55                     node_stack.push({org => org_unit, loc_grp => grp});
56                 END;
57             END;
58
59             node_value = ou_id;
60             IF loc_grp; node_value = node_value _ ':' _ loc_grp.id; END;
61             IF loc_grp;
62                 css_class = 'class="loc_grp"';
63             ELSE;
64                 css_class = 'class="org_unit"';
65             END;
66
67             IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
68                 disabled = 'disabled="disabled"';
69             ELSIF node_value == value;
70                 selected = 'selected="selected"';
71             END %] 
72
73             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
74             [%
75                 # loc_grp's are displayed as children of the current org
76                 depth = org_unit.ou_type.depth;
77                 IF loc_grp; depth = depth + 1; END;
78                 pad = depth * 2;
79                 FOR idx IN [0..pad]; '&nbsp;'; END;
80                 loc_grp ? loc_grp.name : org_unit.name | html ;
81             %]
82             </option> 
83             [%
84         END;
85     %]
86     </select>
87 [% END %]