From e5fcc68aab310814b0ba5444bc97ef504e6e16da Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sun, 11 Mar 2012 20:57:40 -0700 Subject: cleanup for svc_broadband manual router feature, #14698 --- httemplate/browse/router.cgi | 2 +- httemplate/edit/process/svc_broadband.cgi | 3 ++ httemplate/edit/router.cgi | 4 +- httemplate/edit/svc_broadband.cgi | 59 ++-------------------- httemplate/elements/tr-select-router_block_ip.html | 47 ++++++++++++----- httemplate/view/svc_broadband.cgi | 1 - 6 files changed, 44 insertions(+), 72 deletions(-) (limited to 'httemplate') diff --git a/httemplate/browse/router.cgi b/httemplate/browse/router.cgi index 21047d7fc..ef8ad3160 100644 --- a/httemplate/browse/router.cgi +++ b/httemplate/browse/router.cgi @@ -17,7 +17,7 @@ shift->addr_block ); }, - sub { shift->auto_addr ? 'Automatic' : 'Manual' }, + sub { shift->manual_addr ? 'Manual' : 'Automatic' }, sub { 'Delete' }, ], 'links' => [ [ "${p2}edit/router.cgi?", 'routernum' ], diff --git a/httemplate/edit/process/svc_broadband.cgi b/httemplate/edit/process/svc_broadband.cgi index 4184f5fa6..31def255c 100644 --- a/httemplate/edit/process/svc_broadband.cgi +++ b/httemplate/edit/process/svc_broadband.cgi @@ -13,6 +13,9 @@ die "access denied" sub precheck { my $cgi = shift; + if ( !defined($cgi->param('ip_addr')) ) { + $cgi->param('ip_addr', $cgi->param('prev_ip_addr') || ''); + } $cgi->param("usergroup", [ $cgi->param('usergroup') ]); '' } diff --git a/httemplate/edit/router.cgi b/httemplate/edit/router.cgi index 6672d5d75..fdcd7b3b3 100755 --- a/httemplate/edit/router.cgi +++ b/httemplate/edit/router.cgi @@ -7,13 +7,13 @@ 'routername' => 'Name', 'svc_part' => 'Service', 'agentnum' => 'Agent', - 'auto_addr' => 'Assign IP addresses automatically', + 'manual_addr' => 'Assign IP addresses manually', }, 'fields' => [ { 'field'=>'routername', 'type'=>'text', 'size'=>32 }, { 'field'=>'agentnum', 'type'=>'select-agent' }, { 'field'=>'svcnum', 'type'=>'hidden' }, - { 'field'=>'auto_addr','type'=>'checkbox','value'=>'Y'}, + { 'field'=>'manual_addr','type'=>'checkbox','value'=>'Y'}, ], 'error_callback' => $callback, 'edit_callback' => $callback, diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi index 8fccb1fa8..b07c725ae 100644 --- a/httemplate/edit/svc_broadband.cgi +++ b/httemplate/edit/svc_broadband.cgi @@ -102,9 +102,9 @@ END my @fields = ( qw( description speed_down speed_up ), { field=>'sectornum', type=>'select-tower_sector', }, - { field=>'routernum', type=>'select-router_block_ip', }, - qw( mac_addr latitude longitude altitude vlan_profile - performance_profile authkey plan_id ), + { field=>'routernum', type=>'select-router_block_ip' }, + qw( mac_addr latitude longitude altitude vlan_profile + performance_profile authkey plan_id ) ); if ( $conf->exists('svc_broadband-radius') ) { @@ -115,8 +115,6 @@ if ( $conf->exists('svc_broadband-radius') ) { } } -my $fixedblock = ''; - my $part_svc; my $svc_edit_callback = sub { @@ -124,8 +122,6 @@ my $svc_edit_callback = sub { $part_svc = $part_svc_x; #for field_callback to use - $opt->{'labels'}{'block_label'} = 'Block'; - my ($nas_export) = $part_svc->part_export('broadband_nas'); #can we assume there's only one of these per part_svc? if ( $nas_export ) { @@ -173,60 +169,13 @@ my $field_callback = sub { ? 'fixed' : 'hidden'; $fieldref->{'value'} = $columndef->columnvalue; - $fixedblock = $fieldref->{value} - if $fieldref->{field} eq 'blocknum'; - + if ( $fieldref->{field} eq 'usergroup' ) { $fieldref->{'formatted_value'} = [ $object->radius_groups('long_description') ]; } } - if ($object->svcnum) { - - $fieldref->{type} = 'hidden' - if $fieldref->{field} eq 'blocknum'; - - $fieldref->{value} = $object->addr_block->label - if $fieldref->{field} eq 'block_label' && $object->addr_block; - - } else { - - if ($fieldref->{field} eq 'block_label') { - if ($fixedblock && $object->addr_block) { - $object->blocknum($fixedblock); - $fieldref->{value} = $object->addr_block->label; - }else{ - $fieldref->{type} = 'hidden'; - } - } - - if ($fieldref->{field} eq 'blocknum') { - if ( $fixedblock or $conf->exists('auto_router') ) { - $fieldref->{type} = 'hidden'; - $fieldref->{value} = $fixedblock; - return; - } - - my $cust_pkg = qsearchs( 'cust_pkg', {pkgnum => $cgi->param('pkgnum')} ); - die "No cust_pkg entry!" unless $cust_pkg; - - $object->svcpart($part_svc->svcpart); - my @addr_block = - grep { ! $_->agentnum - || $cust_pkg->cust_main->agentnum == $_->agentnum - && $FS::CurrentUser::CurrentUser->agentnum($_->agentnum) - } - map { $_->addr_block } $object->allowed_routers; - my @options = map { $_->blocknum } - sort { $a->label cmp $b->label } @addr_block; - my %option_labels = map { ( $_->blocknum => $_->label ) } @addr_block; - $fieldref->{type} = 'select'; - $fieldref->{options} = \@options; - $fieldref->{labels} = \%option_labels; - } - - } }; diff --git a/httemplate/elements/tr-select-router_block_ip.html b/httemplate/elements/tr-select-router_block_ip.html index 45d1dacd8..ed8fe810f 100644 --- a/httemplate/elements/tr-select-router_block_ip.html +++ b/httemplate/elements/tr-select-router_block_ip.html @@ -1,14 +1,22 @@ <& /elements/tr-td-label.html, label => ($opt{'label'} || 'Router') &> @@ -19,7 +27,7 @@ function hide_if_auto_addr(obj, i) { records => \@routers, name_col => 'routername', value_col => 'routernum', - onchange => 'hide_if_auto_addr', + onchange => 'lock_ip_addr', curr_value=> $opt{'routernum'}, }, { @@ -44,17 +52,18 @@ function hide_if_auto_addr(obj, i) { % } % else { + value="<% $opt{'ip_addr'} |h%>"> % } - <% $opt{'ip_addr'} || '' %> - (automatic) + <%init> + my %opt = @_; my @routers; +my $conf = FS::Conf->new; my $svc_x = $opt{'object'}; if ( $svc_x ) { @@ -91,5 +100,17 @@ else { @routers = qsearch('router', {}); } -my %auto_addr_routernum = map { $_->routernum, $_->auto_addr } @routers; +my %manual_addr_routernum = map { $_->routernum, $_->manual_addr } @routers; + +if ( $conf->exists('auto_router') ) { + # Then show an "(automatic)" router, with no blocks. manual_addr is on + # so that the ip_addr field will be unlocked. + unshift @routers, FS::router->new({ + 'routernum' => '', + 'routername' => '(automatic)', + 'manual_addr' => 'Y', + }); + $manual_addr_routernum{''} = 'Y'; +} + diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi index 961374e7d..af2c575b9 100644 --- a/httemplate/view/svc_broadband.cgi +++ b/httemplate/view/svc_broadband.cgi @@ -17,7 +17,6 @@ my %labels = map { $_ => ( ref($fields->{$_}) #my %labels = (); $labels{'description'} = emt('Description'); -$labels{'router'} = emt('Router'); $labels{'speed_down'} = emt('Download Speed'); $labels{'speed_up'} = emt('Upload Speed'); $labels{'ip_addr'} = emt('IP Address'); -- cgit v1.2.1