merge NG auth, RT#21563
[freeside.git] / httemplate / edit / process / elements / process.html
index 071c43a..0439d4e 100644 (file)
@@ -59,12 +59,20 @@ Example:
    'process_o2m' => { 'table' => table_name',
                       'num_col' => 'column', #if column name is different in
                                              #link_table than source_table 
+                      'fields' => [qw( fieldname fieldname2 )],
                     },
 
+   'skip_process' => 0, #boolean, if set true, will skip the main table
+                        #add/edit processing and only run any linked table
+                        #process_ items
+
    #checks CGI params and whatever else before much else runs
    #return an error string or empty for no error
    'precheck_callback' => sub { my( $cgi ) = @_; },
 
+   #after the new object is created
+   'post_new_object_callback' => sub { my( $cgi, $object ) = @_; },
+
    #after everything's inserted
    'noerror_callback' => sub { my( $cgi, $object ) = @_; },
 
@@ -196,69 +204,83 @@ my %hash =
 my @values = ( 1 );
 if ( $bfield ) {
   @values = $cgi->param($bfield);
-  warn join(',', @values);
+  #warn join(',', @values);
 }
 
 my $new;
 my $new_pkey = '';
 foreach my $value ( @values ) {
 
-  $new = $class->new( \%hash );
+  if ($opt{'skip_process'}) {
+
+    $new = $old;
+    $new_pkey = $old_pkey;
+
+  } else {
+
+    $new = $class->new( \%hash );
 
-  $new->$bfield($value) if $bfield;
+    $new->$bfield($value) if $bfield;
 
-  if ($old && exists($opt{'copy_on_empty'})) {
-    foreach my $field (@{$opt{'copy_on_empty'}}) {
-      $new->set($field, $old->get($field))
-        unless scalar($cgi->param($field));
+    if ($old && exists($opt{'copy_on_empty'})) {
+      foreach my $field (@{$opt{'copy_on_empty'}}) {
+        $new->set($field, $old->get($field))
+          unless scalar($cgi->param($field));
+      }
     }
-  }
 
-  if ( $opt{'agent_virt'} ) {
+    if ( $opt{'post_new_object_callback'} ) {
+      &{ $opt{'post_new_object_callback'} }( $cgi, $new );
+    }
 
-    if ( ! $new->agentnum
-         && (    ! $opt{'agent_null_right'}
-              || ! $curuser->access_right($opt{'agent_null_right'})
-            )
-       )
-    {
+    if ( $opt{'agent_virt'} ) {
 
-      $error ||= 'Select an agent';
+      if ( ! $new->agentnum
+           && (    ! $opt{'agent_null_right'}
+                || ! $curuser->access_right($opt{'agent_null_right'})
+              )
+         )
+      {
 
-    } else {
+        $error ||= 'Select an agent';
 
-      die "illegal agentnum"
-        unless $curuser->agentnums_href->{$new->agentnum}
-            or $curuser->access_right('View customers of all agents')
-            or $opt{'agent_null_right'}
-               && ! $new->agentnum
-               && $curuser->access_right($opt{'agent_null_right'});
+      } else {
+
+        die "illegal agentnum"
+          unless $curuser->agentnums_href->{$new->agentnum}
+              or $curuser->access_right('View customers of all agents')
+              or $opt{'agent_null_right'}
+                 && ! $new->agentnum
+                 && $curuser->access_right($opt{'agent_null_right'});
+
+      }
 
     }
 
-  }
+    my @args = ();
+    if ( !$error && $opt{'args_callback'} ) {
+      @args = &{ $opt{'args_callback'} }( $cgi, $new );
+    }
 
-  $error ||= $new->check;
+    if ( !$error && $opt{'debug'} ) {
+      warn "$me updating record in $table table using $class class\n";
+      warn Dumper(\%hash);
+      warn "with args: \n". Dumper(\@args) if @args;
+    }
 
-  my @args = ();
-  if ( !$error && $opt{'args_callback'} ) {
-    @args = &{ $opt{'args_callback'} }( $cgi, $new );
-  }
+    if ( !$error ) {
+      if ( $old_pkey ) {
 
-  if ( !$error && $opt{'debug'} ) {
-    warn "$me updating record in $table table using $class class\n";
-    warn Dumper(\%hash);
-    warn "with args: \n". Dumper(\@args) if @args;
-  }
+        &{ $opt{'edit_callback'} }( $new, $old ) if $opt{'edit_callback'};
 
-  if ( !$error ) {
-    if ( $old_pkey ) {
-      $error = $new->replace($old, @args);
-    } else {
-      $error = $new->insert(@args);
+        $error = $new->replace($old, @args);
+      } else {
+        $error = $new->insert(@args);
+      }
+      $new_pkey = $new->getfield($pkey);
     }
-    $new_pkey = $new->getfield($pkey);
-  }
+
+  } #unless $opt{'skip_process'}
 
   if ( !$error && $opt{'process_m2m'} ) {
 
@@ -343,5 +365,4 @@ foreach my $value ( @values ) {
   last if $error;
 
 }
-
 </%init>