You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HelenaExpressApp/www/routes.js

401 lines
16 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 routes = [
{
path: '/home',
name: 'home',
on: {
pageBeforeIn: function () {
// make sure it's not shown right after account setup
var accountsetup = (inStorage("accountkey") && inStorage("phonenumber"));
if (accountsetup) {
$("#finishaccountsetupnag").css("display", "none");
}
}
},
async: function (routeTo, routeFrom, resolve, reject) {
// Show a nag message if no account is set up
var accountsetup = (inStorage("accountkey") && inStorage("phonenumber"));
resolve({
templateUrl: './pages/home.html'
}, {
context: {
accountsetup: accountsetup,
pages: [
{
title: "Drop and Send",
href: "/dropandsend",
icon: "fad fa-box-alt",
text: "Bring your package to a secure drop location and we'll ship it for you. No postage or appointment needed."
},
{
title: "Book Appointment",
href: "/appointment",
icon: "fad fa-calendar-alt",
text: "Get mailing, shipping, and notary services on your schedule anywhere in the Helena area."
},
{
title: "My Account",
href: "/account",
icon: "fad fa-user-circle",
text: "Manage your Helena Express account and check rewards points balance."
},
// {
// title: "Track Package",
// href: "/track",
// icon: "fad fa-search",
// text: "Find the latest location and updates about any shipment."
// },
// {
// title: "Get Rates",
// href: "/rates",
// icon: "fad fa-calculator",
// text: "Calculate postage and prices for your item."
// },
// {
// title: "Express Pickup",
// href: "/addresscode",
// icon: "fal fa-qrcode",
// text: "Get a faster pickup and a discount by pre-typing the destination address here."
// },
// {
// title: "Pick Up and Redeliver",
// href: "/noticeslip",
// icon: "fad fa-sticky-note",
// text: "Take a picture of your pink postal notice slip and we'll go get your missed delivery."
// }
]
}
});
}
},
{
path: '/appointment',
name: 'appointment',
async: function (routeTo, routeFrom, resolve, reject) {
resolve({
templateUrl: './pages/appointment.html'
}, {
context: {
services: [
{
title: "Package Pickup",
text: "A courier will come to you and ship your mail, packages, etc.",
icon: "fad fa-hand-holding-box",
serviceid: 19
},
{
title: "Mobile Notary",
text: "A notary public will come to you and notarize your documents.",
icon: "fad fa-file-signature",
serviceid: 21
}
]
}
});
},
routes: [
{
path: "/:serviceId",
async: function (routeTo, routeFrom, resolve, reject) {
var url = SETTINGS.appointmenturl;
if ($("#app").hasClass("theme-dark")) {
url = SETTINGS.appointmenturl_darkmode;
}
resolve({
templateUrl: './pages/appointment.html'
}, {
context: {
url: url + "&service=" + routeTo.params.serviceId
}
});
}
}
]
},
{
path: '/dropandsend',
name: 'dropandsend',
templateUrl: './pages/dropandsend.html',
on: {
pageAfterIn: function () {
var mapboxel = document.getElementById("mapbox-dropboxes");
dropboxMap = new MapControl(mapboxel, true);
dropboxMap.reloadMap();
dropboxMap.mapObj.on('load', function () {
dropboxMap.mapObj.jumpTo({center: [-112.005, 46.589], zoom: 8});
dropboxMap.loadIcon("./assets/images/dropbox-icon.png", "dropbox", function () {
apirequest(SETTINGS.apis.dropandsendlocations, {}, function (data) {
dropboxMap.loadMarkersFromGeoJson(data, "dropbox", "dropbox");
dropboxMap.mapObj.on('click', 'marker-layer-dropbox', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var name = e.features[0].properties.name;
var type = e.features[0].properties.type;
var info = e.features[0].properties.info;
var hours = e.features[0].properties.hours;
var geolink = "geo:" + (Math.round(coordinates[1] * 1000000) / 1000000) + "," + (Math.round(coordinates[0] * 1000000) / 1000000);
var typedesc = "<i class='fas fa-question-circle'></i> Unknown package size limits";
switch (type) {
case "micro":
typedesc = "<i class='fas fa-envelope'></i> Fits envelopes";
break;
case "mini":
typedesc = "<i class='fas fa-mail-bulk'></i> Fits large envelopes and small packages";
break;
case "standard":
typedesc = "<i class='fas fa-box-alt'></i> Fits up to medium-size packages";
break;
case "large":
typedesc = "<i class='fas fa-boxes-alt'></i> Fits most packages";
break;
case "business":
typedesc = "<i class='fas fa-store-alt'></i> Shipping location, accepts any size package";
break;
}
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML("<b>" + name + "</b><br>" + typedesc
+ "<br><b>Hours:</b><br>" + hours
+ "<br><b>More Info:</b><br>" + info
+ "<br><a class=\"button button-fill button-small\" href=\"" + geolink + "\"><i class=\"fas fa-location-circle\"></i> Directions</a>")
.addTo(dropboxMap.mapObj);
});
dropboxMap.mapObj.on('mouseenter', 'marker-layer-dropbox', function () {
dropboxMap.mapObj.getCanvas().style.cursor = 'pointer';
});
dropboxMap.mapObj.on('mouseleave', 'marker-layer-dropbox', function () {
dropboxMap.mapObj.getCanvas().style.cursor = '';
});
dropboxMap.animateMapIn(46.589, -112.005, 9, 0);
}, function (error) {
}, "GET");
});
});
}
}
},
{
path: '/track',
url: './pages/track.html',
name: 'track',
on: {
pageBeforeIn: function () {
addTrackingSuggestions();
$("#trackingcode").val("0");
app.input.validate("#trackingcode");
$("#trackingcode").val("");
}
}
},
{
path: '/rates',
url: './pages/rates.html',
name: 'rates',
on: {
pageAfterIn: function () {
initRateForm();
}
}
},
{
path: '/rateresult',
name: 'rateresult',
templateUrl: './pages/rateresult.html'
},
{
path: '/noticeslip',
url: './pages/noticeslip.html',
name: 'noticeslip',
on: {
pageAfterIn: function () {
initNoticeSlipForm();
}
}
},
{
path: '/noticeslip/success',
name: 'noticeslipsuccess',
templateUrl: './pages/noticeslipsuccess.html'
},
{
path: '/addresscode',
name: 'addresscode',
async: function (routeTo, routeFrom, resolve, reject) {
resolve({
templateUrl: './pages/addresscode.html'
}, {
context: {
fields: [
{label: "Name", id: "name"},
{label: "Company", id: "company"},
{label: "Street", id: "street1"},
{label: "Street (line 2)", id: "street2"},
{label: "City", id: "city"},
{label: "State", id: "state"},
{label: "ZIP", id: "zip"}
]
}
});
}
},
{
path: '/account',
name: 'account',
templateUrl: './pages/account.html',
on: {
pageAfterIn: function () {
initAccountPage();
}
},
routes: [
{
path: '/managepayment',
name: 'managepayment',
templateUrl: './pages/managepayment.html'
}
]
},
{
path: '/track/:code',
name: 'trackresult',
async: trackOpenAsync,
on: {
pageAfterIn: function () {
var mapboxel = document.getElementById("mapbox-track");
var trackingMap = new MapControl(mapboxel, false);
trackingMap.reloadMap();
var latitude = $(mapboxel).data("latitude");
var longitude = $(mapboxel).data("longitude");
var accurate = $(mapboxel).data("accurate") == true;
trackingMap.clearMarkersAndCenterMapOnNewMarker("package-marker", latitude, longitude, accurate);
}
}
},
{
path: '/credits',
url: './pages/credits.html',
name: 'credits'
},
{
path: '/settings',
name: 'settings',
async: function (routeTo, routeFrom, resolve, reject) {
var settings = [];
settings.push(
{
setting: "display",
title: "Display and Appearance",
text: "",
onclick: "router.navigate('/settings/display')",
link: true
}
);
settings.push(
{
setting: "versions",
title: "Helena Express app v" + app_version,
text: "Copyright &copy; 2019-2021 Netsyms Technologies.",
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?mtm_campaign=HelenaExpressApp')",
link: true
});
resolve({
templateUrl: './pages/settings.html'
}, {
context: {
page_title: "Settings",
settings: settings
}
});
},
routes: [
{
path: '/display',
name: 'settings',
async: function (routeTo, routeFrom, resolve, reject) {
var settings = [
{
setting: "apptheme",
title: "Color theme",
select: true,
options: [
{
value: "auto",
label: "Auto",
selected: getStorage("apptheme") == null || getStorage("apptheme") == "auto"
},
{
value: "dark",
label: "Dark",
selected: getStorage("apptheme") == "dark"
},
{
value: "light",
label: "Light",
selected: getStorage("apptheme") == "light"
}
]
},
{
setting: "animation",
title: "Animations",
select: true,
options: [
{
value: "auto",
label: "On",
selected: getStorage("animation") == null || getStorage("animation") == "auto" || getStorage("animation") == "on"
},
// {
// value: "on",
// label: "On",
// selected: getStorage("animation") == "on"
// },
{
value: "off",
label: "Off",
selected: getStorage("animation") == "off"
}
]
}
];
resolve({
templateUrl: './pages/settings.html'
}, {
context: {
page_title: "Display Settings",
settings: settings
}
});
}
}
]
}
];