|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var packages = [];
|
|
|
|
|
|
|
|
if (localStorage.getItem("packages") != null) {
|
|
|
|
packages = JSON.parse(localStorage.getItem("packages"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirmDeletePackage(id) {
|
|
|
|
app.dialog.confirm(
|
|
|
|
"Delete package at " + packages[id].address + "?",
|
|
|
|
"Confirm",
|
|
|
|
function () {
|
|
|
|
// delete
|
|
|
|
deletePackage(id);
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
// cancel
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePackage(id) {
|
|
|
|
packages.splice(id, 1);
|
|
|
|
localStorage.setItem("packages", JSON.stringify(packages));
|
|
|
|
loadPackageList();
|
|
|
|
}
|
|
|
|
|
|
|
|
function countRemainingPackages() {
|
|
|
|
var undelivered = 0;
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
if (packages[i].delivered != true) {
|
|
|
|
undelivered++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undelivered;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPackageByAddress(address, citystate) {
|
|
|
|
$.getJSON(SETTINGS.geocodeapi, {
|
|
|
|
address: address + " " + citystate
|
|
|
|
}, 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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|