diff --git a/Site5/App_GlobalResources/GeographyNames.resx b/Site5/App_GlobalResources/GeographyNames.resx index e8e7068f..16e122a9 100644 --- a/Site5/App_GlobalResources/GeographyNames.resx +++ b/Site5/App_GlobalResources/GeographyNames.resx @@ -117,30 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Ascension Island - - - Andorra - - - Austria - - - Australia - - - Brazil - - - Germany - Denmark - - Spain - Finland @@ -150,24 +129,9 @@ Norway - - Poland - Sweden - - Slovak Republic - - - San Marino - - - United Kingdom - - - United States - Eastern Europe (East of southern tip of Sweden, appx) diff --git a/Site5/Automation/FieldValidation.aspx.cs b/Site5/Automation/FieldValidation.aspx.cs index 2af8dd52..fd0b4a5d 100644 --- a/Site5/Automation/FieldValidation.aspx.cs +++ b/Site5/Automation/FieldValidation.aspx.cs @@ -33,6 +33,7 @@ namespace Swarmops.Frontend.Automation List geographyArray = new List(); PostalCodes codes = PostalCodes.ForCountry(countryCode); Country country = Country.FromCode(countryCode); + int maxPostalCodeLength = 0; foreach (PostalCode code in codes) { @@ -42,6 +43,11 @@ namespace Swarmops.Frontend.Automation CityId = code.CityId }; + if (code.PostalCode.Length > maxPostalCodeLength) + { + maxPostalCodeLength = code.PostalCode.Length; + } + postalCodeArray.Add(dataPoint); } @@ -75,7 +81,8 @@ namespace Swarmops.Frontend.Automation PostalCodes = postalCodeArray.ToArray(), CityNames = cityArray.ToArray(), Geographies = geographyArray.ToArray(), - PostalCodeLength = country.PostalCodeLength + PostalCodeLength = country.PostalCodeLength, + PostalCodeLengthCheck = maxPostalCodeLength }; return result; @@ -118,4 +125,5 @@ public class PostalCodesCities public CityData[] CityNames { get; set; } public GeographyData[] Geographies { get; set; } public int PostalCodeLength; + public int PostalCodeLengthCheck; } \ No newline at end of file diff --git a/Site5/Pages/v5/Swarm/AddPerson.aspx b/Site5/Pages/v5/Swarm/AddPerson.aspx index 73c6623e..fb884bd4 100644 --- a/Site5/Pages/v5/Swarm/AddPerson.aspx +++ b/Site5/Pages/v5/Swarm/AddPerson.aspx @@ -8,32 +8,68 @@ $('#<%=this.TextPostal.ClientID%>').on('input', function() { if (CheckPostalCode()) { - $('#<%=this.TextDateOfBirth.ClientID%>').focus(); + if ($('#<%=this.TextPostal.ClientID%>').val().length == postalCodeLength) { + $('#<%=this.TextDateOfBirth.ClientID%>').focus(); + } } }); + $('#<%=this.TextCity.ClientID%>').on('input', function () { + CheckPostalCity(); + }); }); + function CheckPostalCity() { + var currentCity = $('#<%=this.TextCity.ClientID%>').val().toLowerCase(); + if (currentCity in cityNameLookup) { + var geoId = cityNameLookup[currentCity]; + $('#spanDetectedGeo').text(geographyIdLookup[geoId]); + } else { + $('#spanDetectedGeo').text(''); + } + } + function CheckPostalCode() { - var currentPostalCode = $('#<%=this.TextPostal.ClientID%>').val(); + var currentPostalCode = $('#<%=this.TextPostal.ClientID%>').val().toLowerCase(); + if (currentPostalCode.length > postalCodeLengthCheck) { + currentPostalCode = currentPostalCode.substring(0, postalCodeLengthCheck); + } if (currentPostalCode in postalCodeLookup) { var cityId = postalCodeLookup[currentPostalCode]; - $('#<%=this.TextCity.ClientID%>').attr("disabled", "disabled").val(cityNameLookup[cityId].Name); - $('#spanDetectedGeo').text(geographyNameLookup[cityNameLookup[cityId].GeoId]); + $('#<%=this.TextCity.ClientID%>').attr("disabled", "disabled").val(cityIdLookup[cityId].Name); + $('#spanDetectedGeo').text(geographyIdLookup[cityIdLookup[cityId].GeoId]); + postalCodeIdentified = true; return true; - } else { + } else if (postalCodeIdentified) { $('#<%=this.TextCity.ClientID%>').removeAttr("disabled").val(''); $('#spanDetectedGeo').text(''); + postalCodeIdentified = false; } return false; } function AnimatePostalCodeLength() { - var postalTargetLength = postalCodeLength * 15 - 5; - var cityTargetLength = 235 - 15 * postalCodeLength; + if (postalCodeLength > 0) { + var postalTargetLength = postalCodeLength * 15 - 5; + var cityTargetLength = 235 - 15 * postalCodeLength; - $('#<%=this.TextPostal.ClientID%>').animate({ width: postalTargetLength + "px" }); - $('#<%=this.TextCity.ClientID%>').animate({ width: cityTargetLength + "px" }); + $('#<%=this.TextPostal.ClientID%>').animate({ width: postalTargetLength + "px" }); + $('#<%=this.TextCity.ClientID%>').animate({ width: cityTargetLength + "px" }); + if (!postalCodeVisible) { + setTimeout(function() { + $('#<%=this.TextPostal.ClientID%>').fadeIn(200); + }, 100); + postalCodeVisible = true; + } + + } else if (postalCodeVisible) { + // Remove postal code altogether, if visible now + + $('#<%=this.TextPostal.ClientID%>').animate({ width: 0 }, 200).fadeOut(100); + $('#<%=this.TextCity.ClientID%>').animate({ width: "255px" }, 600); + + postalCodeVisible = false; + } } function UpdatePostalPrefix(oldValue, newValue) { @@ -54,20 +90,24 @@ dataType: "json", success: function (msg) { postalCodeLookup = {}; + cityIdLookup = {}; cityNameLookup = {}; - geographyNameLookup = {}; + geographyIdLookup = {}; postalCodeLength = msg.d.PostalCodeLength; + postalCodeLengthCheck = msg.d.PostalCodeLengthCheck; + $('#<%=TextPostal.ClientID%>').attr('maxlength', postalCodeLength); msg.d.PostalCodes.forEach(function (element, index, array) { - postalCodeLookup[element.Code] = element.CityId; + postalCodeLookup[element.Code.toLowerCase()] = element.CityId; }); msg.d.CityNames.forEach(function(element, index, array) { - cityNameLookup[element.Id] = {}; - cityNameLookup[element.Id].Name = element.Name; - cityNameLookup[element.Id].GeoId = element.GeographyId; + cityIdLookup[element.Id] = {}; + cityIdLookup[element.Id].Name = element.Name; + cityIdLookup[element.Id].GeoId = element.GeographyId; + cityNameLookup[element.Name.toLowerCase()] = element.GeographyId; }); msg.d.Geographies.forEach(function(element, index, array) { - geographyNameLookup[element.Id] = element.Name; + geographyIdLookup[element.Id] = element.Name; }); AnimatePostalCodeLength(); @@ -75,17 +115,22 @@ }, error: function (msg) { console.log(msg); - geographyNameLookup = {}; + geographyIdLookup = {}; postalCodeLookup = {}; + cityIdLookup = {}; cityNameLookup = {}; } }); } var postalCodeLookup = {}; + var cityIdLookup = {}; var cityNameLookup = {}; - var geographyNameLookup = {}; + var geographyIdLookup = {}; var postalCodeLength = 0; + var postalCodeLengthCheck = 0; + var postalCodeVisible = true; + var postalCodeIdentified = false; @@ -109,14 +154,14 @@ ​