when address standardization returns a censustract, don't try to look it up through...
authorMark Wells <mark@freeside.biz>
Tue, 2 Dec 2014 23:43:20 +0000 (15:43 -0800)
committerMark Wells <mark@freeside.biz>
Tue, 2 Dec 2014 23:43:20 +0000 (15:43 -0800)
httemplate/edit/cust_main/bottomfixup.js
httemplate/elements/location.html
httemplate/elements/standardize_locations.js
httemplate/misc/xmlhttp-address_standardize.html

index 8aef1e7..6a9deb9 100644 (file)
@@ -100,14 +100,13 @@ function copyelement(from, to) {
   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
 }
 
-% # the value in pre+'censustract' is the confirmed censustract; if it's set,
-% # and the user hasn't changed it manually, skip this
+% # 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 ( cf.elements[pre+'censustract'].value == '' ||
-         cf.elements[pre+'enter_censustract'].value != 
-         cf.elements[pre+'censustract'].value )
-  {
+  if ( cf.elements[pre+'censustract'].value == '' ) {
     var address_info = form_address_info();
     address_info[pre+'latitude']  = cf.elements[pre+'latitude'].value;
     address_info[pre+'longitude'] = cf.elements[pre+'longitude'].value;
index 5cdc424..214a7d5 100644 (file)
@@ -59,12 +59,7 @@ Example:
     </TR>
 
 % } else {
-
-    <INPUT TYPE     = "hidden"
-           NAME     = "<%$pre%>locationname"
-           ID       = "<%$pre%>locationname"
-           VALUE    = "<% $object->get('locationname') |h %>"
-    >
+    <& hidden.html, field => $pre.'locationname', value => $object->get('locationname') &>
 
 % }
 
@@ -102,10 +97,7 @@ Example:
 
 % } else { # alternate format
 
-      <INPUT TYPE  = "hidden"
-             NAME  = "<%$pre%>address2"
-             VALUE = "<% $object->get('address2') |h %>"
-      >
+<& hidden.html, field => $pre.'address2', value => $object->get('address2') &>
 
 <TR>
     <<%$th%> ALIGN="right">Unit&nbsp;type&nbsp;and&nbsp;#</<%$th%>>
@@ -227,14 +219,14 @@ Example:
 </TR>
 % } else {
 %   foreach (qw(latitude longitude)) {
-<INPUT TYPE="hidden" NAME="<% $_ %>" ID="<% $_ %>" VALUE="<% $object->get($_) |h%>">
+<& hidden.html, field => $pre.$_, value => $object->get($_) &>
 %   }
 % }
-<INPUT TYPE="hidden" NAME="<%$pre%>coord_auto" VALUE="<% $object->coord_auto %>">
-
-<INPUT TYPE="hidden" NAME="<%$pre%>geocode" VALUE="<% $object->geocode %>">
-<INPUT TYPE="hidden" NAME="<%$pre%>censustract" VALUE="<% $object->censustract %>">
-<INPUT TYPE="hidden" NAME="<%$pre%>censusyear" VALUE="<% $object->censusyear %>">
+%
+% foreach (qw(coord_auto geocode censustract censusyear)) {
+  <& hidden.html, field => $pre.$_, value => $object->get($_) &>
+% }
+%
 % if ( $opt{enable_censustract} ) {
 <TR>
   <TD ALIGN="right">Census&nbsp;tract</TD>
@@ -259,7 +251,7 @@ Example:
     </TD>
   </TR>
 % } else {
-    <INPUT TYPE="hidden" ID="<%$pre%>" NAME="<%$pre%>district" VALUE="<% $object->district %>">
+  <& hidden.html, field => $pre.'district', value => $object->get('district') &>
 % }
 
 %# For address standardization:
@@ -267,11 +259,11 @@ Example:
 %# to re-standardize
 % foreach (qw(address1 city state country zip latitude
 %             longitude censustract district addr_clean) ) {
-<INPUT TYPE="hidden" NAME="old_<%$pre.$_%>" ID="old_<%$pre.$_%>" VALUE="<% $object->get($_) |h%>">
+<& hidden.html, field => 'old_'.$pre.$_, value => $object->get($_) &>
 % }
 %# Placeholders
-<INPUT TYPE="hidden" NAME="<%$pre%>cachenum" VALUE="">
-<INPUT TYPE="hidden" NAME="<%$pre%>addr_clean" VALUE="">
+<& hidden.html, field => $pre.'cachenum', value => '' &>
+<& hidden.html, field => $pre.'addr_clean', value => '' &>
 
 <SCRIPT TYPE="text/javascript">
 <&| /elements/onload.js &>
@@ -306,6 +298,26 @@ Example:
       el.attachEvent('onchange', clear_coords);
     }
   }
+  function clear_censustract() {
+    // if the user manually edits the census tract, clear the 'hard' census
+    // tract field so that we can re-verify and present a confirmation popup 
+
+    // get the ID of the hidden censustract field
+    var censustract_id = this.id.replace('enter_', '');
+    var el = document.getElementById(censustract_id);
+    if (el) {
+      el.value = '';
+    }
+  }
+  var el = document.getElementById('<%$pre%>enter_censustract');
+  if (el) {
+    if ( el.addEventListener ) {
+      el.addEventListener('change', clear_censustract);
+    } else if ( el.attachEvent ) {
+      el.attachEvent('onchange', clear_censustract);
+    }
+  }
+
 </&>
 </SCRIPT>
 
index 307f822..f114e34 100644 (file)
@@ -282,10 +282,7 @@ function setselect(el, value) {
 function confirm_censustract() {
 %   if ( FS::Conf->new->exists('cust_main-require_censustract') ) {
   var form = document.<% $formname %>;
-  // this is the existing/confirmed censustract, not the manually entered one
-  if ( form.elements['censustract'].value == '' ||
-       form.elements['censustract'].value != 
-          form.elements['enter_censustract'].value ) {
+  if ( form.elements['censustract'].value == '' ) {
     var address_info = form_address_info();
     address_info['latitude']  = form.elements['latitude'].value;
     address_info['longitude'] = form.elements['longitude'].value;
index 6182653..d0255a0 100644 (file)
@@ -43,6 +43,10 @@ foreach my $pre ( @prefixes ) {
     last if !$all_same;
   }
 
+  $all_same = 0 if ( length( $old{$pre.'censustract'} ) > 0 &&
+                     length( $new{$pre.'censustract'} ) > 0 &&
+                     $old{$pre.'censustract'} ne $new{$pre.'censustract'} );
+
   $all_same = 0 if $new{$pre.'error'};
 }