forked from Netsyms/PackageHelper
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.2 KiB
JavaScript
79 lines
3.2 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
|
|
function addressLookup() {
|
|
if ($("#numberstreetinput").val() == "") {
|
|
app.dialog.alert("A street address is required.", "Not enough info");
|
|
return;
|
|
}
|
|
if ($("#cityinput").val() == "" || $("#stateinput").val() == "") {
|
|
var ziprequired = true;
|
|
}
|
|
if ($("#zipcodeinput").val() == "" && ziprequired) {
|
|
app.dialog.alert("A ZIP code or city and state are required.", "Not enough info");
|
|
}
|
|
app.dialog.preloader("Working...");
|
|
var addrlookupdialogopen = true;
|
|
$.ajax({
|
|
url: SETTINGS.addrlookupapi,
|
|
dataType: 'json',
|
|
method: 'post',
|
|
data: {
|
|
"street": $("#numberstreetinput").val(),
|
|
"unit": $("#unitinput").val(),
|
|
"city": $("#cityinput").val(),
|
|
"state": $("#stateinput").val(),
|
|
"zip": $("#zipcodeinput").val()
|
|
},
|
|
timeout: 15 * 1000,
|
|
success: function (resp) {
|
|
if (addrlookupdialogopen) {
|
|
app.dialog.close();
|
|
addrlookupdialogopen = false;
|
|
}
|
|
if (resp.status == "OK") {
|
|
if (resp.address.status == "OK") {
|
|
var address = resp.address;
|
|
$(".item-text #address").text(address.address);
|
|
var zipstr = "";
|
|
if (address.zip != "") {
|
|
zipstr = address.zip;
|
|
}
|
|
if (address.plus4 != "") {
|
|
zipstr += "-" + address.plus4;
|
|
}
|
|
$(".item-text #citystate").text(address.city + " " + address.state + " " + zipstr);
|
|
|
|
$(".item-text #dp").text(address.delivery_point);
|
|
$(".item-text #route").text(address.route);
|
|
$(".item-text #county").text(address.county);
|
|
$(".item-text #dpvconfirmed").text(address.dpv_confirmed ? "Yes" : "No");
|
|
$(".addrresult").removeClass("display-none");
|
|
} else {
|
|
$(".addrresult").addClass("display-none");
|
|
app.dialog.alert(resp.address.message, "Error");
|
|
}
|
|
if (resp.geocode.status == "OK") {
|
|
$(".georesult").removeClass("display-none");
|
|
$(".item-text #geocoords").text(resp.geocode.latitude + ", " + resp.geocode.longitude);
|
|
$(".item-text #geocoords").attr("src", "geo:" + resp.geocode.latitude + "," + resp.geocode.longitude);
|
|
} else {
|
|
$(".georesult").addClass("display-none");
|
|
}
|
|
} else {
|
|
app.dialog.alert(resp.message, "Error");
|
|
}
|
|
},
|
|
error: function (jqXHR, status, errorThrown) {
|
|
if (addrlookupdialogopen) {
|
|
app.dialog.close();
|
|
addrlookupdialogopen = false;
|
|
}
|
|
app.dialog.alert("There was a network or server issue. Please try again.", "Error");
|
|
}
|
|
});
|
|
} |