% include('elements/edit.html',
'name_singular' => 'rule',
'table' => 'cgp_rule',
'labels' => { 'rulenum' => 'Rule',
'name' => 'Name',
'comment' => 'Comment',
'priority' => 'Priority',
'ruleconditionnum' => 'Condition',
'ruleactionnum' => 'Action',
},
'fields' => [ 'name',
'comment',
{ 'field' => 'priority',
'type' => 'select',
'options' => [ 0 .. 10 ],
'labels' => { 0 => 'Inactive' },
},
{ 'field' => 'svcnum', 'type' => 'hidden', },
{ 'type' => 'tablebreak-tr-title',
'value' => 'Conditions',
},
{ 'field' => 'ruleconditionnum',
'type' => 'select-cgp_rule_condition',
'o2m_table' => 'cgp_rule_condition',
'm2_label' => 'Condition',
'm2_error_callback' => $m2_error_callback_cond,
},
{ 'type' => 'tablebreak-tr-title',
'value' => 'Actions',
},
{ 'field' => 'ruleactionnum',
'type' => 'select-cgp_rule_action',
'o2m_table' => 'cgp_rule_action',
'm2_label' => 'Action',
'm2_error_callback' => $m2_error_callback_action,
},
],
'new_callback' => sub { my( $cgi, $cgp_rule ) = @_;
$cgp_rule->svcnum( $cgi->param('svcnum') );
},
#'viewall_url' => $viewall_url,
'menubar' => [],
)
%>
<%init>
my %opt = @_;
#my $viewall_url = $p. "browse/$table.html?svcnum=$svcnum";
my $m2_error_callback_cond = sub {
my($cgi, $object) = @_;
my @fields = qw( conditionname op params );
my @gfields = ( '', map "_$_", @fields );
map {
if ( /^ruleconditionnum(\d+)$/ ) {
my $num = $1;
if ( grep $cgi->param("ruleconditionnum$num$_"), @gfields ) {
my $x = new FS::cgp_rule_condition {
'ruleconditionnum' => $cgi->param("ruleconditionnum$num"),
map { $_ => scalar($cgi->param("ruleconditionnum${num}_$_")) } @fields,
};
$x;
} else {
();
}
} else {
();
}
}
$cgi->param;
};
my $m2_error_callback_action = sub {
my($cgi, $object) = @_;
my @fields = qw( action params );
my @gfields = ( '', map "_$_", @fields );
map {
if ( /^ruleactionnum(\d+)$/ ) {
my $num = $1;
if ( grep $cgi->param("ruleactionnum$num$_"), @gfields ) {
my $x = new FS::cgp_rule_action {
'ruleactionnum' => $cgi->param("ruleactionnum$num"),
map { $_ => scalar($cgi->param("ruleactionnum${num}_$_")) } @fields,
};
$x;
} else {
();
}
} else {
();
}
}
$cgi->param;
};
%init>