Add delivery alarm for express packages
This commit is contained in:
parent
384dac7b85
commit
c1f74e43fe
@ -82,10 +82,13 @@ function getMapIconForItems(items) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
function addPackage(address, latitude, longitude, type, callback) {
|
||||
function addPackage(address, latitude, longitude, type, callback, deadline) {
|
||||
var added = false;
|
||||
if (typeof type == 'undefined') {
|
||||
type = "package";
|
||||
type = SETTINGS.itemtypes[0].id;
|
||||
}
|
||||
if (typeof deadline == 'undefined') {
|
||||
deadline = false;
|
||||
}
|
||||
|
||||
var packageID = uuidv4();
|
||||
@ -98,6 +101,7 @@ function addPackage(address, latitude, longitude, type, callback) {
|
||||
address: address,
|
||||
delivered: false,
|
||||
type: type,
|
||||
deadline: deadline,
|
||||
id: packageID
|
||||
});
|
||||
added = true;
|
||||
@ -118,6 +122,7 @@ function addPackage(address, latitude, longitude, type, callback) {
|
||||
address: address,
|
||||
delivered: false,
|
||||
type: type,
|
||||
deadline: deadline,
|
||||
id: packageID
|
||||
}
|
||||
]
|
||||
@ -232,57 +237,149 @@ function countPackages() {
|
||||
function addPackageByAddress(address, citystate, type, callback) {
|
||||
var requestfinished = false;
|
||||
var searchingdialogopen = false;
|
||||
$.ajax({
|
||||
url: SETTINGS.geocodeapi,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
address: address + " " + citystate
|
||||
},
|
||||
timeout: 15 * 1000,
|
||||
success: function (resp) {
|
||||
if (searchingdialogopen) {
|
||||
app.dialog.close();
|
||||
searchingdialogopen = false;
|
||||
}
|
||||
requestfinished = true;
|
||||
if (resp.status == "OK") {
|
||||
if (resp.accuracy.ok) {
|
||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
||||
var deadline = false;
|
||||
|
||||
var ajaxlookup = function () {
|
||||
$.ajax({
|
||||
url: SETTINGS.geocodeapi,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
address: address + " " + citystate
|
||||
},
|
||||
timeout: 15 * 1000,
|
||||
success: function (resp) {
|
||||
if (searchingdialogopen) {
|
||||
app.dialog.close();
|
||||
searchingdialogopen = false;
|
||||
}
|
||||
requestfinished = true;
|
||||
if (resp.status == "OK") {
|
||||
if (resp.accuracy.ok) {
|
||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback, deadline);
|
||||
} 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], type, callback, deadline);
|
||||
} else {
|
||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback, deadline);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} 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], type, callback);
|
||||
} else {
|
||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
||||
}
|
||||
app.dialog.alert(resp.message, "Error");
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, errorThrown) {
|
||||
if (searchingdialogopen) {
|
||||
app.dialog.close();
|
||||
searchingdialogopen = false;
|
||||
}
|
||||
requestfinished = true;
|
||||
playSound("error");
|
||||
app.dialog.alert("There was a network issue while finding the address. Please try adding the item again.", "Error");
|
||||
}
|
||||
});
|
||||
|
||||
// Open a loading message if there's a delay finding the address
|
||||
setTimeout(function () {
|
||||
if (!requestfinished) {
|
||||
app.dialog.preloader("Searching for address...");
|
||||
searchingdialogopen = true;
|
||||
}
|
||||
}, 750);
|
||||
}
|
||||
|
||||
if (type == "express") {
|
||||
if (localStorage.getItem("deadlinealarm_minutes") == null) {
|
||||
localStorage.setItem("deadlinealarm_minutes", 20);
|
||||
}
|
||||
var minutes = localStorage.getItem("deadlinealarm_minutes");
|
||||
app.dialog.create({
|
||||
title: 'Express Item',
|
||||
text: 'Set a reminder for ' + minutes + ' minutes before:',
|
||||
buttons: [
|
||||
{
|
||||
text: '10:30 AM',
|
||||
close: true
|
||||
},
|
||||
{
|
||||
text: '12:00 PM',
|
||||
close: true
|
||||
},
|
||||
{
|
||||
text: '3:00 PM',
|
||||
close: true
|
||||
},
|
||||
{
|
||||
text: "No reminder",
|
||||
color: "red",
|
||||
close: true
|
||||
}
|
||||
],
|
||||
verticalButtons: true,
|
||||
onClick: function (dialog, index) {
|
||||
deadline = new Date();
|
||||
switch (index) {
|
||||
case 0:
|
||||
deadline.setMinutes(30);
|
||||
deadline.setHours(10);
|
||||
break;
|
||||
case 1:
|
||||
deadline.setMinutes(00);
|
||||
deadline.setHours(12);
|
||||
break;
|
||||
case 2:
|
||||
deadline.setMinutes(00);
|
||||
deadline.setHours(12 + 3);
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
deadline = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (deadline != false) {
|
||||
deadline = deadline.getTime() / 1000;
|
||||
}
|
||||
ajaxlookup();
|
||||
}
|
||||
}).open();
|
||||
} else {
|
||||
ajaxlookup();
|
||||
}
|
||||
}
|
||||
|
||||
function checkDeadlines() {
|
||||
if (localStorage.getItem("deadlinealarm_minutes") == null) {
|
||||
localStorage.setItem("deadlinealarm_minutes", 20);
|
||||
}
|
||||
var minutes = localStorage.getItem("deadlinealarm_minutes");
|
||||
var currentTime = new Date().getTime() / 1000;
|
||||
var deadlineTime = currentTime + (minutes * 60);
|
||||
for (i in packages) {
|
||||
for (j in packages[i].items) {
|
||||
var item = packages[i].items[j];
|
||||
if (typeof item.deadline != 'undefined' && item.deadline != false && item.delivered != true) {
|
||||
if ((typeof item.deadlinealarmed == 'undefined' || item.deadlinealarmed != true) && item.deadline <= deadlineTime) {
|
||||
playSound("alert");
|
||||
app.dialog.alert(
|
||||
"Item at " + item.address + " needs to be delivered by " + timestampToTimeString(item.deadline) + " (" + Math.floor((item.deadline - currentTime) / 60) + " minutes from now).",
|
||||
"Delivery Alarm",
|
||||
function () {
|
||||
|
||||
}
|
||||
);
|
||||
packages[i].items[j].deadlinealarmed = true;
|
||||
}
|
||||
} else {
|
||||
playSound("error");
|
||||
app.dialog.alert(resp.message, "Error");
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, errorThrown) {
|
||||
if (searchingdialogopen) {
|
||||
app.dialog.close();
|
||||
searchingdialogopen = false;
|
||||
}
|
||||
requestfinished = true;
|
||||
playSound("error");
|
||||
app.dialog.alert("There was a network issue while finding the address. Please try adding the item again.", "Error");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Open a loading message if there's a delay finding the address
|
||||
setTimeout(function () {
|
||||
if (!requestfinished) {
|
||||
app.dialog.preloader("Searching for address...");
|
||||
searchingdialogopen = true;
|
||||
}
|
||||
}, 750);
|
||||
}
|
||||
setInterval(checkDeadlines, 15 * 1000);
|
Loading…
x
Reference in New Issue
Block a user