-%
-%
-% my %opt = @_;
-% my $table = $opt{'table'};
-% $opt{'fields'} ||= [ fields($table) ];
-% push @{ $opt{'fields'} }, qw( pkgnum svcpart );
-%
-%
<% include( 'process.html',
'edit_ext' => 'cgi',
'redirect' => popurl(3)."view/$table.cgi?",
+ 'args_callback' => $args_callback,
%opt,
)
%>
+<%init>
+my %opt = @_;
+my $table = $opt{'table'};
+$opt{'fields'} ||= [ fields($table) ];
+push @{ $opt{'fields'} }, qw( pkgnum svcpart );
+push @{ $opt{'fields'} }, @{ "FS::$table"->table_info->{'addl_process_fields'} }
+ if UNIVERSAL::can("FS::$table", 'table_info')
+ && "FS::$table"->table_info->{'addl_process_fields'};
+foreach (fields($table)) {
+ if ( $cgi->param($_.'_classnum') ) {
+ push @{ $opt{'fields'} }, $_.'_classnum';
+ }
+}
+
+my $args_callback = sub {
+ my ($cgi, $svc) = @_;
+ my $part_svc = FS::part_svc->by_key($cgi->param('svcpart'))
+ or die "svcpart required";
+ if ( $part_svc->has_router ) {
+ my $router = FS::router->new({
+ map { $_ => scalar($cgi->param("router_$_")) }
+ qw( routernum routername blocknum )
+ });
+ if ($router->blocknum and length($router->routername) == 0) {
+ #sensible default
+ $router->set('routername', $svc->label);
+ }
+ return (child_objects => [ $router ]);
+ }
+ ();
+};
+
+</%init>