communigate (phase 2): rules: adding conditions and actions to rule edit. RT#7514
[freeside.git] / httemplate / elements / select-cgp_rule_condition.html
1 % unless ( $opt{'js_only'} ) {
2   <% include( 'select.html',
3                 %opt,
4                 'options'  => \@conditions,
5                 'labels'   => { '' => 'Select Condition' },
6                 'onchange' => $key.'_changed',
7             )
8   %>
9   <% include( 'select.html',
10                 'name' => $opt{'field'}.'_op',
11                 'id'   => $key.'_op',
12                 'options' => \@op,
13                 #XXX curr op
14             )
15   %>
16   <% include( 'input-text.html',
17                 'name' => $opt{'field'}.'_params',
18                 'id'   => $key.'_params',
19                 #XXX curr value... anything else?
20             )
21   %>
22 % # could add more UI sugar for date/time ranges, string #lists, etc.
23 % }
24 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
25     <SCRIPT TYPE="text/javascript">
26 % }
27 % unless ( $opt{'html_only'} ) {
28
29       function opt(what,value,text) {
30         var optionName = new Option(text, value, false, false);
31         var length = what.length;
32         what.options[length] = optionName;
33       }
34
35       function <% $key %>_changed(what) {
36
37         <% $opt{'onchange'} %>
38
39         var <% $key %>_value = what.options[what.selectedIndex].value;
40         //alert ("condition changed to " + <% $key %>_value );
41
42         var op_Element = what.form.<% $key %>_op;
43         var params_Element = what.form.<% $key %>_params;
44
45         //cond2op in javascript... not as elegant cause my js << my perl
46
47         // if bool, hide/disable _op and _params entirely
48         if ( <%$key%>_value == '' || <%$key%>_value == 'Human Generated' ) {
49           op_Element.disabled = true;
50           op_Element.style.visibility = "hidden";
51           params_Element.disabled = true;
52           params_Element.style.visibility = "hidden";
53           return true;
54         }
55         
56         var OpArray = [ 'is', 'is not' ];
57
58         // if lt_ge, add em
59         if ( <%$key%>_value == 'Message Size' || <%$key%>_value == 'Time of Day' || <%$key%>_value == 'Current Date' ) {
60           OpArray.push('less than');
61           OpArray.push('greater than');
62         }
63
64         // unless no_in, add em
65         if ( <%$key%>_value != 'Message Size' && <%$key%>_value != 'Current Date' && <%$key%>_value != 'Existing Mailbox' ) {
66           OpArray.push('in');
67           OpArray.push('not in');
68         }
69
70         // blank the current op list
71         for ( var i = op_Element.length; i >= 0; i-- )
72           op_Element.options[i] = null;
73
74         // update the _op select with this new array
75         for ( var s = 0; s < OpArray.length; s++ )
76             opt(what.form.<% $key %>_op, OpArray[s], OpArray[s]);
77
78         // show _op and _params (in case we were a bool before)
79         op_Element.disabled = false;
80         op_Element.style.visibility = "visible";
81         params_Element.disabled = false;
82         params_Element.style.visibility = "visible";
83
84       }
85 % }
86 % unless ( $opt{'html_only'} || $opt{'js_only'} ) {
87     </SCRIPT>
88 % }
89 <%once>
90
91 my @conditions = (
92   '',
93
94   #generic http://www.communigate.com/CommunigatePro/Rules.html#Conditions
95   'Submit Address',
96   'Time of Day',
97   'Current Date',
98   'Current Day',
99   'Preference',
100   'FreeBusy',
101   'Existing Mailbox',
102
103   #email http://www.communigate.com/CommunigatePro/QueueRules.html#Conditions
104   'From',
105   'Sender',
106   'To',
107   'Cc',
108   'Reply-To',
109   'Any To or Cc',
110   'Each To or Cc',
111   'Return-Path',
112   "'From' Name",
113   'Subject',
114   'Message-ID',
115   'Message Size',
116   'Human Generated',
117   'Header Field',
118   'Any Recipient',
119   'Each Recipient',
120   'Source',
121   'Security',
122   'Any Route',
123   'Each Route'
124 );
125
126 my %bool = ( #hide the op and valud dropdowns entirely
127   '' => 1, #XXX hide _op and _params on "Select Condition"
128   'Human Generated' => 1,
129 );
130
131 my %no_in = ( #hide in/not in
132   'Message Size' => 1,
133   'Current Date' => 1,
134   'Existing Mailbox' => 1,
135 );
136
137 my %lt_gt = ( #add less than/greater than
138   'Message Size' => 1,
139   'Time of Day', => 1,
140   'Current Date', => 1,
141 );
142
143 my $cond2op = sub {
144   my $cond = shift;
145   return () if $bool{$cond}; 
146   my @op = ( 'is', 'is not' );
147   push @op, 'less than', 'greater than'  if $lt_gt{$cond};
148   push @op, 'in', 'not in' unless $no_in{$cond};
149   @op;
150 };
151
152 </%once>
153 <%init>
154
155 my %opt = @_;
156
157 my $key = $opt{'field'} || $opt{'id'};
158
159 #XXX curr value -> hidden op / param / param selects depending
160 #my @op = &$cond2op($curr_value);
161 my @op = &$cond2op();
162
163 </%init>