X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Fsvc_Common.html;h=fc29327aee98cfd42cc8ac0793a7166c008b6717;hb=5ffd80e8e6ac4554fc4515b018eaf0354ebcdc9a;hp=4355cb4cd10bc7b93e7636c6cf47646db68dddb3;hpb=9c7dee35f91a386fcce14cb6c3e9d23ba3eee8af;p=freeside.git diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index 4355cb4cd..fc29327ae 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -1,27 +1,9 @@ -% -% my %opt = @_; -% -% #my( $svcnum, $pkgnum, $svcpart, $part_svc ); -% my( $pkgnum, $svcpart, $part_svc ); -% -% #get & untaint pkgnum & svcpart -% if ( ! $cgi->param('error') -% && $cgi->param('pkgnum') && $cgi->param('svcpart') -% ) -% { -% $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; -% $pkgnum = $1; -% $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; -% $svcpart = $1; -% #$cgi->delete_all(); #so edit.html treats this correctly as new?? -% } -% <% include( 'edit.html', 'menubar' => [], 'error_callback' => sub { - my( $cgi, $svc_x ) = @_; + my( $cgi, $svc_x, $fields, $opt ) = @_; #$svcnum = $svc_x->svcnum; $pkgnum = $cgi->param('pkgnum'); $svcpart = $cgi->param('svcpart'); @@ -29,11 +11,21 @@ $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart }); die "No part_svc entry!" unless $part_svc; + label_fixup($part_svc, $opt); + $svc_x->setfield('svcpart', $svcpart); + + if ( my $cb = $opt{'svc_error_callback'} ) { + my $cust_pkg = $pkgnum + ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) + : ''; #? + &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); + } + }, 'edit_callback' => sub { - my( $cgi, $svc_x ) = @_; + my( $cgi, $svc_x, $fields, $opt ) = @_; #$svcnum = $svc_x->svcnum; my $cust_svc = $svc_x->cust_svc or die "Unknown (cust_svc) svcnum!"; @@ -43,52 +35,143 @@ $part_svc = qsearchs ('part_svc', { svcpart=>$svcpart }); die "No part_svc entry!" unless $part_svc; + + label_fixup($part_svc, $opt); + + if ( my $cb = $opt{'svc_edit_callback'} ) { + my $cust_pkg = $pkgnum + ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) + : ''; #? + &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); + } + + if ( $part_svc->has_router ) { + my $router = qsearchs('router', {svcnum => $svc_x->svcnum}); + if ( $router ) { + $svc_x->set("router_$_", $router->get($_)) + foreach ('routername', 'routernum'); + my ($block) = $router->addr_block; # one-to-one for now + if ( $block ) { + $svc_x->set('router_blocknum', $block->blocknum); + # silly, but necessary...make the currently + # assigned block appear on the list + my ($field) = grep {ref($_) and + $_->{field} eq 'router_blocknum'} + @$fields; + $field->{extra_sql} = + ' OR routernum = '.$router->routernum; + $field->{curr_value} = $block->blocknum; + } + } + } + }, 'new_hashref_callback' => sub { #my( $cgi, $svc_x ) = @_; - { svcpart => $svcpart }; + { pkgnum => $pkgnum, + svcpart => $svcpart, + }; }, 'new_callback' => sub { - my( $cgi, $svc_x ) = @_;; + my( $cgi, $svc_x, $fields, $opt ) = @_; - $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart }); - die "No part_svc entry!" unless $part_svc; + $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart }); + die "No part_svc entry!" unless $part_svc; - #$svcnum=''; + label_fixup($part_svc, $opt); - $svc_x->set_default_and_fixed; + #$svcnum=''; + if ( my $cb = $opt{'svc_new_callback'} ) { + my $cust_pkg = $pkgnum + ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) + : ''; #? + &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); + } + + $svc_x->set_default_and_fixed; }, 'field_callback' => sub { my ($cgi, $object, $f) = @_; + my $columndef = $part_svc->part_svc_column($f->{'field'}); my $flag = $columndef->columnflag; - if ( $flag eq 'F' ) { - $f->{'type'} = 'fixed'; + + if ( $flag eq 'F' ) { #fixed + $f->{'type'} = length($columndef->columnvalue) + ? 'fixed' + : 'hidden'; $f->{'value'} = $columndef->columnvalue; + + } elsif ( $flag eq 'A' ) { #auto assign from inventory + $f->{'type'} = 'hidden'; + + } elsif ( $flag eq 'M' ) { #manually assign from inventory + $f->{'type'} = 'select-inventory_item'; + $f->{'empty_label'} = 'Select inventory item'; + $f->{'extra_sql'} = 'WHERE ( svcnum IS NULL ' . + ($object->svcnum && ' OR svcnum = '.$object->svcnum) . + ')'; + $f->{'classnum'} = $columndef->columnvalue; + $f->{'disable_empty'} = $object->svcnum ? 1 : 0; + + } elsif ( $flag eq 'H' ) { #hardware + $f->{'type'} = 'select-hardware_type'; + $f->{'hashref'} = { + 'classnum'=>$columndef->columnvalue + }; + + } elsif ( $flag eq 'S' #selectable choice + && $f->{type} !~ /^select-svc(-domain|_pbx)$/ ) { + $f->{type} = 'select'; + $f->{options} = [ split( /\s*,\s*/, + $columndef->columnvalue) + ]; + } + + if ( $f->{'type'} eq 'select-svc_pbx' + || $f->{'type'} eq 'select-svc-domain' + ) + { + $f->{'include_opt_callback'} = + sub { ( 'pkgnum' => $pkgnum, + 'svcpart' => $svcpart, + ); + }; + } + + if ( $f->{'field'} eq 'custnum' && $pkgnum ) { + my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); + $object->set('custnum', $cust_pkg->custnum); + } + + if ( my $cb = $opt{'svc_field_callback'} ) { + &{ $cb }( $cgi, $object, $f); } + }, 'html_init' => sub { + my $html; my $cust_main; if ( $pkgnum ) { my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); $cust_main = $cust_pkg->cust_main if $cust_pkg; - } - $cust_main - ? include( '/elements/small_custview.html', + if ( $cust_main ) { + $html = include( '/elements/small_custview.html', $cust_main, '', 1, popurl(2). "view/cust_main.cgi" - ). '
' - : ''; - + ). '
'; + } + } + $html; }, 'html_table_bottom' => sub { @@ -116,3 +199,82 @@ %opt #pass through/override params ) %> +<%once> + +sub label_fixup { + my( $part_svc, $opt ) = @_; + + $opt->{'name'} ||= $part_svc->svc; + + my $svcdb = $part_svc->svcdb; + require "FS/$svcdb.pm"; + + if ( UNIVERSAL::can("FS::$svcdb", 'table_info') ) { + #$opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'}; + + my $fields = "FS::$svcdb"->table_info->{'fields'}; + $opt->{'fields'} ||= [ grep { $_ ne 'svcnum' } keys %$fields ]; + + $opt->{labels} ||= { + map { $_ => ( ref($fields->{$_}) + ? $fields->{$_}{'label'} + : $fields->{$_} + ); + } + keys %$fields + }; + } + + #false laziness w/view/svc_Common.html + #override default labels with service-definition labels if applicable + my $labels = $opt->{labels}; # with -> here + foreach my $field ( keys %{ $opt->{labels} } ) { + my $col = $part_svc->part_svc_column($field); + $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/; + } + + if ( $part_svc->has_router ) { + # these will be set up as pseudo-fields in the new_ and edit_ callbacks + push @{ $opt->{'fields'} }, ( + { field => 'router_routernum', type => 'hidden' }, + { field => 'router_routername', type => 'text', size => 32 }, + # router address block selection + # (one-to-one for now) + { field => 'router_blocknum', + type => 'select-table', + table => 'addr_block', + hashref => { 'routernum' => '0' }, + agent_virt => 1, + agent_null => 1, + name_col => 'cidr', + order_by => 'ORDER BY ip_gateway, ip_netmask', + empty_label => '(none)', + disable_empty => 0, + }, + ); + $labels->{router_routername} = 'Attached router name'; + $labels->{router_blocknum} = 'Attached address block'; + } +} + + +<%init> + +my %opt = @_; + +#my( $svcnum, $pkgnum, $svcpart, $part_svc ); +my( $pkgnum, $svcpart, $part_svc ); + +#get & untaint pkgnum & svcpart +if ( ! $cgi->param('error') + && $cgi->param('pkgnum') && $cgi->param('svcpart') + ) +{ + $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; + $pkgnum = $1; + $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; + $svcpart = $1; + #$cgi->delete_all(); #so edit.html treats this correctly as new?? +} + +