diff --git a/www/assets/images/history-dashed.svg b/www/assets/images/history-dashed.svg new file mode 100644 index 0000000..e691902 --- /dev/null +++ b/www/assets/images/history-dashed.svg @@ -0,0 +1,2 @@ + + diff --git a/www/assets/js/list.js b/www/assets/js/list.js index 872b69e..a184305 100644 --- a/www/assets/js/list.js +++ b/www/assets/js/list.js @@ -141,10 +141,12 @@ function loadPackageList(sortType) { } // If there was a search open when the reload was triggered - var searchboxVal = $(".package-list-searchbar input[type=search]").val(); - if (searchboxVal != "") { - searchbar.clear(); - searchbar.search(searchboxVal); + if (router.currentRoute.name == "list") { + var searchboxVal = $(".package-list-searchbar input[type=search]").val(); + if (searchboxVal != "") { + searchbar.clear(); + searchbar.search(searchboxVal); + } } } diff --git a/www/assets/js/manage.js b/www/assets/js/manage.js index b9fd8c2..38695ce 100644 --- a/www/assets/js/manage.js +++ b/www/assets/js/manage.js @@ -42,7 +42,36 @@ $("#addpackagebtn").click(function () { } var address = ($("input[name=number]").val() + " " + $("input[name=street]").val()).toUpperCase(); - addPackageByAddress(address, $("input[name=citystate]").val().toUpperCase(), $("input[name=itemtype]:checked").val()); + $("#no-history").addClass("display-none"); + addPackageByAddress(address, $("input[name=citystate]").val().toUpperCase(), $("input[name=itemtype]:checked").val(), function (ids) { + var packageObj = getPackage(ids.packageID); + $("#historylist").prepend('
  • ' + + '
    ' + + ' ' + + '
    ' + + '
    ' + + '
    ' + + ' ' + packageObj.address + + '
    ' + + '
    ' + + '
  • '); + }); +}); + +// Remove any pre-existing click handlers from the history list, +// otherwise the user will see a number of confirm prompts equal to the number +// of times they've opened the manage page +$(".view-main").off("click", "#historylist .history-list-item"); + +$(".view-main").on("click", "#historylist .history-list-item", function () { + console.log("Asking to delete ", $(this).data("package")); + confirmDeletePackage(getPackage($(this).data("package")), function (id) { + console.log("Removing history item", id); + $('#historylist .history-list-item[data-package="' + id + '"]').remove(); + if ($('#historylist .history-list-item').length == 0) { + $("#no-history").removeClass("display-none"); + } + }); }); // Restore user's last entered city/state combo diff --git a/www/assets/js/packages.js b/www/assets/js/packages.js index ee1e5b9..87e97c3 100644 --- a/www/assets/js/packages.js +++ b/www/assets/js/packages.js @@ -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); } } ); diff --git a/www/pages/list.html b/www/pages/list.html index 7fb9627..80b696e 100644 --- a/www/pages/list.html +++ b/www/pages/list.html @@ -40,12 +40,11 @@
    -
    -
    -
    - +
    +
    + Add + Recent +
    +
    + +
    +
    +
    +
    +
      +
    • Address
    • +
    • +
      +
      Address Number
      +
      + + +
      +
      +
    • +
    • +
      +
      Street
      +
      + + +
      +
      +
    • +
    • +
      +
      City, State, ZIP
      +
      + +
      +
      +
    • +
    • Item Type
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    +
    +
    + +
    +
    + +
    No recently added items! Swipe to add some.
    +
    +
      + +
    +