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.
101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
|
|
function addPackage(address, latitude, longitude) {
|
|
packages.push({
|
|
"address": address,
|
|
"coords": [
|
|
latitude,
|
|
longitude
|
|
]
|
|
});
|
|
localStorage.setItem("packages", JSON.stringify(packages));
|
|
|
|
playSound("ok");
|
|
|
|
app.toast.show({
|
|
text: 'Package Added!<br><span style="font-size: 80%;">' + address + "</span>",
|
|
position: "bottom",
|
|
destroyOnClose: true,
|
|
closeTimeout: 1000 * 3
|
|
});
|
|
|
|
if (map != null) {
|
|
map.updatePackageLayer(packages);
|
|
}
|
|
}
|
|
|
|
$("#addpackagebtn").click(function () {
|
|
if ($("input[name=number]").val().trim() == "") {
|
|
playSound("error");
|
|
app.toast.show({
|
|
text: "Please fill in a street number.",
|
|
position: "bottom",
|
|
destroyOnClose: true,
|
|
closeTimeout: 1000 * 10
|
|
});
|
|
return;
|
|
}
|
|
if ($("input[name=street]").val().trim() == "") {
|
|
playSound("error");
|
|
app.toast.show({
|
|
text: "Please fill in a street name.",
|
|
position: "bottom",
|
|
destroyOnClose: true,
|
|
closeTimeout: 1000 * 10
|
|
});
|
|
return;
|
|
}
|
|
if ($("input[name=citystate]").val().trim() == "") {
|
|
playSound("error");
|
|
app.toast.show({
|
|
text: "Please fill in a city and state.",
|
|
position: "bottom",
|
|
destroyOnClose: true,
|
|
closeTimeout: 1000 * 10
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Save city/state if changed
|
|
if (localStorage.getItem("citystate") != $("input[name=citystate]").val().trim()) {
|
|
localStorage.setItem("citystate", $("input[name=citystate]").val().trim());
|
|
}
|
|
|
|
var address = ($("input[name=number]").val() + " " + $("input[name=street]").val()).toUpperCase();
|
|
$.getJSON(geocodeapi, {
|
|
address: address + " " + $("input[name=citystate]").val().toUpperCase()
|
|
}, function (resp) {
|
|
if (resp.status == "OK") {
|
|
if (resp.accuracy.ok) {
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1]);
|
|
} else {
|
|
playSound("error");
|
|
app.dialog.confirm(
|
|
"The address \"" + address + "\" couldn't be reliably located. Add it anyways?",
|
|
"Accuracy Warning",
|
|
function (ok) {
|
|
if (resp.address.street == "") {
|
|
addPackage(address, resp.coords[0], resp.coords[1]);
|
|
} else {
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1]);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
} else {
|
|
playSound("error");
|
|
app.dialog.alert(resp.message, "Error");
|
|
}
|
|
});
|
|
});
|
|
|
|
// Restore user's last entered city/state combo
|
|
if (localStorage.getItem("citystate") != null) {
|
|
$("input[name=citystate]").val(localStorage.getItem("citystate"));
|
|
} |