/* * 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/. */ function openTrackingInfoPage(id) { router.navigate("/track/" + id); } function trackOpenAsync(routeTo, routeFrom, resolve, reject) { app.dialog.preloader("Loading..."); apirequest( SETTINGS.apis.track, { id: routeTo.params.id, format: "json" }, function (resp) { app.dialog.close(); if (resp.status == "ERROR") { app.dialog.alert(resp.msg, "Error"); reject(); } else { addToTrackingHistory(resp.id); var context = {}; context.info = resp.info; context.events = resp.events; context.components = resp.components; resolve({ templateUrl: "pages/trackresult.html", }, { context: context }); } }, function (xhr) { app.dialog.close(); var error = $.parseJSON(xhr.responseText); if (error && typeof error.msg != 'undefined') { app.dialog.alert(error.msg, "Error"); } else { app.dialog.alert("A server or network error occurred.", "Error"); } reject(); }, "GET"); } function getTrackingHistory() { var history = getStorage("trackhistory"); if (history != null) { return JSON.parse(history); } else { return []; } } function addToTrackingHistory(id) { var history = getTrackingHistory(); for (var i = 0; i < history.length; i++) { if (history[i] == id) { history.splice(i, 1); } } // Add the code back to the list so it's at the top history.push(id); while (history.length > 10) { history.shift(); } setStorage("trackhistory", JSON.stringify(history)); }