Merge branch 'master' of ssh://git.freeside.biz/home/git/freeside
[freeside.git] / httemplate / edit / tower.html
1 <& elements/edit.html,
2      name_singular => 'tower',
3      table         => 'tower',
4      viewall_dir   => 'browse',
5      html_init     => include('/elements/mapselect.html'),
6      fields        => [ 'towername',
7                         { field=>'disabled', type=>'checkbox', value=>'Y', },
8                         { field=>'color',    type=>'pickcolor' },
9                         { field               => 'default_ip_addr',
10                           curr_value_callback => $default_ip_addr_callback },
11                         'latitude',
12                         'longitude',
13                         'altitude',
14                         'height',
15                         'veg_height',
16 #                        { field             => 'sectornum',
17 #                          type              => 'tower_sector',
18 #                          o2m_table         => 'tower_sector',
19 #                          m2_label          => 'Sector',
20 #                          m2_error_callback => $m2_error_callback,
21 #                        },
22                         { type              => 'tower_sectors',
23                           field             => 'sectornum',
24                           # does its own o2m-thing
25                         },
26                       ],
27      labels        => { 'towernum'        => 'Tower',
28                         'towername'       => 'Name',
29                         'sectornum'       => 'Sector',
30                         'disabled'        => 'Disabled',
31                         'default_ip_addr' => 'Tower IP address',
32                         'latitude'        => 'Latitude',
33                         'longitude'       => 'Longitude',
34                         'altitude'        => 'Altitude (feet)',
35                         'height'          => 'Tower height (feet)',
36                         'veg_height'      => 'Vegetation height (feet)',
37                         'color'           => 'Color',
38                       },
39 &>
40 <%init>
41
42 my $m2_error_callback = sub { # reconstruct the list
43   my ($cgi, $object) = @_;
44
45   my @fields = qw(
46     sectorname ip_addr height freq_mhz direction width tilt v_width db_high db_low sector_range
47   );
48
49   map {
50     my $k = $_;
51     new FS::tower_sector {
52       'towernum'  => $object->towernum,
53       'sectornum' => scalar( $cgi->param($k) ),
54       map { $_ => scalar( $cgi->param($k.'_'.$_) ) } @fields,
55     };
56   } grep length($cgi->param($_.'_sectorname')),
57       grep /^sectornum\d+$/,
58         ($cgi->param);
59 };
60
61 my $default_ip_addr_callback = sub {
62   my ($cgi, $object) = @_;
63   my $sector = $object ? $object->default_sector : '';
64   $sector ? $sector->ip_addr : '';
65 };
66
67 </%init>