X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fcust_main%2Fbottomfixup.js;h=97816aad76dfa5011be474523feb5a5d18a048dd;hb=ecf1c9cc0a20be6e489657e005ea771977b9f69c;hp=ae4aafb701fff27fee2da65b8409a4e6dd9091e2;hpb=5f675c352a10f555de5831bb76ab00b35b6b9bd1;p=freeside.git diff --git a/httemplate/edit/cust_main/bottomfixup.js b/httemplate/edit/cust_main/bottomfixup.js index ae4aafb70..97816aad7 100644 --- a/httemplate/edit/cust_main/bottomfixup.js +++ b/httemplate/edit/cust_main/bottomfixup.js @@ -1,281 +1,131 @@ -function bottomfixup(what) { - - var layervars = new Array( - 'payauto', - 'payinfo', 'payinfo1', 'payinfo2', 'paytype', - 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv', - 'paystart_month', 'paystart_year', 'payissue', - 'payip', - 'paid' - ); - - var cf = document.CustomerForm; - var payby = cf.payby.options[cf.payby.selectedIndex].value; - for ( f=0; f < layervars.length; f++ ) { - var field = layervars[f]; - copyelement( cf.elements[payby + '_' + field], - cf.elements[field] - ); - } - - //this part does USPS address correction - - // XXX should this be first and should we update the form fields that are - // displayed??? - - var cf = document.CustomerForm; +<%init> +my %opt = @_; # custnum +my $conf = new FS::Conf; - var state_el = cf.elements['state']; - var ship_state_el = cf.elements['ship_state']; +my $company_latitude = $conf->config('company_latitude'); +my $company_longitude = $conf->config('company_longitude'); - //address_standardize( - var cust_main = new Array( - 'company', cf.elements['company'].value, - 'address1', cf.elements['address1'].value, - 'address2', cf.elements['address2'].value, - 'city', cf.elements['city'].value, - 'state', state_el.options[ state_el.selectedIndex ].value, - 'zip', cf.elements['zip'].value, +my @fixups = ('standardize_locations'); - 'ship_company', cf.elements['ship_company'].value, - 'ship_address1', cf.elements['ship_address1'].value, - 'ship_address2', cf.elements['ship_address2'].value, - 'ship_city', cf.elements['ship_city'].value, - 'ship_state', ship_state_el.options[ ship_state_el.selectedIndex ].value, - 'ship_zip', cf.elements['ship_zip'].value - ); +push @fixups, 'confirm_censustract_bill', 'confirm_censustract_ship' + if $conf->exists('cust_main-require_censustract'); - address_standardize( cust_main, update_address ); +my $uniqueness = $conf->config('cust_main-check_unique'); +push @fixups, 'check_unique' + if $uniqueness and !$opt{'custnum'}; +push @fixups, 'do_submit'; # always last +%init> +var fixups = <% encode_json(\@fixups) %>; +var fixup_position; +var running = false; + +<&| /elements/onload.js &> +submit_abort(); +&> + +%# state machine to deal with all the asynchronous stuff we're doing +%# call this after each fixup on success: +function submit_continue() { + if ( running ) { + window[ fixups[fixup_position++] ].call(); + } } -var standardize_address; - -function update_address(arg) { - - var argsHash = eval('(' + arg + ')'); - - var changed = argsHash['address_standardized']; - var ship_changed = argsHash['ship_address_standardized']; - var error = argsHash['error']; - var ship_error = argsHash['ship_error']; - - - //yay closures - standardize_address = function () { - - var cf = document.CustomerForm; - var state_el = cf.elements['state']; - var ship_state_el = cf.elements['ship_state']; - - if ( changed ) { - cf.elements['company'].value = argsHash['new_company']; - cf.elements['address1'].value = argsHash['new_address1']; - cf.elements['address2'].value = argsHash['new_address2']; - cf.elements['city'].value = argsHash['new_city']; - setselect(cf.elements['state'], argsHash['new_state']); - cf.elements['zip'].value = argsHash['new_zip']; - } +%# or on failure: +function submit_abort() { + running = false; + fixup_position = 0; + document.CustomerForm.submitButton.disabled = false; + cClick(); +} - if ( ship_changed ) { - cf.elements['ship_company'].value = argsHash['new_ship_company']; - cf.elements['ship_address1'].value = argsHash['new_ship_address1']; - cf.elements['ship_address2'].value = argsHash['new_ship_address2']; - cf.elements['ship_city'].value = argsHash['new_ship_city']; - setselect(cf.elements['ship_state'], argsHash['new_ship_state']); - cf.elements['ship_zip'].value = argsHash['new_ship_zip']; - } +function bottomfixup(what) { + fixup_position = 0; + document.CustomerForm.submitButton.disabled = true; + running = true; + submit_continue(); +} - } +function do_submit() { + document.CustomerForm.submit(); +} +<& /elements/standardize_locations.js, + 'callback' => 'submit_continue();', + 'billship' => 1, + 'with_census' => 1, # no with_firm, apparently +&> + +% # the value in pre+'censustract' is the confirmed censustract (either from +% # the previous saved record, or from address standardization (if the backend +% # supports it), or from an aborted previous submit. only need to reconfirm +% # if it's empty. +function confirm_censustract(pre) { var cf = document.CustomerForm; - -% if ( $conf->exists('enable_taxproducts') ) { - - if ( <% $taxpre %>error || - new String(argsHash['new_<% $taxpre %>zip']).length < 10 ) - { - - var country_el = cf.elements['<% $taxpre %>country']; - var country = country_el.options[ country_el.selectedIndex ].value; - - if ( country == 'CA' || country == 'US' ) { - - var state_el = cf.elements['<% $taxpre %>state']; - var state = state_el.options[ state_el.selectedIndex ].value; - - var url = "cust_main/choose_tax_location.html" + - "?data_vendor=cch-zip" + - ";city=" + cf.elements['<% $taxpre %>city'].value + - ";state=" + state + - ";zip=" + cf.elements['<% $taxpre %>zip'].value + - ";country=" + country + - ";"; - - // popup a chooser - OLgetAJAX( url, update_geocode, 300 ); - - } else { - - cf.elements['geocode'].value = 'DEFAULT'; - cf.submit(); - - } - - } else - -% } - - if ( changed || ship_changed ) { - -% if ( $conf->exists('cust_main-auto_standardize_address') ) { - - standardize_address(); - cf.submit(); - -% } else { - - // popup a confirmation popup - - var confirm_change = - '
Entered billing address | ' + - 'Standardized billing address |
---|---|
' + argsHash['company'] + - ' | ' + argsHash['new_company'] + ' |
' + argsHash['address1'] + - ' | ' + argsHash['new_address1'] + ' |
' + argsHash['address2'] + - ' | ' + argsHash['new_address2'] + ' |
' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] + - ' | ' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + ' |
Entered service address | ' + - 'Standardized service address |
' + argsHash['ship_company'] + - ' | ' + argsHash['new_ship_company'] + ' |
' + argsHash['ship_address1'] + - ' | ' + argsHash['new_ship_address1'] + ' |
' + argsHash['ship_address2'] + - ' | ' + argsHash['new_ship_address2'] + ' |
' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] + - ' | ' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + ' |
' + - '' + - ' | ' + - '' + - ' |
' + - ' |