summaryrefslogtreecommitdiff
path: root/httemplate/elements/select-tower_sector.html
blob: 1973ef9c6bb01b6f2a6e0a43874658d8f6d032c9 (plain)
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
% 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> No sector
<%init>
my %opt = @_;

my %sectors_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;
  }
}
</%init>