X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fstandardize_locations.js;h=e98039d9d416a1c156a983979d828fe1e87ab806;hb=c6782ab85ea83e0c78d85b8975985aac9d467f9d;hp=d9c1df7e6f9173bccccac1061a6c5869376d0792;hpb=2bb7db96a07599e980323c1b6b23a8c79cc17a9a;p=freeside.git diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index d9c1df7e6..e98039d9d 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -1,8 +1,14 @@ +function status_message(text, caption) { + text = '

' + text + '

'; + caption = caption || 'Please wait...'; + overlib(text, WIDTH, 444, HEIGHT, 168, CAPTION, caption, STICKY, AUTOSTATUSCAP, CLOSECLICK, MIDX, 0, MIDY, 0); +} + function form_address_info() { var cf = document.<% $formname %>; - var returnobj = { onlyship: <% $onlyship ? 1 : 0 %> }; -% if ( !$onlyship ) { + var returnobj = { billship: <% $billship %> }; +% if ( $billship ) { returnobj['same'] = cf.elements['same'].checked; % } % if ( $withfirm ) { @@ -53,16 +59,12 @@ function standardize_locations() { cf.elements['<% $pre %>coord_auto'].value = 'Y'; changed = true; } - -% } #foreach $pre - // standardize if the old address wasn't clean - if ( cf.elements['old_ship_addr_clean'].value == '' || - cf.elements['old_bill_addr_clean'].value == '' ) { - + if ( cf.elements['<% $pre %>addr_clean'].value == '' ) { changed = true; - } +% } #foreach $pre + // or if it was clean but has been changed for (var key in address_info) { var old_el = cf.elements['old_'+key]; @@ -75,7 +77,7 @@ function standardize_locations() { % # If address hasn't been changed, auto-confirm the existing value of % # censustract so that we don't ask the user to confirm it again. - if ( !changed ) { + if ( !changed && <% $withcensus %> ) { if ( address_info['same'] ) { cf.elements['bill_censustract'].value = address_info['bill_censustract']; @@ -87,8 +89,7 @@ function standardize_locations() { % if ( $conf->config('address_standardize_method') ) { if ( changed ) { - var startup_msg = '

Verifying address...

'; - overlib(startup_msg, WIDTH, 444, HEIGHT, 168, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSECLICK, MIDX, 0, MIDY, 0); + status_message('Verifying address...'); address_standardize(JSON.stringify(address_info), confirm_standardize); } else { @@ -116,8 +117,14 @@ function confirm_standardize(arg) { replace_address(); // with the contents of returned['new'] - } - else { + } else if ( returned['all_same'] ) { + + // then all entered address fields are correct + // but we still need to set the lat/long fields and addr_clean + status_message('Verified'); + replace_address(); + + } else { var querystring = encodeURIComponent( JSON.stringify(returned) ); // confirmation popup: knows to call replace_address(), @@ -184,12 +191,14 @@ function post_standardization() { % if ( $conf->exists('enable_taxproducts') ) { + var cf = document.<% $formname %>; + if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 ) { var country_el = cf.elements['<% $taxpre %>country']; var country = country_el.options[ country_el.selectedIndex ].value; - var geocode = cf.elements['geocode'].value; + var geocode = cf.elements['bill_geocode'].value; if ( country == 'CA' || country == 'US' ) { @@ -211,14 +220,14 @@ function post_standardization() { } else { - cf.elements['geocode'].value = 'DEFAULT'; + cf.elements['bill_geocode'].value = 'DEFAULT'; <% $post_geocode %>; } } else { - cf.elements['geocode'].value = ''; + cf.elements['bill_geocode'].value = ''; <% $post_geocode %>; } @@ -243,14 +252,14 @@ function update_geocode() { cf.elements['<% $taxpre %>city'].value = argsHash['city']; setselect(cf.elements['<% $taxpre %>state'], argsHash['state']); cf.elements['<% $taxpre %>zip'].value = argsHash['zip']; - cf.elements['geocode'].value = argsHash['geocode']; + cf.elements['bill_geocode'].value = argsHash['geocode']; <% $post_geocode %>; } // popup a chooser - overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 ); + overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 ); } @@ -268,21 +277,18 @@ function setselect(el, value) { my %opt = @_; my $conf = new FS::Conf; -my $withfirm = 1; -my $withcensus = 1; +my $withfirm = $opt{'with_firm'} ? 1 : 0; +my $withcensus = $opt{'with_census'} ? 1 : 0; + +my @prefixes = ''; +my $billship = $opt{'billship'} ? 1 : 0; # whether to have bill_ and ship_ prefixes +my $taxpre = ''; +if ($billship) { + @prefixes = qw(bill_ ship_); + $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : 'bill_'; +} my $formname = $opt{form} || 'CustomerForm'; -my $onlyship = $opt{onlyship} || ''; -#my $main_prefix = $opt{main_prefix} || ''; -#my $ship_prefix = $opt{ship_prefix} || ($onlyship ? '' : 'ship_'); -# The prefixes are now 'ship_' and 'bill_'. -my $taxpre = 'bill_'; -$taxpre = 'ship_' if ( $conf->exists('tax-ship_address') || $onlyship ); my $post_geocode = $opt{callback} || 'post_geocode();'; -$withfirm = 0 if $opt{no_company}; -$withcensus = 0 if $opt{no_census}; - -my @prefixes = ('ship_'); -unshift @prefixes, 'bill_' unless $onlyship;