1 % unless ( $opt{'js_only'} ) {
3 <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
5 <% include( 'select.html',
6 'field' => $name.'_conditionname',
7 'id' => $id.'_conditionname',
8 'options' => \@conditions,
9 'curr_value' => $conditionname,
10 'labels' => { '' => 'Select Condition' },
11 'onchange' => $name.'_changed',
15 <% include( 'select.html',
16 'field' => $name.'_op',
19 'curr_value' => scalar($cgi->param($name.'_op'))
20 || $cgp_rule_condition->op,
21 'disabled' => $disabled,
26 <% include( 'input-text.html',
27 'field' => $name.'_params',
28 'id' => $id.'_params',
29 'curr_value' => scalar($cgi->param($name.'_params'))
30 || $cgp_rule_condition->params,
31 'disabled' => $disabled,
33 'nodarken_disabled' => 1,
37 % # could add more UI sugar for date/time ranges, string #lists, etc.
40 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
41 <SCRIPT TYPE="text/javascript">
43 % unless ( $opt{'html_only'} ) {
45 function opt(what,value,text) {
46 var optionName = new Option(text, value, false, false);
47 var length = what.length;
48 what.options[length] = optionName;
51 function <% $name %>_changed(what) {
55 var <% $name %>_value = what.options[what.selectedIndex].value;
57 var op_Element = what.form.<% $name %>_op;
58 var params_Element = what.form.<% $name %>_params;
60 //cond2op in javascript... not as elegant cause my js << my perl
62 // if bool, hide/disable _op and _params entirely
63 if ( <%$name%>_value == '' || <%$name%>_value == 'Human Generated' ) {
64 op_Element.disabled = true;
65 op_Element.style.visibility = "hidden";
66 params_Element.disabled = true;
67 params_Element.style.visibility = "hidden";
71 var OpArray = [ 'is', 'is not' ];
74 if ( <%$name%>_value == 'Message Size' || <%$name%>_value == 'Time of Day' || <%$name%>_value == 'Current Date' ) {
75 OpArray.push('less than');
76 OpArray.push('greater than');
79 // unless no_in, add em
80 if ( <%$name%>_value != 'Message Size' && <%$name%>_value != 'Current Date' && <%$name%>_value != 'Existing Mailbox' ) {
82 OpArray.push('not in');
85 // blank the current op list
86 for ( var i = op_Element.length; i >= 0; i-- )
87 op_Element.options[i] = null;
89 // update the _op select with this new array
90 for ( var s = 0; s < OpArray.length; s++ )
91 opt(what.form.<% $name %>_op, OpArray[s], OpArray[s]);
93 // show _op and _params (in case we were a bool before)
94 op_Element.disabled = false;
95 op_Element.style.visibility = "visible";
96 params_Element.disabled = false;
97 params_Element.style.visibility = "visible";
101 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
109 #generic http://www.communigate.com/CommunigatePro/Rules.html#Conditions
118 #email http://www.communigate.com/CommunigatePro/QueueRules.html#Conditions
141 my %bool = ( map { $_=>1 } ( #hide the op and valud dropdowns entirely
146 my %no_in = ( map { $_=>1 } ( #hide in/not in
152 my %lt_gt = ( map { $_=>1 } ( #add less than/greater than
160 return () if $bool{$cond};
161 my @op = ( 'is', 'is not' );
162 push @op, 'less than', 'greater than' if $lt_gt{$cond};
163 push @op, 'in', 'not in' unless $no_in{$cond};
172 my $name = $opt{'element_name'} || $opt{'field'} || 'ruleconditionnum';
173 #my $id = $opt{'id'} || 'contactnum';
174 my $id = $opt{'id'} || $opt{'field'} || 'ruleconditionnum';
176 my $curr_value = $opt{'curr_value'} || $opt{'value'};
179 if ( $opt{'onchange'} ) {
180 $onchange = $opt{'onchange'};
181 $onchange .= '(what)' unless $onchange =~ /\(\w*\);?$/;
184 my $cgp_rule_condition;
186 $cgp_rule_condition = qsearchs('cgp_rule_condition',
187 { 'ruleconditionnum' => $curr_value } );
189 $cgp_rule_condition = new FS::cgp_rule_condition {};
192 my $conditionname = scalar($cgi->param($name.'_conditionname'))
193 || $cgp_rule_condition->conditionname;
195 my @op = &$cond2op($conditionname);
197 my $disabled = scalar(@op) ? '' : 1;
198 my $style = $disabled ? 'visibility:hidden' : '';