+ 'precheck_callback' => sub {
+ my $cgi = shift;
+ my $action = $cgi->param('action') or return;
+ my %actionfields = map { $_ =~ /^$action\.(.*)/; $1 => $cgi->param($_) }
+ grep { /^$action\./ } $cgi->param;
+ if ( exists($actionfields{'reasonnum'}) and
+ length($actionfields{'reasonnum'}) == 0 ) {
+ return 'Reason required';
+ }
+ if ( $cgi->param('_initialize') ) {
+ $cgi->param('disabled', 'Y');
+ }
+
+ my $balance_age_rx = qr/^(condition.+)\.balance_age\.age$/;
+
+ foreach my $param ( keys %{ $cgi->Vars() } ){
+
+ next unless ( $param =~ /$balance_age_rx/ );
+ next unless $cgi->param($1) eq 'balance_age';
+
+ my $errstr = FS::part_event::Condition::balance_age->
+ check_options( { age => $cgi->param($param),
+ age_units => $cgi->param("${param}_units") } );
+
+ return $errstr if $errstr;
+ }
+
+ return '';
+ },
+ 'noerror_callback' => sub {
+ my ($cgi, $new) = @_;
+ if ( $cgi->param('_initialize') ) {
+ my $job = new FS::queue {
+ 'job' => 'FS::part_event::process_initialize'
+ };
+ my $error = $job->insert('eventpart' => $new->eventpart);
+ warn "error queueing job: $error\n" if $error; # can't do anything else
+ }
+ },