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