add config to display note at top, RT#84990
[freeside.git] / httemplate / edit / cgp_rule.html
1 <% include('elements/edit.html',
2              'name_singular' => 'rule',
3              'table'         => 'cgp_rule',
4              'labels' => { 'rulenum'          => 'Rule',
5                            'name'             => 'Name',
6                            'comment'          => 'Comment',
7                            'priority'         => 'Priority',
8                            'ruleconditionnum' => 'Condition',
9                            'ruleactionnum'    => 'Action',
10                          },
11              'fields' => [ 'name',
12                            'comment',
13                            { 'field'     => 'priority',
14                              'type'      => 'select',
15                              'options'   => [ 0 .. 10 ],
16                              'labels'    => { 0 => 'Inactive' },
17                            },
18                            { 'field'     => 'svcnum', 'type' => 'hidden', },
19                            { 'type'      => 'tablebreak-tr-title',
20                              'value'     => 'Conditions',
21                            },
22                            { 'field'     => 'ruleconditionnum',
23                              'type'      => 'select-cgp_rule_condition',
24                              'o2m_table' => 'cgp_rule_condition',
25                              'm2_label'  => 'Condition',
26                              'm2_error_callback' => $m2_error_callback_cond,
27                            },
28                            { 'type'      => 'tablebreak-tr-title',
29                              'value'     => 'Actions',
30                            },
31                            { 'field'     => 'ruleactionnum',
32                              'type'      => 'select-cgp_rule_action',
33                              'o2m_table' => 'cgp_rule_action',
34                              'm2_label'  => 'Action',
35                              'm2_error_callback' => $m2_error_callback_action,
36                            },
37                          ],
38              'new_callback' => sub { my( $cgi, $cgp_rule ) = @_;
39                                      $cgp_rule->svcnum( $cgi->param('svcnum') );
40                                    },
41              #'viewall_url' => $viewall_url,
42              'menubar' => [],
43           )
44 %>
45 <%init>
46
47 my %opt = @_;
48
49 #my $viewall_url = $p. "browse/$table.html?svcnum=$svcnum";
50
51 my $m2_error_callback_cond = sub {
52   my($cgi, $object) = @_;
53
54   my @fields = qw( conditionname op params );
55   my @gfields = ( '', map "_$_", @fields );
56
57   map {
58         if ( /^ruleconditionnum(\d+)$/ ) {
59           my $num = $1;
60           if ( grep $cgi->param("ruleconditionnum$num$_"), @gfields ) {
61             my $x = new FS::cgp_rule_condition {
62               'ruleconditionnum' => scalar($cgi->param("ruleconditionnum$num")),
63               map { $_ => scalar($cgi->param("ruleconditionnum${num}_$_")) } @fields,
64             };
65             $x;
66           } else {
67             ();
68           }
69         } else {
70           ();
71         }
72       }
73       $cgi->param;
74 };
75
76 my $m2_error_callback_action = sub {
77   my($cgi, $object) = @_;
78
79   my @fields = qw( action params );
80   my @gfields = ( '', map "_$_", @fields );
81
82   map {
83         if ( /^ruleactionnum(\d+)$/ ) {
84           my $num = $1;
85           if ( grep $cgi->param("ruleactionnum$num$_"), @gfields ) {
86             my $x = new FS::cgp_rule_action {
87               'ruleactionnum' => scalar($cgi->param("ruleactionnum$num")),
88               map { $_ => scalar($cgi->param("ruleactionnum${num}_$_")) } @fields,
89             };
90             $x;
91           } else {
92             ();
93           }
94         } else {
95           ();
96         }
97       }
98       $cgi->param;
99
100 };
101
102 </%init>