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