RT 78356 - fixed display of error on tower and sector exports
[freeside.git] / httemplate / edit / process / elements / process.html
index fd12c61..1711b01 100644 (file)
@@ -62,6 +62,8 @@ Example:
                       'fields' => [qw( fieldname fieldname2 )],
                     },
 
+   'process_locale' => 'fieldname', # update entries in the _msgcat table
+
    'process_upload' => {
                          'process'  => 'misc/mytable-import.html',
                           # fields to pass to the back end job, besides the 
@@ -78,8 +80,12 @@ Example:
    'precheck_callback' => sub { my( $cgi ) = @_; },
 
    #after the new object is created
+   #return an error string or empty for no error
    'post_new_object_callback' => sub { my( $cgi, $object ) = @_; },
 
+   #run right before replacing (not run for inserts)
+   'edit_callback' => sub { my( $new, $old ) = @_; },
+
    #after everything's inserted
    'noerror_callback' => sub { my( $cgi, $object ) = @_; },
 
@@ -87,6 +93,9 @@ Example:
    # for use with tables that are FS::option_Common (among other things)
    'args_callback' => sub { my( $cgi, $object ) = @_; },
 
+   # if no errors after package insert or replace will update services attached to package.
+   'update_svc' => sub { my( $cgi, $object ) = @_; },
+
    'debug' => 1, #turns on debugging output
 
    #agent virtualization
@@ -100,6 +109,12 @@ Example:
 
 </%doc>
 %if ( $error ) {
+%  ## flatten any array refs so multi selects are sticky on error
+%  for my $param ($cgi->param) {
+%    if (ref($cgi->param($param)) eq "ARRAY") {
+%      $cgi->param($param, (join ",", @{$cgi->param($param)}));
+%    }
+%  }
 %
 %  #my $query = $m->scomp('/elements/create_uri_query');
 %  #$cgi->redirect("$url?$query");
@@ -186,7 +201,7 @@ process();
   <% include('/elements/header-popup.html', $opt{'popup_reload'} ) %>
 
   <SCRIPT TYPE="text/javascript">
-    window.top.location.reload();
+    topreload();
   </SCRIPT>
 
   </BODY>
@@ -271,7 +286,7 @@ foreach my $value ( @values ) {
     }
 
     if ( $opt{'post_new_object_callback'} ) {
-      &{ $opt{'post_new_object_callback'} }( $cgi, $new );
+      $error ||= &{ $opt{'post_new_object_callback'} }( $cgi, $new );
     }
 
     if ( $opt{'agent_virt'} ) {
@@ -363,12 +378,21 @@ foreach my $value ( @values ) {
 
   }
 
-  if ( !$error && $opt{'process_o2m'} ) {
-
-    my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY'
-                           ? @{ $opt{'process_o2m'} }
-                           :  ( $opt{'process_o2m'} );
+  my @process_o2m;
+  if ( $opt{'process_o2m'} ) {
+    @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY'
+                        ? @{ $opt{'process_o2m'} }
+                        :  ( $opt{'process_o2m'} );
+  }
+  if ( $opt{'process_locale'} ) {
+    push @process_o2m,
+    {
+      'table'  => $table . '_msgcat',
+      'fields' => [ 'locale', $opt{'process_locale'} ],
+    };
+  }
 
+  if ( !$error ) {
 
     foreach my $process_o2m (@process_o2m) {
 
@@ -427,6 +451,12 @@ foreach my $value ( @values ) {
     }
   }
 
+  if ( !$error and $opt{'update_svc'} ) {
+    my @args = ();
+    @args = &{ $opt{'args_callback'} }( $cgi, $new ) if $opt{'args_callback'};
+   $error = &{ $opt{'update_svc'} }( $cgi, $new, @args );
+  }
+
   if ( $error ) {
 
     $cgi->param('error', $error);
@@ -448,6 +478,16 @@ foreach my $value ( @values ) {
 
 }
 
+if ($class eq "FS::tower") {
+  foreach my $part_svc_broadband_export ( FS::tower_sector->part_export_svc_broadband ) {
+    if ($part_svc_broadband_export and $part_svc_broadband_export->can('export_tower_sector')) {
+      my $export_tower = $part_svc_broadband_export->export_tower_sector($new);
+      $error = $export_tower->{'error'} if $export_tower;
+    }
+  }
+  $cgi->param('error', $error) if $error;
+}
+
 # set up redirect URLs
 
 my $redirect;