]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/org_selector.tt2
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[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.aouct_tree || ctx.aou_tree}];
11     inherited_vis = ctx.get_cgf('opac.org_unit.non_inherited_visibility').enabled == 'f';
12
13     IF !name; 
14         name = 'loc';
15         IF show_loc_groups; name = 'locg'; END;
16     END;
17     IF !value;
18         value = ctx.search_ou;
19         IF show_loc_groups; 
20             value = CGI.param('locg') || ctx.search_ou;
21         END;
22     END;
23     %]
24
25     <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
26     [% 
27         WHILE node_stack.size > 0; 
28             node = node_stack.pop();
29             org_unit = node.org;
30             loc_grp = node.loc_grp;
31             ou_id = org_unit.id;
32             css_class = '';
33             disabled = '';
34             selected = '';
35             visible = org_unit.opac_visible == 't';
36
37             # org and all children are invisible.
38             NEXT IF !visible AND inherited_vis AND !ctx.is_staff;
39
40             IF !loc_grp; # processing an org unit
41
42                 top_loc_groups = [];
43                 IF show_loc_groups;
44                     # add the location groups that sort below the child org units
45                     FOR grp IN ctx.copy_location_groups.$ou_id.reverse;
46                         IF grp.top == 't';
47                             top_loc_groups.push(grp);
48                         ELSE;
49                             node_stack.push({org => org_unit, loc_grp => grp});
50                         END;
51                     END;
52                 END;
53
54                 # add the child org units
55                 FOR child IN org_unit.children.reverse;
56                     node_stack.push({org => child});
57                 END;
58
59                 # add the location groups that sort to the top
60                 # above the child org units
61                 FOR grp IN top_loc_groups;
62                     node_stack.push({org => org_unit, loc_grp => grp});
63                 END;
64
65             END;
66
67             # This org unit is not publicly visible (though its children may be).
68             NEXT UNLESS ctx.is_staff OR visible;
69
70             node_value = ou_id;
71             IF loc_grp;
72                 node_value = node_value _ ':' _ loc_grp.id; 
73                 css_class = 'class="loc_grp"';
74             ELSE;
75                 css_class = 'class="org_unit"';
76             END;
77
78             IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
79                 disabled = 'disabled="disabled"';
80             ELSIF node_value == value;
81                 selected = 'selected="selected"';
82             END; 
83
84             pad_depth = 0;
85
86             # copy loc groups appear as children of the owning org unit
87             SET pad_depth = pad_depth + 1 IF loc_grp;
88
89             # determine the depth by calculating the distance from the root
90             porg = ctx.get_aou(org_unit.parent_ou);
91             WHILE porg;
92                 SET pad_depth = pad_depth + 1 IF porg.opac_visible == 't' OR ctx.is_staff;
93                 porg = ctx.get_aou(porg.parent_ou);
94             END;
95
96             pad_depth = pad_depth * 2;
97             display_name = loc_grp ? loc_grp.name : org_unit.name %]
98
99             <option value='[% node_value %]' [% selected %] [% disabled %] [% css_class %]> 
100                 [% '&nbsp;' FOR [0..pad_depth]; display_name | html %]
101             </option> 
102
103         [% END %]
104     </select>
105 [% END %]