]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
Copy Location Search Groups : TPac org unit selector
[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;
33                 IF show_loc_groups;
34                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
35                         node_stack.push({org => org_unit, loc_grp => grp});
36                     END;
37                 END;
38                 FOR child IN org_unit.children.reverse;
39                     node_stack.push({org => child});
40                 END;
41             END;
42
43             node_value = ou_id;
44             IF loc_grp; node_value = node_value _ ':' _ loc_grp.id; END;
45
46             IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
47                 disabled = 'disabled="disabled"';
48             ELSIF node_value == value;
49                 selected = 'selected="selected"';
50             END %] 
51
52             <option value='[% node_value %]' [% selected %] [% disabled %]> 
53             [%
54                 # loc_grp's are displayed as children of the current org
55                 depth = org_unit.ou_type.depth;
56                 IF loc_grp; depth = depth + 1; END;
57                 pad = depth * 2;
58                 FOR idx IN [0..pad]; '&nbsp;'; END;
59                 loc_grp ? loc_grp.name : org_unit.name | html ;
60             %]
61             </option> 
62             [%
63         END;
64     %]
65     </select>
66 [% END %]