9ac93063314bf5ee0b5526be049f47479fe76518
[freeside.git] / httemplate / elements / select-cgp_rule_action.html
1 % unless ( $opt{'js_only'} ) {
2
3     <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<%$curr_value%>">
4
5     <% include( 'select.html',
6                   'field'      => $name.'_action',
7                   'id'         => $id.'_action',
8                   'options'    => \@actions,
9                   'curr_value' => scalar($cgi->param($name.'_action'))
10                                   || $cgp_rule_action->action,
11                   'labels'     => { '' => 'Select Action' },
12                   'onchange'   => $name.'_changed',
13                   'style'      => 'vertical-align:top',
14               )
15     %>
16
17     <TEXTAREA NAME          = "<% $name %>_params"
18                 ID          = "<% $id %>_params"
19                 <% $disabled %>
20                 <% $style %>
21 %#                <% $rows %>
22 %#                <% $cols %>
23 %#                <% $onchange %>
24       ><% scalar($cgi->param($name.'_params')) || $cgp_rule_action->params |h %></TEXTAREA>
25
26 % }
27 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
28     <SCRIPT TYPE="text/javascript">
29 % }
30 % unless ( $opt{'html_only'} ) {
31
32     function <% $name %>_changed(what) {
33
34         <% $opt{'onchange'} %>
35
36         var <% $name %>_value = what.options[what.selectedIndex].value;
37
38         var params_Element = what.form.<% $name %>_params;
39
40         // if bool, hide/disable _op and _params entirely
41         if ( <%$name%>_value == '' || <%$name%>_value == 'Stop Processing' || <%$name%>_value == 'Discard' ) {
42           params_Element.disabled = true;
43           params_Element.style.visibility = "hidden";
44         } else {
45           params_Element.disabled = false;
46           params_Element.style.visibility = "visible";
47
48         }
49         
50     }
51
52 % }
53 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
54     </SCRIPT>
55 % }
56 <%once>
57
58 my @actions = (
59   '',
60
61   #generic http://www.communigate.com/CommunigatePro/Rules.html#Actions
62   'Reject',
63   'SendURL',
64   'Send IM',
65   'FingerNotify',
66   'Write To Log',
67   "Remember 'From' in",
68
69   #email http://www.communigate.com/CommunigatePro/QueueRules.html#Actions
70   'Stop Processing',
71   'Discard',
72   'Reject With',
73   'Mark',
74   'Add Header',
75   'Tag Subject',
76   'Store in',
77   'Redirect to',
78   'Forward to',
79   'Mirror to',
80   'Reply with',
81   'Reply to All with',
82   'React with',
83   'store Encrypted in',
84   'Copy attachments into',
85   'Execute',
86   'ExternalFilter',
87   'Accept Request',
88 );
89
90 my %noparam = ( map { $_=>1 } '', 'Stop Processing', 'Discard' );
91
92 </%once>
93 <%init>
94
95 my %opt = @_;
96
97 my $name = $opt{'element_name'} || $opt{'field'} || 'ruleactionnum';
98 #my $id = $opt{'id'} || 'contactnum';
99 my $id = $opt{'id'} || $opt{'field'} || 'ruleactionnum';
100
101 my $curr_value = $opt{'curr_value'} || $opt{'value'};
102
103 my $cgp_rule_action;
104 if ( $curr_value ) {
105   $cgp_rule_action = qsearchs('cgp_rule_action',
106                                 { 'ruleactionnum' => $curr_value } );
107 } else {
108   $cgp_rule_action = new FS::cgp_rule_action {};
109 }
110
111 my $disabled = $noparam{$curr_value} ? 'DISABLED' : '';
112 my $style = $disabled ? 'STYLE="visibility:hidden"' : '';
113
114 </%init>