1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
% if ( ! $opt{'multiple'} ) {
<& /elements/select-table.html,
table => 'tower_sector',
name_col => 'description',
order_by => 'ORDER BY towernum,sectorname',
empty_label => ' ',
@_
&>
% }
% else { # currently only multiple sectors, not towers
<& /elements/select-table.html,
table => 'tower',
name_col => 'towername',
id => 'towernum',
field => 'dummy_towernum',
onchange => 'change_towernum(this.value);',
element_etc => 'STYLE="vertical-align:top"',
&>
<SELECT NAME="sectornum" ID="sectornum" MULTIPLE SIZE="6"></SELECT>
<SCRIPT TYPE="text/javascript">
var sectors_of = <% encode_json(\%sectors_of) %>;
var select_sectornum = document.getElementById('sectornum');
function change_towernum(towernum) {
select_sectornum.options.length = 0;
for (var sectornum in sectors_of[towernum]) {
var o = document.createElement('OPTION');
o.value = sectornum;
o.text = sectors_of[towernum][sectornum];
o.selected = true;
select_sectornum.add(o, null);
}
return;
}
change_towernum('');
</SCRIPT>
<BR>
<INPUT TYPE="checkbox" VALUE="none" NAME="sectornum" CHECKED> <% $empty_label %>
% }
<%init>
my %opt = @_;
my %sectors_of;
my %default_of;
if ( $opt{'multiple'} ) {
foreach my $sector ( qsearch('tower_sector',{}) ) {
$sectors_of{$sector->towernum} ||= {};
$sectors_of{$sector->towernum}->{$sector->sectornum} = $sector->sectorname;
$sectors_of{''}->{$sector->sectornum} = $sector->description;
$default_of{$sector->towernum} = $sector->sectornum
if $sector->sectorname eq '_default';
}
}
foreach my $towernum (keys %sectors_of) {
# hide default sectors for towers that have real sectors defined
my $sectornum = $default_of{$towernum};
if ( keys %{ $sectors_of{$towernum} } > 1 ) {
delete $sectors_of{$towernum}->{$sectornum};
delete $sectors_of{''}->{$sectornum};
}
else {
# show default sectorname as '(all)'
$sectors_of{$towernum}->{$sectornum} = '(all)'
}
}
my $empty_label = $opt{'empty_label'} || 'Include services with no tower/sector';
</%init>
|