diff options
author | ivan <ivan> | 2010-04-30 02:32:39 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-04-30 02:32:39 +0000 |
commit | 6873aec01740ea7c70a5e20a3f3bce6e76bca410 (patch) | |
tree | 64298627d0396ab78310ce9f5059665a5f8c1bdd /httemplate | |
parent | 2ac302e18d723563692cdbbd74f3e9e5331a3014 (diff) |
communigate (phase 2): rules: show conditions/actions on rule browse, fix rule edit for conditions and actions without op/param, fix rule edit stickiness on errors. RT#7514
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/cgp_rule.html | 40 | ||||
-rw-r--r-- | httemplate/edit/cgp_rule.html | 58 | ||||
-rw-r--r-- | httemplate/elements/select-cgp_rule_action.html | 8 | ||||
-rw-r--r-- | httemplate/elements/select-cgp_rule_condition.html | 8 |
4 files changed, 101 insertions, 13 deletions
diff --git a/httemplate/browse/cgp_rule.html b/httemplate/browse/cgp_rule.html index 3bf4d69bd..ea11d62bf 100644 --- a/httemplate/browse/cgp_rule.html +++ b/httemplate/browse/cgp_rule.html @@ -7,13 +7,15 @@ 'order_by' => 'ORDER BY priority DESC', }, 'count_query' => $count_query, - 'header' => [ 'Priority', 'Name', '' ], + 'header' => [ 'Priority', 'Name', 'Conditions', 'Actions', '' ], 'fields' => [ sub { shift->priority || 'Inactive'; }, 'name', + $condition_sub, + $action_sub, sub { 'Delete'; }, ], #'align' - 'links' => [ $edit_sub, $edit_sub, $del_sub ], + 'links' => [ $edit_sub, $edit_sub, '', '', $del_sub ], ) %> <%init> @@ -40,6 +42,40 @@ my $html_init = qq(<A HREF="$view">View this $svc_label</A><BR><BR>). qq!<A HREF="${p}edit/cgp_rule.html?svcnum=$svcnum">Add new rule</A><BR><BR>!; +my $condition_sub = sub { + my $cgp_rule = shift; + + [ map { + [ + { data => $_->condition, + #align => + }, + { data => $_->op, + align => 'center', + }, + { data => $_->params, + #align => + }, + ]; + } + $cgp_rule->cgp_rule_condition + ]; +}; + +my $action_sub = sub { + my $cgp_rule = shift; + + [ map { + [ + { data => $_->action }, + #{ data => '<pre>'.$_->params.'</pre>' }, #gets very big.. limit to + { data => $_->params }, # some actions? + ]; + } + $cgp_rule->cgp_rule_action + ]; +}; + my $edit_sub = [ $p.'edit/cgp_rule.html?', 'rulenum' ]; my $del_sub = [ $p.'misc/delete-cgp_rule.html?', 'rulenum' ]; #XXX javascript areyousure or something diff --git a/httemplate/edit/cgp_rule.html b/httemplate/edit/cgp_rule.html index adf993f25..d9c19a150 100644 --- a/httemplate/edit/cgp_rule.html +++ b/httemplate/edit/cgp_rule.html @@ -23,8 +23,7 @@ 'type' => 'select-cgp_rule_condition', 'o2m_table' => 'cgp_rule_condition', 'm2_label' => 'Condition', - #XXX m2_error_callback - 'm2_error_callback' => sub {}, + 'm2_error_callback' => $m2_error_callback_cond, }, { 'type' => 'tablebreak-tr-title', 'value' => 'Actions', @@ -33,8 +32,7 @@ 'type' => 'select-cgp_rule_action', 'o2m_table' => 'cgp_rule_action', 'm2_label' => 'Action', - #XXX m2_error_callback - 'm2_error_callback' => sub {}, + 'm2_error_callback' => $m2_error_callback_action, }, ], 'new_callback' => sub { my( $cgi, $cgp_rule ) = @_; @@ -48,7 +46,57 @@ my %opt = @_; -#my $svcnum #huh XXX #my $viewall_url = $p. "browse/$table.html?svcnum=$svcnum"; +my $m2_error_callback_cond = sub { + my($cgi, $object) = @_; + + my @fields = qw( condition 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_condition { + 'ruleactionnum' => $cgi->param("ruleactionnum$num"), + map { $_ => scalar($cgi->param("ruleactionnum${num}_$_")) } @fields, + }; + $x; + } else { + (); + } + } else { + (); + } + } + $cgi->param; + +}; + </%init> diff --git a/httemplate/elements/select-cgp_rule_action.html b/httemplate/elements/select-cgp_rule_action.html index 9ac930633..7cefdc4b5 100644 --- a/httemplate/elements/select-cgp_rule_action.html +++ b/httemplate/elements/select-cgp_rule_action.html @@ -6,8 +6,7 @@ 'field' => $name.'_action', 'id' => $id.'_action', 'options' => \@actions, - 'curr_value' => scalar($cgi->param($name.'_action')) - || $cgp_rule_action->action, + 'curr_value' => $action, 'labels' => { '' => 'Select Action' }, 'onchange' => $name.'_changed', 'style' => 'vertical-align:top', @@ -108,7 +107,10 @@ if ( $curr_value ) { $cgp_rule_action = new FS::cgp_rule_action {}; } -my $disabled = $noparam{$curr_value} ? 'DISABLED' : ''; +my $action = scalar($cgi->param($name.'_action')) + || $cgp_rule_action->action; + +my $disabled = $noparam{$action} ? 'DISABLED' : ''; my $style = $disabled ? 'STYLE="visibility:hidden"' : ''; </%init> diff --git a/httemplate/elements/select-cgp_rule_condition.html b/httemplate/elements/select-cgp_rule_condition.html index 0c305d916..622cbe86d 100644 --- a/httemplate/elements/select-cgp_rule_condition.html +++ b/httemplate/elements/select-cgp_rule_condition.html @@ -6,8 +6,7 @@ 'field' => $name.'_condition', 'id' => $id.'_condition', 'options' => \@conditions, - 'curr_value' => scalar($cgi->param($name.'_condition')) - || $cgp_rule_condition->condition, + 'curr_value' => $condition, 'labels' => { '' => 'Select Condition' }, 'onchange' => $name.'_changed', ) @@ -190,7 +189,10 @@ if ( $curr_value ) { $cgp_rule_condition = new FS::cgp_rule_condition {}; } -my @op = &$cond2op($curr_value); +my $condition = scalar($cgi->param($name.'_condition')) + || $cgp_rule_condition->condition; + +my @op = &$cond2op($condition); my $disabled = scalar(@op) ? '' : 1; my $style = $disabled ? 'visibility:hidden' : ''; |