diff --git a/www/assets/js/track.js b/www/assets/js/track.js index 5e2f726..b3b18bb 100644 --- a/www/assets/js/track.js +++ b/www/assets/js/track.js @@ -17,7 +17,7 @@ function addTrackingSuggestions() { $("#tracking-history-list ul").html(""); var history = getTrackingHistory(); if (history == false || history.length == 0) { - $("#tracking-history-list ul").html('
  • You haven\'t tracked anything yet.
  • '); + $("#tracking-history-list ul").html('
  • You haven\'t tracked anything yet.
  • '); } else { for (var i = history.length - 1; i >= 0; i--) { $("#tracking-history-list ul").append('
  • ' @@ -57,6 +57,65 @@ function addTrackingSuggestions() { } else { $("#tracking-account-list ul").html('
  • '); } + + var codes = getTrackingMultiList(); + if (codes.length > 0) { + $("#tracking-multi-list ul").html('
  • Loading...
  • '); + // Only update if we're on that tab, since it's not the easiest API call for the server to do + if ($("#tracking-multi-list").hasClass("tab-active")) { + updateTrackingMultiListStatus(); + } + } else { + $("#tracking-multi-list ul").html('
  • Quickly see the latest status for multiple packages at the same time right here. Long-pressRight-click a tracking code in the Recent tab to add it.
  • '); + } +} + +function updateTrackingMultiListStatus() { + var codes = getTrackingMultiList(); + console.log(codes.length); + $("#tracking-multi-list ul").html('
  • Loading...
  • '); + if (codes.length > 0) { + $("#tracking-multi-list ul").html(""); + for (var i = 0; i < codes.length; i++) { + $("#tracking-multi-list ul").append('
  • '); + } + apirequest(SETTINGS.apis.trackmultiple, { + code: codes.join(",") + }, function (resp) { + if (resp.status == "OK") { + for (const code in resp.results) { + $(".tracking-code-multi-link[data-trackingcode=\"" + code + "\"] .tracking-multi-status-text").text(resp.results[code].text); + $(".tracking-code-multi-link[data-trackingcode=\"" + code + "\"] .tracking-multi-status-icon").attr("src", "./assets/images/icons/" + resp.results[code].icon + ".svg"); + } + + $("#tracking-multi-list ul").append('
  •  Long-pressRight-click an entry to remove it.
  • '); + } else { + $("#tracking-multi-list ul").html('
  • Error: ' + resp.msg + '
  • '); + sendErrorReport("Tracking", "Couldn't get multi tracking", resp.msg); + } + }, function (xhr) { + try { + var resp = $.parseJSON(xhr.responseText); + if (resp && typeof resp.msg != 'undefined') { + $("#tracking-multi-list ul").html('
  • Error: ' + resp.msg + '
  • '); + sendErrorReport("Tracking", "Couldn't get multi tracking", resp.msg); + } else { + $("#tracking-multi-list ul").html('
  • There\'s a server or network problem. Check your Internet connection or try again later.
  • '); + sendErrorReport("Tracking", "Couldn't get multi tracking", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + } catch (ex) { + $("#tracking-multi-list ul").html('
  • There\'s a server or network problem. Check your Internet connection or try again later.
  • '); + sendErrorReport("Tracking", "Couldn't get multi tracking", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + }); + + } else { + $("#tracking-multi-list ul").html('
  • Quickly see the latest status for multiple packages at the same time right here. Long-press or right click a tracking code in the Recent tab to add it.
  • '); + } } function openTrackingBarcodeScanner() { @@ -191,7 +250,14 @@ $("#app").on("contextmenu", ".tracking-code-history-link", function (evt) { } }, { - text: 'Remove From List', + text: 'Add to Multi list', + onClick: function () { + addToTrackingMultiList(code); + addTrackingSuggestions(); + } + }, + { + text: 'Remove From History', onClick: function () { removeFromTrackingHistory(code); addTrackingSuggestions(); @@ -211,6 +277,44 @@ $("#app").on("contextmenu", ".tracking-code-history-link", function (evt) { return false; }); +$("#app").on("contextmenu", ".tracking-code-multi-link", function (evt) { + var code = $(this).data("trackingcode"); + + var action = app.actions.create({ + buttons: [ + [ + { + text: 'Track', + bold: true, + onClick: function () { + openTrackingInfoPage(code); + } + }, + { + text: 'Remove from list', + onClick: function () { + removeFromTrackingMultiList(code); + addTrackingSuggestions(); + } + } + ], + [ + { + text: 'Cancel', + color: 'red' + } + ] + ] + }); + + action.open(); + return false; +}); + +$("#app").on("tab:show", "#tracking-multi-list", function (evt) { + updateTrackingMultiListStatus(); +}); + function getTrackingHistory() { var history = getStorage("trackinghistory"); if (history == "false" || history == "null" || history == null) { @@ -252,4 +356,48 @@ function removeFromTrackingHistory(code) { setStorage("trackinghistory", JSON.stringify(history)); $(".tracking-code-history-link[data-trackingcode=\"" + code + "\"]").parent("li").remove(); +} + + +function getTrackingMultiList() { + var history = getStorage("multitrackingcodes"); + if (history == "false" || history == "null" || history == null) { + return []; + } else { + return JSON.parse(history); + } +} + +function addToTrackingMultiList(code) { + var history = getTrackingMultiList(); + + for (var i = 0; i < history.length; i++) { + if (history[i] == code) { + history.splice(i, 1); + } + } + // Add the code back to the list so it's at the top + history.push(code); + + while (history.length > 10) { + history.shift(); + } + setStorage("multitrackingcodes", JSON.stringify(history)); +} + +function removeFromTrackingMultiList(code) { + var history = getTrackingMultiList(); + + for (var i = 0; i < history.length; i++) { + if (history[i] == code) { + history.splice(i, 1); + } + } + + while (history.length > 10) { + history.shift(); + } + setStorage("multitrackingcodes", JSON.stringify(history)); + + $(".tracking-code-multi-link[data-trackingcode=\"" + code + "\"]").parent("li").remove(); } \ No newline at end of file diff --git a/www/pages/track.html b/www/pages/track.html index 01cb913..ad61148 100644 --- a/www/pages/track.html +++ b/www/pages/track.html @@ -53,6 +53,10 @@ From Me
    + + + Multi +
    @@ -75,6 +79,17 @@
    +
    +
    + +
    +
    diff --git a/www/settings.js b/www/settings.js index 255ad2c..9365a53 100644 --- a/www/settings.js +++ b/www/settings.js @@ -7,6 +7,7 @@ var SETTINGS = { apis: { track: "http://localhost/helena.express/apis/track/", + trackmultiple: "http://localhost/helena.express/apis/trackmultiple/", rates: "http://localhost/helena.express/apis/rates/", appointmentredirect: "http://localhost/helena.express/apis/appointmentredirect/", requestpickup: "http://localhost/helena.express/apis/requestpickup/",