From 7e769d53f9b8378525e95df2ada7405e761adc83 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 20 May 2022 12:36:37 -0600 Subject: [PATCH] Add ZIP lookup tool to rate calculator --- www/assets/js/rates.js | 57 +++++++++++++++++++ www/pages/rates.html | 123 +++++++++++++++++++++++++++++++++++++++++ www/settings.js | 2 + 3 files changed, 182 insertions(+) diff --git a/www/assets/js/rates.js b/www/assets/js/rates.js index d28192c..c532dda 100644 --- a/www/assets/js/rates.js +++ b/www/assets/js/rates.js @@ -41,12 +41,14 @@ var itemTypeCharacteristics = { function updateRateForm() { if ($("#to_country").val() == "" || $("#to_country").val() == "US") { $(".citystateboxes").css("display", "none"); + $("#zipcodelookuplink").css("display", ""); $("#ziptext").html("ZIP Code"); $("#to_zip").attr("inputmode", "numeric"); $("#to_zip").attr("required", "true"); $("#to_zip").attr("placeholder", "ZIP Code"); } else { $(".citystateboxes").css("display", ""); + $("#zipcodelookuplink").css("display", "none"); $("#ziptext").html("Postal Code"); $("#to_zip").attr("inputmode", "text"); $("#to_zip").removeAttr("required"); @@ -150,4 +152,59 @@ function getRates() { sendErrorReport("Rates", "Couldn't get rates", "Server/network problem: " + xhr.status + ": " + xhr.statusText); } }, "GET"); +} + +function doZipCodeLookup(street, city, state) { + if (street == "") { + app.dialog.alert("You need to enter a street address.", "ZIP Code Lookup"); + return; + } + if (city == "") { + app.dialog.alert("You need to enter a city.", "ZIP Code Lookup"); + return; + } + if (state == "") { + app.dialog.alert("You need to select a state.", "ZIP Code Lookup"); + return; + } + + app.dialog.preloader("Searching..."); + + apirequest( + SETTINGS.apis.zipcodelookup, + { + street: street, + city: city, + state: state + }, + function (resp) { + app.dialog.close(); + if (resp.status == "OK") { + app.popup.close(); + $("#to_street1").val(resp.address.address); + $("#to_zip").val(resp.address.zip); + app.input.checkEmptyState('#to_street1'); + app.input.checkEmptyState('#to_zip'); + app.dialog.alert("The correct ZIP Code is " + resp.address.zip, "ZIP Code Lookup"); + } else { + app.dialog.alert(resp.msg, "Error"); + sendErrorReport("ZIP Lookup", "Couldn't get ZIP Code", resp.msg); + } + }, + function (xhr) { + app.dialog.close(); + try { + var error = $.parseJSON(xhr.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + sendErrorReport("ZIP Lookup", "Couldn't get ZIP Code", error.msg); + } else { + app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error"); + sendErrorReport("ZIP Lookup", "Couldn't get ZIP Code", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + } catch (ex) { + app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error"); + sendErrorReport("ZIP Lookup", "Couldn't get ZIP Code", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + }, "GET"); } \ No newline at end of file diff --git a/www/pages/rates.html b/www/pages/rates.html index 3752cc4..99d3153 100644 --- a/www/pages/rates.html +++ b/www/pages/rates.html @@ -69,6 +69,7 @@ + I don't know the ZIP Code