/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 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"); } }); }