& elements/edit.html,
name_singular => 'tower',
table => 'tower',
viewall_dir => 'browse',
fields => [ 'towername',
{ field=>'disabled', type=>'checkbox', value=>'Y', },
{ field => 'default_ip_addr',
curr_value_callback => $default_ip_addr_callback },
{ field => 'sectornum',
type => 'tower_sector',
o2m_table => 'tower_sector',
m2_label => 'Sector',
m2_error_callback => $m2_error_callback,
},
'latitude',
'longitude',
],
labels => { 'towernum' => 'Tower',
'towername' => 'Name',
'sectornum' => 'Sector',
'disabled' => 'Disabled',
'default_ip_addr' => 'Tower IP address',
'latitude' => 'Latitude',
'longitude' => 'Longitude',
},
&>
<%init>
my $m2_error_callback = sub { # reconstruct the list
my ($cgi, $object) = @_;
my @fields = qw(sectorname ip_addr);
map {
my $k = $_;
next if !length($cgi->param($k.'_sectorname'));
new FS::tower_sector {
'towernum' => $object->towernum,
'sectornum' => scalar( $cgi->param($k) ),
map { $_ => scalar( $cgi->param($k.'_'.$_) ) } @fields,
};
} grep /^sectornum\d+$/, ($cgi->param);
};
my $default_ip_addr_callback = sub {
my ($cgi, $object) = @_;
my $sector = $object ? $object->default_sector : '';
$sector ? $sector->ip_addr : '';
};
%init>