From efac4a4045b9311fc68bbca284919d24bb1a3c2e Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 8 Oct 2007 21:06:30 +0000 Subject: [PATCH] add cust_bill_owed as an implicit condition (whew), and make sure it is added on migrations (also: fixed implicit conditions like this which only apply to a subset of eventtables) --- FS/FS/part_event/Condition/cust_bill_owed.pm | 6 ++ bin/freeside-migrate-events | 7 ++ httemplate/edit/part_event.html | 95 ++++++++++++++++++++-------- 3 files changed, 80 insertions(+), 28 deletions(-) diff --git a/FS/FS/part_event/Condition/cust_bill_owed.pm b/FS/FS/part_event/Condition/cust_bill_owed.pm index e90d3db28..5e582ef69 100644 --- a/FS/FS/part_event/Condition/cust_bill_owed.pm +++ b/FS/FS/part_event/Condition/cust_bill_owed.pm @@ -16,6 +16,12 @@ sub eventtable_hashref { }; } +sub implicit_flag { 30; } + +sub remove_warning { + 'Are you sure you want to remove this condition? Doing so will allow this event to run even for invoices which have no outstanding balance. Perhaps you want to reset "Amount owed over" to 0 instead of removing the condition entirely?'; #better error msg? +} + sub option_fields { ( 'owed' => { 'label' => 'Amount owed over', diff --git a/bin/freeside-migrate-events b/bin/freeside-migrate-events index f33a0ad0e..76643b886 100644 --- a/bin/freeside-migrate-events +++ b/bin/freeside-migrate-events @@ -94,6 +94,13 @@ foreach my $part_bill_event ( $error = $balance->insert( 'balance' => 0 ); die $error if $error; + my $cust_bill_owed = new FS::part_event_condition { + 'eventpart' => $part_event->eventpart, + 'conditionname' => 'cust_bill_owed' + }; + $error = $cust_bill_owed->insert( 'owed' => 0 ); + die $error if $error; + my $payby = new FS::part_event_condition { 'eventpart' => $part_event->eventpart, 'conditionname' => 'payby' diff --git a/httemplate/edit/part_event.html b/httemplate/edit/part_event.html index c94da615d..5b14edfa7 100644 --- a/httemplate/edit/part_event.html +++ b/httemplate/edit/part_event.html @@ -93,6 +93,9 @@ % } var eventtable = what.options[what.selectedIndex].value; +% if ( $JS_DEBUG ) { + alert ("eventtable: " + eventtable); +% } var eventdesc = what.options[what.selectedIndex].text; //remove the ** Select type ** @@ -101,7 +104,7 @@ } //// - // XXX gray out conditions that can't apply? + // XXX gray out conditions that can't apply (in addition to the warning)? //// //// @@ -129,23 +132,33 @@ % } warning.style.display = 'none'; - if ( ! seen_condition && conditionname != '') { + if ( ! seen_condition && conditionname != '' ) { // add the current (not valid) condition back opt(cond_select, conditionname, cond_desc, true ); - if ( true <% @implicit_conditions - ? ( ' && '. join(' && ', map { "conditionname != '$_'" } - @implicit_conditions - ) - ) - : '' - %> ) { + if ( ! condition_is_implicit(conditionname) ) { + cond_select.parentNode.parentNode.style.display = ''; + cond_select.disabled = ''; // turn on a warning and gray out the condition row % if ( $JS_DEBUG ) { alert('turning on warning; setting style.display of '+ cond_id + - '_warning (' + warning + ') to none'); + '_warning (' + warning + ') to ""'); % } warning.innerHTML = 'Not applicable to ' + eventdesc + ' events'; warning.style.display = ''; + } else { + if ( ! condition_in_eventtable(conditionname) ) { +% if ( $JS_DEBUG ) { + alert(conditionname + " not in " + eventtable + "; disabling"); +% } + cond_select.parentNode.parentNode.style.display = 'none'; + cond_select.disabled = 'disabled'; + } else { +% if ( $JS_DEBUG ) { + alert(conditionname + " implicit for " + eventtable + "; enabling"); +% } + cond_select.parentNode.parentNode.style.display = ''; + cond_select.disabled = ''; + } } } @@ -320,6 +333,30 @@ if ( add_condname.length == 0 ) return; + var in_eventtable = condition_in_eventtable(add_condname); + + if ( ! in_eventtable ) return; + + for ( var cnum=0; document.getElementById('conditionname'+cnum); cnum++ ) { + if ( cnum == curnum ) continue; + + var cond_id = 'conditionname' + cnum; + var cond_select = document.getElementById(cond_id); + + if ( cond_select.disabled ) continue; + + //alert("adding " + add_condname + " to " + cond_id); + + opt(cond_select, add_condname, add_conddesc, false ); + + cond_select.parentNode.parentNode.style.display = ''; + + } + + } + + function condition_in_eventtable(condname) { + var eventtable_el = document.getElementById('eventtable'); var eventtable = eventtable_el.options[eventtable_el.selectedIndex].value; @@ -332,10 +369,8 @@ if ( eventtable == '<% $eventtable %>' ) { % foreach my $conditionname ( keys %conditions ) { -% my $description = $conditions{$conditionname}->{'description'}; -% $description =~ s/'/\\'/g; - if ( add_condname == '<% $conditionname %>' ) { + if ( condname == '<% $conditionname %>' ) { in_eventtable = true; } @@ -345,24 +380,23 @@ % } - if ( ! in_eventtable ) return; - - for ( var cnum=0; document.getElementById('conditionname'+cnum); cnum++ ) { - if ( cnum == curnum ) continue; - - var cond_id = 'conditionname' + cnum; - var cond_select = document.getElementById(cond_id); - - if ( cond_select.disabled ) continue; - - //alert("adding " + add_condname + " to " + cond_id); + return in_eventtable; - opt(cond_select, add_condname, add_conddesc, false ); + } - cond_select.parentNode.parentNode.style.display = ''; + function condition_is_implicit(condname) { + if ( true <% @implicit_conditions + ? ( ' && '. join(' && ', map { "condname != '$_'" } + @implicit_conditions + ) + ) + : '' + %> ) { + return false; + } else { + return true; } - } function condition_repop(cond_select) { @@ -375,7 +409,10 @@ var cond_desc = cond_select.options[cond_select.selectedIndex].text; var seen_condition = false; - if ( cond_select.disabled ) return false; //skip deleted conditions + //skip deleted conditions + if ( cond_select.disabled && conditionname != '' && ! condition_is_implicit(conditionname) ) { + return false; + } var field_regex = /(\d+)$/; var match = field_regex.exec(cond_select.name); @@ -423,9 +460,11 @@ if ( cond_select.length > 1 || cond_select.length == 1 && cond_select.options[0].value.length > 0 ) { cond_select.parentNode.parentNode.style.display = ''; + cond_select.disabled = ''; } else { cond_select.parentNode.parentNode.style.display = 'none'; + cond_select.disabled = 'disabled'; } return seen_condition; -- 2.11.0