From 2ac302e18d723563692cdbbd74f3e9e5331a3014 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 29 Apr 2010 07:40:46 +0000 Subject: [PATCH] communigate (phase 2): rules: adding conditions and actions to rule edit. RT#7514 --- FS/FS/cgp_rule.pm | 2 +- httemplate/edit/cgp_rule.html | 32 +++--- httemplate/edit/process/cgp_rule.html | 14 ++- httemplate/elements/input-text.html | 8 +- httemplate/elements/select-cgp_rule_action.html | 99 ++++++++++++++---- httemplate/elements/select-cgp_rule_condition.html | 113 ++++++++++++++------- httemplate/elements/select.html | 16 +++ 7 files changed, 205 insertions(+), 79 deletions(-) diff --git a/FS/FS/cgp_rule.pm b/FS/FS/cgp_rule.pm index 7e5c9fefb..82e712204 100644 --- a/FS/FS/cgp_rule.pm +++ b/FS/FS/cgp_rule.pm @@ -1,7 +1,7 @@ package FS::cgp_rule; use strict; -use base qw( FS::Record ); +use base qw( FS::o2m_Common FS::Record ); use FS::Record qw( qsearch qsearchs dbh ); use FS::cust_svc; use FS::cgp_rule_condition; diff --git a/httemplate/edit/cgp_rule.html b/httemplate/edit/cgp_rule.html index 6f2d80161..adf993f25 100644 --- a/httemplate/edit/cgp_rule.html +++ b/httemplate/edit/cgp_rule.html @@ -10,29 +10,31 @@ }, 'fields' => [ 'name', 'comment', - { 'field' => 'priority', - 'type' => 'select', - 'options' => [ 0 .. 10 ], - 'labels' => { 0 => 'Inactive' }, + { 'field' => 'priority', + 'type' => 'select', + 'options' => [ 0 .. 10 ], + 'labels' => { 0 => 'Inactive' }, }, - { 'field' => 'svcnum', 'type' => 'hidden', }, - { 'type' => 'tablebreak-tr-title', - 'value' => 'Conditions', + { 'field' => 'svcnum', 'type' => 'hidden', }, + { 'type' => 'tablebreak-tr-title', + 'value' => 'Conditions', }, - { 'field' => 'ruleconditionnum', - 'type' => 'select-cgp_rule_condition', + { 'field' => 'ruleconditionnum', + 'type' => 'select-cgp_rule_condition', 'o2m_table' => 'cgp_rule_condition', - 'm2_label' => 'Condition', + 'm2_label' => 'Condition', #XXX m2_error_callback + 'm2_error_callback' => sub {}, }, - { 'type' => 'tablebreak-tr-title', - 'value' => 'Actions', + { 'type' => 'tablebreak-tr-title', + 'value' => 'Actions', }, - { 'field' => 'ruleactionnum', - 'type' => 'select-cgp_rule_action', + { 'field' => 'ruleactionnum', + 'type' => 'select-cgp_rule_action', 'o2m_table' => 'cgp_rule_action', - 'm2_label' => 'Action', + 'm2_label' => 'Action', #XXX m2_error_callback + 'm2_error_callback' => sub {}, }, ], 'new_callback' => sub { my( $cgi, $cgp_rule ) = @_; diff --git a/httemplate/edit/process/cgp_rule.html b/httemplate/edit/process/cgp_rule.html index 3880b56b9..f427b6ccf 100644 --- a/httemplate/edit/process/cgp_rule.html +++ b/httemplate/edit/process/cgp_rule.html @@ -1,6 +1,16 @@ <% include( 'elements/process.html', - 'table' => 'cgp_rule', - 'redirect' => $redirect, + 'table' => 'cgp_rule', + 'redirect' => $redirect, + 'process_o2m' => [ + { + 'table' => 'cgp_rule_condition', + 'fields' => [qw( condition op params )], + }, + { + 'table' => 'cgp_rule_action', + 'fields' => [qw( action params )], + }, + ], ) %> <%init> diff --git a/httemplate/elements/input-text.html b/httemplate/elements/input-text.html index 9db064348..fb50a5070 100644 --- a/httemplate/elements/input-text.html +++ b/httemplate/elements/input-text.html @@ -31,13 +31,17 @@ $opt{'disabled'} = &{ $opt{'disabled'} }( \%opt ) $opt{'disabled'} = 'DISABLED' if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah? -my @style = (); +my @style = ref($opt{'style'}) + ? @{ $opt{'style'} } + : $opt{'style'} + ? ( $opt{'style'} ) + : (); push @style, 'text-align: '. $opt{'text-align'} if $opt{'text-align'}; push @style, 'background-color: #dddddd' - if $opt{'disabled'}; + if $opt{'disabled'} && ! $opt{'nodarken_disabled'}; my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : ''; diff --git a/httemplate/elements/select-cgp_rule_action.html b/httemplate/elements/select-cgp_rule_action.html index 25c3a2567..9ac930633 100644 --- a/httemplate/elements/select-cgp_rule_action.html +++ b/httemplate/elements/select-cgp_rule_action.html @@ -1,22 +1,59 @@ -%# XXX CSS to verticially align the select vs. the textarea -<% include( 'select.html', - %opt, - 'options' => \@actions, #reverse order if we ever need to specify - 'labels' => { '' => 'Select Action' }, - ) -%> - - > -%# XXX curr value - -<%init> +% unless ( $opt{'js_only'} ) { -my %opt = @_; + + + <% include( 'select.html', + 'field' => $name.'_action', + 'id' => $id.'_action', + 'options' => \@actions, + 'curr_value' => scalar($cgi->param($name.'_action')) + || $cgp_rule_action->action, + 'labels' => { '' => 'Select Action' }, + 'onchange' => $name.'_changed', + 'style' => 'vertical-align:top', + ) + %> + + + +% } +% unless ( $opt{'html_only'} || $opt{'js_only'} ) { + +% } +<%once> my @actions = ( '', @@ -50,6 +87,28 @@ my @actions = ( 'Accept Request', ); -#XXX hmm, hide textarea w/Stop Processing,Discard like _condition.html +my %noparam = ( map { $_=>1 } '', 'Stop Processing', 'Discard' ); + + +<%init> + +my %opt = @_; + +my $name = $opt{'element_name'} || $opt{'field'} || 'ruleactionnum'; +#my $id = $opt{'id'} || 'contactnum'; +my $id = $opt{'id'} || $opt{'field'} || 'ruleactionnum'; + +my $curr_value = $opt{'curr_value'} || $opt{'value'}; + +my $cgp_rule_action; +if ( $curr_value ) { + $cgp_rule_action = qsearchs('cgp_rule_action', + { 'ruleactionnum' => $curr_value } ); +} else { + $cgp_rule_action = new FS::cgp_rule_action {}; +} + +my $disabled = $noparam{$curr_value} ? 'DISABLED' : ''; +my $style = $disabled ? 'STYLE="visibility:hidden"' : ''; - + diff --git a/httemplate/elements/select-cgp_rule_condition.html b/httemplate/elements/select-cgp_rule_condition.html index eaf7211fa..0c305d916 100644 --- a/httemplate/elements/select-cgp_rule_condition.html +++ b/httemplate/elements/select-cgp_rule_condition.html @@ -1,25 +1,42 @@ % unless ( $opt{'js_only'} ) { + + + <% include( 'select.html', - %opt, - 'options' => \@conditions, - 'labels' => { '' => 'Select Condition' }, - 'onchange' => $key.'_changed', + 'field' => $name.'_condition', + 'id' => $id.'_condition', + 'options' => \@conditions, + 'curr_value' => scalar($cgi->param($name.'_condition')) + || $cgp_rule_condition->condition, + 'labels' => { '' => 'Select Condition' }, + 'onchange' => $name.'_changed', ) %> + <% include( 'select.html', - 'name' => $opt{'field'}.'_op', - 'id' => $key.'_op', - 'options' => \@op, - #XXX curr op + 'field' => $name.'_op', + 'id' => $id.'_op', + 'options' => \@op, + 'curr_value' => scalar($cgi->param($name.'_op')) + || $cgp_rule_condition->op, + 'disabled' => $disabled, + 'style' => $style, ) %> + <% include( 'input-text.html', - 'name' => $opt{'field'}.'_params', - 'id' => $key.'_params', - #XXX curr value... anything else? + 'field' => $name.'_params', + 'id' => $id.'_params', + 'curr_value' => scalar($cgi->param($name.'_params')) + || $cgp_rule_condition->params, + 'disabled' => $disabled, + 'style' => $style, + 'nodarken_disabled' => 1, ) %> + % # could add more UI sugar for date/time ranges, string #lists, etc. + % } % unless ( $opt{'html_only'} || $opt{'js_only'} ) {