]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/reporter/templates/widgets/lib-choose.multiselect
big ol reporter cleanup for the meeting
[Evergreen.git] / Open-ILS / src / reporter / templates / widgets / lib-choose.multiselect
1 [%
2
3 PROCESS inputs;
4
5 BLOCK editor;
6 root = 'SELECT * FROM ' _ table.findvalue('tablename') _ ' WHERE parent_ou IS NULL ORDER BY name;';
7 q = 'SELECT * FROM ' _ table.findvalue('tablename') _ ' WHERE parent_ou = ? ORDER BY name;';
8
9 org_unit_type = DBI.tie('actor.org_unit_type', 'id')
10
11 %]
12
13 <script language="javascript">
14         filters["[% input_prefix %]"] = "[% table_label _ ' -- ' _ field.findvalue('label') %]";
15
16         var multihier_[% table_alias %] = [];
17
18         function change_multihier_[% table_alias %] ( sel ) {
19                 for (var i = 0; i < sel.options.length; i++) {
20                         if (sel.options[i].selected) {
21                                 sel.options[i].selected = false;
22                                 for (var j in multihier_[% table_alias %]) {
23                                         if (multihier_[% table_alias %][j] == sel.options[i].id) {
24                                                 sel.options[i].selected = true
25                                                 continue;
26                                         }
27                                 }
28                         }
29                 }
30         }
31 </script>
32
33 [%
34
35 WRAPPER select name=input_prefix multi="multi" onchange='change_multihier_' _ table_alias _ '(this);';
36         depth = 0;
37         FOR f = DBI.query(root);
38                 sel = 0;
39                 FOR v = current_value;
40                         sel = 1 IF v == f.id;
41                         LAST;
42                 END;
43                 INCLUDE option value=f.id content=f.name selected=sel;
44                 INCLUDE next_level parent_ou = f.id;
45         END;
46 END;
47 END;
48
49 BLOCK next_level;
50         depth = depth + 1;
51         x = depth;
52         s = DBI.prepare(q);
53         FOR f = s.execute(parent_ou);
54                 ou_t = f.ou_type;
55
56                 logme(["can_have_vols for ou_t", ,org_unit_type.$ou_t.can_have_vols]);
57
58                 IF org_unit_type.$ou_t.can_have_vols == 1;
59                         %]
60                         <script language="javascript">
61                                 multihier_[% table_alias %].push("mh_[% f.id %]");
62                         </script>
63                         [%
64                 END;
65
66                 x = depth;
67                 val = '';
68                 WHILE x > 0;
69                         val = val _ '&nbsp;&nbsp;';
70                         x = x - 1;
71                 END;
72
73                 selected = '';
74                 FOR v = current_value;
75                         IF v == f.id;
76                                 selected = 'selected';
77                                 LAST;
78                         END;
79                 END;
80                 INCLUDE option value=f.id content=val _ f.name id='mh_' _ f.id;
81                 INCLUDE next_level parent_ou = f.id;
82         END;
83 END;
84
85 BLOCK display;
86         org_units = DBI.tie('actor.org_unit', 'id');
87         list = [];
88         FOR o = current_value;
89                 list.push(org_units.$o.name);
90         END;
91         list.join('<br/>');
92 END;
93 %]