From e70caae70c4f94d3ab0771a7277d71bc8919f671 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 23 Aug 2019 19:56:23 -0600 Subject: [PATCH] Warn user if package address isn't real --- www/assets/js/manage.js | 60 +++++++++++++++++++++++++++-------------- www/index.html | 4 +-- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/www/assets/js/manage.js b/www/assets/js/manage.js index 2147c59..528aafd 100644 --- a/www/assets/js/manage.js +++ b/www/assets/js/manage.js @@ -5,6 +5,30 @@ */ +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!
' + address + "", + position: "bottom", + destroyOnClose: true, + closeTimeout: 1000 * 3 + }); + + if (map != null) { + map.updatePackageLayer(packages); + } +} + $("#addpackagebtn").click(function () { if ($("input[name=number]").val().trim() == "") { playSound("error"); @@ -41,27 +65,23 @@ $("#addpackagebtn").click(function () { address: address + " " + $("input[name=citystate]").val().toUpperCase() }, function (resp) { if (resp.status == "OK") { - packages.push({ - "address": address, - "coords": [ - resp.coords[0], - resp.coords[1] - ] - }); - localStorage.setItem("packages", JSON.stringify(packages)); - - playSound("ok"); - - app.toast.show({ - text: 'Package Added!
' + address + "", - position: "bottom", - destroyOnClose: true, - closeTimeout: 1000 * 2 - }); - - if (map != null) { - map.updatePackageLayer(packages); + 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"); diff --git a/www/index.html b/www/index.html index b4c4978..e5448f1 100644 --- a/www/index.html +++ b/www/index.html @@ -20,9 +20,7 @@