X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fselect-cgp_rule_condition.html;h=bc96ab48774cfe6b1b21a354d1b74629d6ac4341;hb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;hp=1ce85bdb63c117edd28da2c00d514d14d7c6ace5;hpb=6874a21f3cb26a167e49cc1324df30119c6ed75d;p=freeside.git
diff --git a/httemplate/elements/select-cgp_rule_condition.html b/httemplate/elements/select-cgp_rule_condition.html
index 1ce85bdb6..bc96ab487 100644
--- a/httemplate/elements/select-cgp_rule_condition.html
+++ b/httemplate/elements/select-cgp_rule_condition.html
@@ -1,26 +1,121 @@
-<% include( 'select.html',
- %opt,
- 'options' => \@conditions, #reverse order if we ever need to spec
- 'labels' => { '' => 'Select Condition' },
- )
-%>
-<% include( 'select.html',
- 'name' => $opt{'field'}.'_op',
- 'id' => ($opt{'field'}||$opt{'id'}).'_op',
- 'options' => \@myop,
- )
-%>
-<% include( 'input-text.html',
- 'name' => $opt{'field'}.'_params',
- #XXX curr value... anything else?
- )
-%>
-<%init>
+% unless ( $opt{'js_only'} ) {
-my %opt = @_;
+
+
+ <% include( 'select.html',
+ 'field' => $name.'_conditionname',
+ 'id' => $id.'_conditionname',
+ 'options' => \@conditions,
+ 'curr_value' => $conditionname,
+ 'labels' => { '' => 'Select Condition' },
+ 'onchange' => $name.'_changed',
+ )
+ %>
+
+ <% include( 'select.html',
+ 'field' => $name.'_op',
+ 'id' => $id.'_op',
+ 'options' => \@op,
+ 'curr_value' => scalar($cgi->param($name.'_op'))
+ || $cgp_rule_condition->op,
+ 'disabled' => $disabled,
+ 'style' => $style,
+ )
+ %>
+
+ <% include( 'input-text.html',
+ 'field' => $name.'_params',
+ 'id' => $id.'_params',
+ 'curr_value' => scalar($cgi->param($name.'_params'))
+ || $cgp_rule_condition->params,
+ 'disabled' => $disabled,
+ 'style' => $style,
+ 'nodarken_disabled' => 1,
+ )
+ %>
+
+% # could add more UI sugar for date/time ranges, string #lists, etc.
+
+% }
+% unless ( $opt{'html_only'} || $opt{'js_only'} ) {
+
+% }
+<%once>
my @conditions = (
'',
+
+ #generic http://www.communigate.com/CommunigatePro/Rules.html#Conditions
+ 'Submit Address',
+ 'Time of Day',
+ 'Current Date',
+ 'Current Day',
+ 'Preference',
+ 'FreeBusy',
+ 'Existing Mailbox',
+
+ #email http://www.communigate.com/CommunigatePro/QueueRules.html#Conditions
'From',
'Sender',
'To',
@@ -43,21 +138,63 @@ my @conditions = (
'Each Route'
);
-my %bool = (
- 'Human Generated' => 1,
-);
+my %bool = ( map { $_=>1 } ( #hide the op and valud dropdowns entirely
+ '',
+ 'Human Generated',
+));
-my %number = (
- 'Message Size' => 1,
-);
+my %no_in = ( map { $_=>1 } ( #hide in/not in
+ 'Message Size',
+ 'Current Date',
+ 'Existing Mailbox',
+));
+
+my %lt_gt = ( map { $_=>1 } ( #add less than/greater than
+ 'Message Size',
+ 'Time of Day',
+ 'Current Date',
+));
+
+my $cond2op = sub {
+ my $cond = shift;
+ return () if $bool{$cond};
+ my @op = ( 'is', 'is not' );
+ push @op, 'less than', 'greater than' if $lt_gt{$cond};
+ push @op, 'in', 'not in' unless $no_in{$cond};
+ @op;
+};
+
+%once>
+<%init>
+
+my %opt = @_;
+
+my $name = $opt{'element_name'} || $opt{'field'} || 'ruleconditionnum';
+#my $id = $opt{'id'} || 'contactnum';
+my $id = $opt{'id'} || $opt{'field'} || 'ruleconditionnum';
+
+my $curr_value = $opt{'curr_value'} || $opt{'value'};
+
+my $onchange = '';
+if ( $opt{'onchange'} ) {
+ $onchange = $opt{'onchange'};
+ $onchange .= '(what)' unless $onchange =~ /\(\w*\);?$/;
+}
+
+my $cgp_rule_condition;
+if ( $curr_value ) {
+ $cgp_rule_condition = qsearchs('cgp_rule_condition',
+ { 'ruleconditionnum' => $curr_value } );
+} else {
+ $cgp_rule_condition = new FS::cgp_rule_condition {};
+}
-#XXX curr value -> hidden op / param / param selects depending
+my $conditionname = scalar($cgi->param($name.'_conditionname'))
+ || $cgp_rule_condition->conditionname;
-my @op = ( 'is', 'is not', 'in', 'not in' );
-my @op_number = ( 'is', 'is_not', 'less than', 'greater than' );
+my @op = &$cond2op($conditionname);
-my @myop = @op; #XXX $number{$curr_value} ? @op_number : @op;
-#XXX and a fancy onchange handler... yes.
-#XXX (and for total hiding of the %bool one)
+my $disabled = scalar(@op) ? '' : 1;
+my $style = $disabled ? 'visibility:hidden' : '';
%init>