1 % unless ( $opt{'js_only'} ) {
3 <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
5 <% include( 'select.html',
6 'field' => $name.'_condition',
7 'id' => $id.'_condition',
8 'options' => \@conditions,
9 'curr_value' => scalar($cgi->param($name.'_condition'))
10 || $cgp_rule_condition->condition,
11 'labels' => { '' => 'Select Condition' },
12 'onchange' => $name.'_changed',
16 <% include( 'select.html',
17 'field' => $name.'_op',
20 'curr_value' => scalar($cgi->param($name.'_op'))
21 || $cgp_rule_condition->op,
22 'disabled' => $disabled,
27 <% include( 'input-text.html',
28 'field' => $name.'_params',
29 'id' => $id.'_params',
30 'curr_value' => scalar($cgi->param($name.'_params'))
31 || $cgp_rule_condition->params,
32 'disabled' => $disabled,
34 'nodarken_disabled' => 1,
38 % # could add more UI sugar for date/time ranges, string #lists, etc.
41 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
42 <SCRIPT TYPE="text/javascript">
44 % unless ( $opt{'html_only'} ) {
46 function opt(what,value,text) {
47 var optionName = new Option(text, value, false, false);
48 var length = what.length;
49 what.options[length] = optionName;
52 function <% $name %>_changed(what) {
56 var <% $name %>_value = what.options[what.selectedIndex].value;
58 var op_Element = what.form.<% $name %>_op;
59 var params_Element = what.form.<% $name %>_params;
61 //cond2op in javascript... not as elegant cause my js << my perl
63 // if bool, hide/disable _op and _params entirely
64 if ( <%$name%>_value == '' || <%$name%>_value == 'Human Generated' ) {
65 op_Element.disabled = true;
66 op_Element.style.visibility = "hidden";
67 params_Element.disabled = true;
68 params_Element.style.visibility = "hidden";
72 var OpArray = [ 'is', 'is not' ];
75 if ( <%$name%>_value == 'Message Size' || <%$name%>_value == 'Time of Day' || <%$name%>_value == 'Current Date' ) {
76 OpArray.push('less than');
77 OpArray.push('greater than');
80 // unless no_in, add em
81 if ( <%$name%>_value != 'Message Size' && <%$name%>_value != 'Current Date' && <%$name%>_value != 'Existing Mailbox' ) {
83 OpArray.push('not in');
86 // blank the current op list
87 for ( var i = op_Element.length; i >= 0; i-- )
88 op_Element.options[i] = null;
90 // update the _op select with this new array
91 for ( var s = 0; s < OpArray.length; s++ )
92 opt(what.form.<% $name %>_op, OpArray[s], OpArray[s]);
94 // show _op and _params (in case we were a bool before)
95 op_Element.disabled = false;
96 op_Element.style.visibility = "visible";
97 params_Element.disabled = false;
98 params_Element.style.visibility = "visible";
102 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
110 #generic http://www.communigate.com/CommunigatePro/Rules.html#Conditions
119 #email http://www.communigate.com/CommunigatePro/QueueRules.html#Conditions
142 my %bool = ( map { $_=>1 } ( #hide the op and valud dropdowns entirely
147 my %no_in = ( map { $_=>1 } ( #hide in/not in
153 my %lt_gt = ( map { $_=>1 } ( #add less than/greater than
161 return () if $bool{$cond};
162 my @op = ( 'is', 'is not' );
163 push @op, 'less than', 'greater than' if $lt_gt{$cond};
164 push @op, 'in', 'not in' unless $no_in{$cond};
173 my $name = $opt{'element_name'} || $opt{'field'} || 'ruleconditionnum';
174 #my $id = $opt{'id'} || 'contactnum';
175 my $id = $opt{'id'} || $opt{'field'} || 'ruleconditionnum';
177 my $curr_value = $opt{'curr_value'} || $opt{'value'};
180 if ( $opt{'onchange'} ) {
181 $onchange = $opt{'onchange'};
182 $onchange .= '(what)' unless $onchange =~ /\(\w*\);?$/;
185 my $cgp_rule_condition;
187 $cgp_rule_condition = qsearchs('cgp_rule_condition',
188 { 'ruleconditionnum' => $curr_value } );
190 $cgp_rule_condition = new FS::cgp_rule_condition {};
193 my @op = &$cond2op($curr_value);
195 my $disabled = scalar(@op) ? '' : 1;
196 my $style = $disabled ? 'visibility:hidden' : '';