|
|
|
@ -25,6 +25,16 @@ function getUndeliveredCount(address) {
|
|
|
|
|
return undelivered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPackage(packageid) {
|
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
|
for (var j = 0; j < packages[i].items.length; j++) {
|
|
|
|
|
if (packages[i].items[j].id == packageid) {
|
|
|
|
|
return packages[i].items[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getIconForType(packagetype) {
|
|
|
|
|
switch (packagetype) {
|
|
|
|
|
case "package":
|
|
|
|
@ -76,37 +86,43 @@ function getMapIconForItems(items) {
|
|
|
|
|
return "multiple-items";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addPackage(address, latitude, longitude, type) {
|
|
|
|
|
function addPackage(address, latitude, longitude, type, callback) {
|
|
|
|
|
var added = false;
|
|
|
|
|
if (typeof type == 'undefined') {
|
|
|
|
|
type = "package";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var packageID = uuidv4();
|
|
|
|
|
var coordsID = "";
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
|
if (packages[i].coords[0] == latitude && packages[i].coords[1] == longitude && packages[i].address == address) {
|
|
|
|
|
coordsID = packages[i].id;
|
|
|
|
|
packages[i].items.push({
|
|
|
|
|
address: address,
|
|
|
|
|
delivered: false,
|
|
|
|
|
type: type,
|
|
|
|
|
id: uuidv4()
|
|
|
|
|
id: packageID
|
|
|
|
|
});
|
|
|
|
|
added = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!added) {
|
|
|
|
|
coordsID = uuidv4();
|
|
|
|
|
packages.push({
|
|
|
|
|
coords: [
|
|
|
|
|
latitude,
|
|
|
|
|
longitude
|
|
|
|
|
],
|
|
|
|
|
id: uuidv4(),
|
|
|
|
|
id: coordsID,
|
|
|
|
|
address: address,
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
address: address,
|
|
|
|
|
delivered: false,
|
|
|
|
|
type: type,
|
|
|
|
|
id: uuidv4()
|
|
|
|
|
id: packageID
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
@ -125,6 +141,13 @@ function addPackage(address, latitude, longitude, type) {
|
|
|
|
|
if (map != null) {
|
|
|
|
|
reloadMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
callback({
|
|
|
|
|
coordsID: coordsID,
|
|
|
|
|
packageID: packageID
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function markDelivered(id, delivered) {
|
|
|
|
@ -150,13 +173,13 @@ function markDelivered(id, delivered) {
|
|
|
|
|
localStorage.setItem("packages", JSON.stringify(packages));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function confirmDeletePackage(id) {
|
|
|
|
|
function confirmDeletePackage(package, callback) {
|
|
|
|
|
app.dialog.confirm(
|
|
|
|
|
"Delete package at " + packages[id].address + "?",
|
|
|
|
|
"Delete item at " + package.address + "?",
|
|
|
|
|
"Confirm",
|
|
|
|
|
function () {
|
|
|
|
|
// delete
|
|
|
|
|
deletePackage(id);
|
|
|
|
|
deletePackage(package.id, callback);
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
// cancel
|
|
|
|
@ -164,7 +187,7 @@ function confirmDeletePackage(id) {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deletePackage(id) {
|
|
|
|
|
function deletePackage(id, callback) {
|
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
|
for (var j = 0; j < packages[i].items.length; j++) {
|
|
|
|
|
if (packages[i].items[j].id == id) {
|
|
|
|
@ -176,6 +199,10 @@ function deletePackage(id) {
|
|
|
|
|
|
|
|
|
|
localStorage.setItem("packages", JSON.stringify(packages));
|
|
|
|
|
loadPackageList();
|
|
|
|
|
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
callback(id);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -204,13 +231,13 @@ function countPackages() {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addPackageByAddress(address, citystate, type) {
|
|
|
|
|
function addPackageByAddress(address, citystate, type, callback) {
|
|
|
|
|
$.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], type);
|
|
|
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
|
|
|
|
} else {
|
|
|
|
|
playSound("error");
|
|
|
|
|
app.dialog.confirm(
|
|
|
|
@ -218,9 +245,9 @@ function addPackageByAddress(address, citystate, type) {
|
|
|
|
|
"Accuracy Warning",
|
|
|
|
|
function (ok) {
|
|
|
|
|
if (resp.address.street == "") {
|
|
|
|
|
addPackage(address, resp.coords[0], resp.coords[1], type);
|
|
|
|
|
addPackage(address, resp.coords[0], resp.coords[1], type, callback);
|
|
|
|
|
} else {
|
|
|
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type);
|
|
|
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|