/* * 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 show_help = function () { return getStorage("show_help") != "false"; } var routes = [ { path: '/home', name: 'home', async: function (routeTo, routeFrom, resolve, reject) { var total = countPackages(); var undelivered = countRemainingPackages(); var delivered = total - undelivered; var percent = (total > 0 ? (delivered / total) : 1); resolve({ templateUrl: './pages/home.html' }, { context: { packageTotal: total, packageLeft: undelivered, packageDelivered: delivered, packagePercent: percent, oldui: inStorage("oldhomeui") && getStorage("oldhomeui") == "true", pages: [ { title: "Add Items", href: "/add", icon: "fas fa-truck-loading", bg: "add.svg" }, { title: "Item List", href: "/list", icon: "fas fa-list", bg: "list.svg" }, { title: "Delivery Map", href: "/map", icon: "fas fa-map", bg: "map.svg" }, { title: "Route Notes", href: "/myroute", icon: "fas fa-sticky-note", bg: "notes.svg" }, { title: "Toolbox", href: "/toolbox", icon: "fas fa-tools", bg: "toolbox.svg" }, { title: "Settings", href: "/settings", icon: "fas fa-cog", bg: "settings.svg" } ] } }); } }, { path: '/add', name: 'add', templateUrl: './pages/add.html', options: { context: { show_help: show_help, itemtypes: SETTINGS.itemtypes } }, on: { pageAfterIn: function () { setupStreetAutofill("#streetInput", "input[name=number]"); } } }, { path: '/list', name: 'list', templateUrl: './pages/list.html', options: { context: { show_help: show_help } }, on: { pageAfterIn: function () { loadPackageList(); searchbar = app.searchbar.create({ el: '.package-list-searchbar', searchContainer: '#addresslist', searchIn: '.item-title', backdrop: false, on: { search(sb, query, previousQuery) { console.log(query, previousQuery); } } }); } } }, { path: '/map', templateUrl: './pages/map.html', name: 'map', options: { context: { show_help: show_help } }, on: { pageAfterIn: function () { reloadMap(); } } }, { path: '/myroute', name: 'myroute', async: function (routeTo, routeFrom, resolve, reject) { var notes = false; if (inStorage("notes")) { notes = JSON.parse(getStorage("notes")); if (notes.length == 0) { notes = false; } } resolve({ templateUrl: './pages/myroute.html' }, { context: { notes: notes } }); }, on: { pageAfterIn: function () { notessearchbar = app.searchbar.create({ el: '.notes-list-searchbar', searchContainer: '#noteslist', searchIn: '.item-title', backdrop: false, on: { search(sb, query, previousQuery) { console.log(query, previousQuery); } } }); } }, routes: [ { path: '/addnote', on: { pageAfterIn: function () { setupStreetAutofill("input[name=street]", "input[name=number]"); } }, async: function (routeTo, routeFrom, resolve, reject) { var uuid = uuidv4(); resolve({ templateUrl: './pages/myroute/editnote.html' }, { context: { noteid: uuid, title: "Add Note", toggles: SETTINGS.routenotetoggles, note: { id: uuid, number: "", street: "", zipcode: inStorage("zipcode") ? getStorage("zipcode") : "", route: inStorage("lastrouteid") ? getStorage("lastrouteid") : "", notes: "", toggles: {} } } }); }, }, { path: '/editnote', templateUrl: './pages/myroute/editnote.html', on: { pageAfterIn: function () { setupStreetAutofill("input[name=street]", "input[name=number]"); } }, options: { context: { title: "Edit Note", toggles: SETTINGS.routenotetoggles } } } ] }, { path: '/login', templateUrl: './pages/login.html', name: 'login', options: { context: { loginurl: SETTINGS.loginurl } } }, { path: '/toolbox', url: './pages/toolbox.html', name: 'toolbox', routes: [ { path: '/scanner', templateUrl: './pages/toolbox/scanner.html', routes: [ { path: '/scanner', templateUrl: './pages/toolbox/scanner/scanner.html', name: 'scanner' }, { path: '/entries', name: 'entries', async: function (routeTo, routeFrom, resolve, reject) { if (getStorage("scanevents") != null && getStorage("scanevents") != "[]") { var entries = JSON.parse(getStorage("scanevents")); for (i in entries) { entries[i].event = entries[i].event.join(' '); } } else { var entries = false; } resolve({ templateUrl: './pages/toolbox/scanner/entries.html' }, { context: { entries: entries } }); }, on: { pageAfterIn: function () { $(".barcode_entry").each(function () { var code = $(this).data("barcode"); JsBarcode("#barcode_" + code, code, { format: "code128", ean128: true, width: 2, height: 40 }); }); } } } ] }, { path: '/track', name: 'track', async: function (routeTo, routeFrom, resolve, reject) { var history = getStorage("trackingcodehistory"); if (history == null) { history = false; } else { history = JSON.parse(history).reverse(); // Most recent on top } resolve({ templateUrl: './pages/toolbox/track.html' }, { context: { trackingcodehistory: history } }); }, routes: [ { path: '/info', templateUrl: './pages/toolbox/trackinginfo.html', name: 'trackinginfo' } ] }, { path: '/weather', url: './pages/toolbox/weather.html', name: 'weather', on: { pageAfterIn: function () { loadWeather(); } } }, { path: '/addrlookup', url: './pages/toolbox/addrlookup.html', name: 'addrlookup' }, { path: '/sharelist', url: './pages/toolbox/sharelist.html', name: 'sharelist' } ] }, { path: '/help', routes: [ { path: '/list', panel: { url: './pages/help/list.html' } }, { path: '/map', panel: { url: './pages/help/map.html' } } ] }, { path: '/credits', url: './pages/credits.html', name: 'credits' }, { path: '/settings', name: 'settings', async: function (routeTo, routeFrom, resolve, reject) { var settings = []; if (getStorage("username") != null && getStorage("password") != null) { var lastsync = getStorage("lastsync"); if (lastsync == null) { lastsync = "never"; } else { lastsync = timestampToDateTimeString(lastsync); } settings.push( { setting: "account", title: "Account", text: "Logged in as " + getStorage("username") + "
" + "Last sync: " + lastsync }, { setting: "syncnow", title: "", text: "Sync now", link: true, onclick: "resyncAndRestart()" }, { setting: "logout", title: "", text: "Log out", link: true, onclick: "logout()" }, ); } else { settings.push( { setting: "login", title: "Account", text: "Log in to backup and sync your settings and data.", onclick: "router.navigate('/login')", link: true } ); } settings.push( { setting: "alerts", title: "Package Alerts", text: "Change the alert sound, volume, and distance.", onclick: "router.navigate('/settings/alerts')", link: true }, { setting: "maps", title: "Map and Navigation", text: "Change map settings and units.", onclick: "router.navigate('/settings/maps')", link: true } ); if (platform_type == "cordova" && cordova.platformId != "browser") { settings.push({ setting: "wakelock", title: "Keep screen on", text: "Improves GPS accuracy and alert sound reliability, but uses more battery.", toggle: true, checked: getStorage("wakelock") == "true", onclick: "" }); } settings.push( { setting: "darktheme", title: "Use dark theme", text: "Saves power on phones with OLED screens.", toggle: true, checked: getStorage("darktheme") == "true", onclick: "" }, { setting: "showhelp", title: "Show help", text: "Show the help icons", toggle: true, checked: getStorage("show_help") != "false", onclick: "" }, { setting: "oldhomeui", title: "Show home screen as list", text: "Use a vertical list instead of tiles.", toggle: true, checked: getStorage("oldhomeui") == "true", onclick: "" }, { setting: "versions", title: "PackageHelper app v" + app_version, text: "Copyright © 2019-2020 Netsyms Technologies. Licensed under the Mozilla Public License 2.0.", onclick: "" }, { setting: "opensource", title: "Credits and open source info", text: "", onclick: "router.navigate('/credits')", link: true }, { setting: "privacy", title: "Privacy policy and legal", text: "", onclick: "openBrowser('https://netsyms.com/legal?pk_campaign=PackageHelperApp')", link: true }, { setting: "clearcache", title: "Clear Cache", text: "Delete saved maps and other temporary data", link: true, onclick: "clearCaches()" }); resolve({ templateUrl: './pages/settings.html' }, { context: { page_title: "Settings", settings: settings } }); }, routes: [ { path: '/alerts', name: 'settings', async: function (routeTo, routeFrom, resolve, reject) { var alertsounds = []; for (var id in SETTINGS.alertsounds) { if (SETTINGS.alertsounds.hasOwnProperty(id)) { alertsounds.push({ value: id, label: SETTINGS.alertsounds[id].name, selected: getStorage("alertsound") == id }); } } var settings = [ { setting: "alertsound", title: "Alert sound", text: "Select which sound to play when a package is nearby.", select: true, options: alertsounds }, { setting: "alertvolume", title: "Alert volume", min: 0, max: 100, step: 1, value: getStorage("alertvolume"), slider: true }, { setting: "alertradius", title: "Alert radius (meters)", min: 50, max: 500, step: 50, value: getStorage("alertradius"), slider: true }, { setting: "alertinterval", title: "Alert interval (seconds)", min: 15, max: 120, step: 15, value: getStorage("alertinterval") == null ? 30 : getStorage("alertinterval"), slider: true } ]; resolve({ templateUrl: './pages/settings.html' }, { context: { page_title: "Alert Settings", settings: settings } }); } }, { path: '/maps', name: 'settings', async: function (routeTo, routeFrom, resolve, reject) { var mapstyles = []; for (var id in SETTINGS.maptileurls) { if (SETTINGS.maptileurls.hasOwnProperty(id)) { mapstyles.push({ value: id, label: SETTINGS.maptileurls[id].name, selected: getStorage("mapsource") == id }); } } var settings = [ { setting: "mapsource", title: "Map style", select: true, options: mapstyles, text: "Choose which map style to use." }, { setting: "units", title: "Measurement units", select: true, options: [ { value: "metric", label: "Meters/Kilometers", selected: getStorage("units") == "metric" }, { value: "imperial", label: "Feet/Miles", selected: getStorage("units") == "imperial" } ] }, { setting: "trackzoom", title: "Zoom when tracking location", select: true, options: [ { value: 15, label: "Low", selected: getStorage("trackzoom") == 15 }, { value: 16, label: "Normal", selected: getStorage("trackzoom") == null || getStorage("trackzoom") == 16 }, { value: 17, label: "High", selected: getStorage("trackzoom") == 17 } ] }, { setting: "mapscale", title: "Map Scale Ruler", text: "Show a scale in the corner of the map.", toggle: true, checked: getStorage("mapscale") !== "false", onclick: "" }, { setting: "maptype", title: "Alternative map", text: "Turn this on if you have problems with the map.", toggle: true, checked: getStorage("maptype") == "leaflet", onclick: "" } ]; resolve({ templateUrl: './pages/settings.html' }, { context: { page_title: "Map Settings", settings: settings } }); } } ] } ];