summaryrefslogtreecommitdiff
path: root/httemplate/edit/cgp_rule.html
blob: 1f838e23861e198294c6bcae8baab8dbf65b7aeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<% 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' => scalar($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' => scalar($cgi->param("ruleactionnum$num")),
              map { $_ => scalar($cgi->param("ruleactionnum${num}_$_")) } @fields,
            };
            $x;
          } else {
            ();
          }
        } else {
          ();
        }
      }
      $cgi->param;

};

</%init>