summaryrefslogtreecommitdiff
path: root/httemplate/elements/select-cgp_rule_action.html
blob: 7cefdc4b53fe0da9471594381875d6539487edfc (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
% unless ( $opt{'js_only'} ) {

    <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<%$curr_value%>">

    <% include( 'select.html',
                  'field'      => $name.'_action',
                  'id'         => $id.'_action',
                  'options'    => \@actions,
                  'curr_value' => $action,
                  'labels'     => { '' => 'Select Action' },
                  'onchange'   => $name.'_changed',
                  'style'      => 'vertical-align:top',
              )
    %>

    <TEXTAREA NAME          = "<% $name %>_params"
                ID          = "<% $id %>_params"
                <% $disabled %>
                <% $style %>
%#                <% $rows %>
%#                <% $cols %>
%#                <% $onchange %>
      ><% scalar($cgi->param($name.'_params')) || $cgp_rule_action->params |h %></TEXTAREA>

% }
% unless ( $opt{'html_only'} || $opt{'js_only'} ) {
    <SCRIPT TYPE="text/javascript">
% }
% unless ( $opt{'html_only'} ) {

    function <% $name %>_changed(what) {

        <% $opt{'onchange'} %>

        var <% $name %>_value = what.options[what.selectedIndex].value;

        var params_Element = what.form.<% $name %>_params;

        // if bool, hide/disable _op and _params entirely
        if ( <%$name%>_value == '' || <%$name%>_value == 'Stop Processing' || <%$name%>_value == 'Discard' ) {
          params_Element.disabled = true;
          params_Element.style.visibility = "hidden";
        } else {
          params_Element.disabled = false;
          params_Element.style.visibility = "visible";

        }
        
    }

% }
% unless ( $opt{'html_only'} || $opt{'js_only'} ) {
    </SCRIPT>
% }
<%once>

my @actions = (
  '',

  #generic http://www.communigate.com/CommunigatePro/Rules.html#Actions
  'Reject',
  'SendURL',
  'Send IM',
  'FingerNotify',
  'Write To Log',
  "Remember 'From' in",

  #email http://www.communigate.com/CommunigatePro/QueueRules.html#Actions
  'Stop Processing',
  'Discard',
  'Reject With',
  'Mark',
  'Add Header',
  'Tag Subject',
  'Store in',
  'Redirect to',
  'Forward to',
  'Mirror to',
  'Reply with',
  'Reply to All with',
  'React with',
  'store Encrypted in',
  'Copy attachments into',
  'Execute',
  'ExternalFilter',
  'Accept Request',
);

my %noparam = ( map { $_=>1 } '', 'Stop Processing', 'Discard' );

</%once>
<%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 $action = scalar($cgi->param($name.'_action'))
             || $cgp_rule_action->action;

my $disabled = $noparam{$action} ? 'DISABLED' : '';
my $style = $disabled ? 'STYLE="visibility:hidden"' : '';

</%init>