566 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			566 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /*
 | |
|  * 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 localStorage.getItem("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
 | |
|                 }
 | |
|             });
 | |
|         }
 | |
|     },
 | |
|     {
 | |
|         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 (localStorage.getItem("scanevents") != null && localStorage.getItem("scanevents") != "[]") {
 | |
|                                 var entries = JSON.parse(localStorage.getItem("scanevents"));
 | |
|                                 for (i in entries) {
 | |
|                                     entries[i].event = entries[i].event.join(' <i class="fas fa-chevron-right"></i> ');
 | |
|                                 }
 | |
|                             } 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 = localStorage.getItem("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: '/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 (localStorage.getItem("username") != null && localStorage.getItem("password") != null) {
 | |
|                 var lastsync = localStorage.getItem("lastsync");
 | |
|                 if (lastsync == null) {
 | |
|                     lastsync = "never";
 | |
|                 } else {
 | |
|                     lastsync = timestampToDateTimeString(lastsync);
 | |
|                 }
 | |
|                 settings.push(
 | |
|                         {
 | |
|                             setting: "account",
 | |
|                             title: "Account",
 | |
|                             text: "Logged in as " + localStorage.getItem("username") + "<br>" + "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: localStorage.getItem("wakelock") == "true",
 | |
|                     onclick: ""
 | |
|                 });
 | |
|             }
 | |
| 
 | |
|             settings.push(
 | |
|                     {
 | |
|                         setting: "darktheme",
 | |
|                         title: "Use dark theme",
 | |
|                         text: "Saves power on phones with OLED screens.",
 | |
|                         toggle: true,
 | |
|                         checked: localStorage.getItem("darktheme") == "true",
 | |
|                         onclick: ""
 | |
|                     },
 | |
|                     {
 | |
|                         setting: "showhelp",
 | |
|                         title: "Show help",
 | |
|                         text: "Show the <span class=material-icons-intext><i class=material-icons>help</i></span> icons",
 | |
|                         toggle: true,
 | |
|                         checked: localStorage.getItem("show_help") != "false",
 | |
|                         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: localStorage.getItem("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: localStorage.getItem("alertvolume"),
 | |
|                             slider: true
 | |
|                         },
 | |
|                         {
 | |
|                             setting: "alertradius",
 | |
|                             title: "Alert radius (meters)",
 | |
|                             min: 50,
 | |
|                             max: 500,
 | |
|                             step: 50,
 | |
|                             value: localStorage.getItem("alertradius"),
 | |
|                             slider: true
 | |
|                         },
 | |
|                         {
 | |
|                             setting: "alertinterval",
 | |
|                             title: "Alert interval (seconds)",
 | |
|                             min: 15,
 | |
|                             max: 120,
 | |
|                             step: 15,
 | |
|                             value: localStorage.getItem("alertinterval") == null ? 30 : localStorage.getItem("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: localStorage.getItem("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: localStorage.getItem("units") == "metric"
 | |
|                                 },
 | |
|                                 {
 | |
|                                     value: "imperial",
 | |
|                                     label: "Feet/Miles",
 | |
|                                     selected: localStorage.getItem("units") == "imperial"
 | |
|                                 }
 | |
|                             ]
 | |
|                         },
 | |
|                         {
 | |
|                             setting: "trackzoom",
 | |
|                             title: "Zoom when tracking location",
 | |
|                             select: true,
 | |
|                             options: [
 | |
|                                 {
 | |
|                                     value: 15,
 | |
|                                     label: "Low",
 | |
|                                     selected: localStorage.getItem("trackzoom") == 15
 | |
|                                 },
 | |
|                                 {
 | |
|                                     value: 16,
 | |
|                                     label: "Normal",
 | |
|                                     selected: localStorage.getItem("trackzoom") == null || localStorage.getItem("trackzoom") == 16
 | |
|                                 },
 | |
|                                 {
 | |
|                                     value: 17,
 | |
|                                     label: "High",
 | |
|                                     selected: localStorage.getItem("trackzoom") == 17
 | |
|                                 }
 | |
|                             ]
 | |
|                         },
 | |
|                         {
 | |
|                             setting: "maptype",
 | |
|                             title: "Alternative map",
 | |
|                             text: "Turn this on if you have problems with the map.",
 | |
|                             toggle: true,
 | |
|                             checked: localStorage.getItem("maptype") == "leaflet",
 | |
|                             onclick: ""
 | |
|                         }
 | |
|                     ];
 | |
|                     resolve({
 | |
|                         templateUrl: './pages/settings.html'
 | |
|                     }, {
 | |
|                         context: {
 | |
|                             page_title: "Map Settings",
 | |
|                             settings: settings
 | |
|                         }
 | |
|                     });
 | |
|                 }
 | |
|             }
 | |
|         ]
 | |
|     }
 | |
| ];
 |