HelenaExpressApp/www/routes.js

464 lines
17 KiB
JavaScript
Raw Normal View History

2020-10-10 19:26:30 -06:00
/*
* 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/.
*/
2021-10-02 14:34:53 -06:00
var compiledPages = {};
var pagesToCompile = [
"home",
2022-01-12 12:32:53 -07:00
"send",
2021-10-02 14:34:53 -06:00
"welcome",
"appointment",
"dropandsend",
2021-10-19 20:07:44 -06:00
"pickup",
2022-01-19 15:33:40 -07:00
"shop",
"shoppingcart_fragment",
2021-10-02 14:34:53 -06:00
"rateresult",
"account",
"trackresult",
2022-02-01 19:52:22 -07:00
"settings",
"receipts"
2021-10-02 14:34:53 -06:00
];
console.log("Compiling page templates...");
for (var i = 0; i < pagesToCompile.length; i++) {
compiledPages[pagesToCompile[i]] = Template7.compile($.ajax({
type: "GET",
url: "./pages/" + pagesToCompile[i] + ".html",
async: false
}).responseText);
}
console.log("Compiled page templates.");
2020-10-10 19:26:30 -06:00
var routes = [
{
path: '/welcome',
2021-10-03 00:14:31 -06:00
content: compiledPages.welcome(),
name: 'welcome',
on: {
pageAfterIn: function () {
}
}
},
2020-10-10 19:26:30 -06:00
{
path: '/home',
name: 'home',
alias: ["/"],
on: {
pageBeforeIn: function () {
// make sure it's not shown right after account setup
2021-10-19 20:07:44 -06:00
var accountsetup = (inStorage("accountkey") && inStorage("accountnumber"));
if (accountsetup) {
$("#finishaccountsetupnag").css("display", "none");
}
}
},
2021-10-02 14:34:53 -06:00
async: function ( { resolve, reject }) {
// Show a nag message if no account is set up
2021-10-19 20:07:44 -06:00
var accountsetup = (inStorage("accountkey") && inStorage("accountnumber")) || getStorage("hideaccountnag") == "true";
// add escape hatch to regular website if running online
var escapehatch = false;
if (window.location.hostname == "app.helena.express") {
escapehatch = true;
}
2020-10-10 19:26:30 -06:00
resolve({
2021-10-02 14:34:53 -06:00
content: compiledPages.home({
accountsetup: accountsetup,
escapehatch: escapehatch,
2020-10-10 19:26:30 -06:00
pages: [
2021-10-19 20:07:44 -06:00
{
2022-01-12 12:32:53 -07:00
title: "Send a Package",
href: "/send",
2021-10-19 20:07:44 -06:00
icon: "fad fa-boxes",
2022-01-12 12:32:53 -07:00
text: "Find a drop box or schedule a pickup."
2021-10-19 20:07:44 -06:00
},
{
2022-01-12 12:32:53 -07:00
title: "Notarize a Document",
2022-01-19 15:33:40 -07:00
href: "/appointment/notary",
2022-01-12 12:32:53 -07:00
icon: "fad fa-file-signature",
text: "Book a mobile notary visit."
2020-10-10 19:26:30 -06:00
},
{
2022-01-19 15:33:40 -07:00
title: "Write a Telegram",
2021-12-18 18:31:04 -07:00
href: "/telegram",
icon: "fad fa-typewriter",
2022-01-12 12:32:53 -07:00
text: "Send a hand-delivered telegram anywhere in the Helena area."
2022-01-19 15:33:40 -07:00
},
{
title: "Shop for Supplies",
href: "/shop",
icon: "fad fa-shopping-cart",
text: "Get boxes, labels, and shipping supplies delivered to your door."
},
{
title: "Manage My Account",
href: "/account",
icon: "fad fa-user-circle",
text: "Get account number, check rewards points, update payment method, and more."
},
2022-01-12 12:32:53 -07:00
]
})
}, {});
}
},
{
path: '/send',
name: 'send',
async: function ( { resolve, reject }) {
resolve({
content: compiledPages.send({
pages: [
{
2022-01-19 15:33:40 -07:00
title: "Use a Drop Box",
href: "/dropandsend",
icon: "fad fa-box-alt",
text: "Bring your package to a Drop and Send location and we'll ship it for you. No postage or appointment needed."
},
{
title: "Request a Pickup",
2022-01-12 12:32:53 -07:00
href: "/pickup",
icon: "fad fa-home",
text: "Leave your package on your porch and we'll pick it up and ship it for you. No postage or appointment needed."
},
{
2022-01-19 15:33:40 -07:00
title: "Book an Appointment",
href: "/appointment/shipping",
2022-01-12 12:32:53 -07:00
icon: "fad fa-calendar-alt",
text: "A courier will come to you on your schedule. No account required."
2021-10-02 14:34:53 -06:00
}
2020-10-10 19:26:30 -06:00
]
2021-10-02 14:34:53 -06:00
})
}, {});
2020-10-10 19:26:30 -06:00
}
},
2021-01-22 15:17:35 -07:00
{
path: '/appointment',
name: 'appointment',
2021-10-02 14:34:53 -06:00
async: function ( { resolve, reject }) {
2021-01-22 15:17:35 -07:00
resolve({
2021-10-02 14:34:53 -06:00
content: compiledPages.appointment({
2021-08-14 14:38:55 -06:00
services: [
{
title: "Package Pickup",
text: "A courier will come to you and ship your mail, packages, etc.",
icon: "fad fa-hand-holding-box",
2022-01-19 15:33:40 -07:00
serviceid: "shipping"
2021-08-14 14:38:55 -06:00
},
{
title: "Mobile Notary",
text: "A notary public will come to you and notarize your documents.",
icon: "fad fa-file-signature",
2022-01-19 15:33:40 -07:00
serviceid: "notary"
2021-08-14 14:38:55 -06:00
}
]
2021-10-02 14:34:53 -06:00
})
}, {
2021-01-22 15:17:35 -07:00
});
2021-08-14 14:38:55 -06:00
},
routes: [
{
path: "/:serviceId",
2021-10-02 14:34:53 -06:00
async: function ( { resolve, reject, to }) {
2022-01-19 15:33:40 -07:00
var url = SETTINGS.apis.appointmentredirect + "?service=" + to.params.serviceId;
if ($("body").hasClass("theme-dark")) {
url += "&darkmode=1";
2021-08-14 14:38:55 -06:00
}
resolve({
2021-10-02 14:34:53 -06:00
content: compiledPages.appointment({
2022-01-19 15:39:09 -07:00
url: url,
serviceid: to.params.serviceId
2021-10-02 14:34:53 -06:00
})
2021-08-14 14:38:55 -06:00
}, {
});
}
}
]
2021-01-22 15:17:35 -07:00
},
{
path: '/dropandsend',
name: 'dropandsend',
2021-10-02 14:34:53 -06:00
content: compiledPages.dropandsend(),
on: {
pageBeforeIn: function () {
checkIfAccountGoodWithPaymentMethod(function (ok) {
if (!ok) {
$("#addPaymentMethodNag").css("display", "");
}
}, function (error) {
$("#addPaymentMethodNag").css("display", "");
});
},
pageAfterOut: function () {
dropboxMap = null;
}
}
},
2021-10-19 20:07:44 -06:00
{
path: '/pickup',
name: 'pickup',
async: function ( {resolve}) {
resolve({
content: compiledPages.pickup({
streetaddress: inStorage("lastpickupaddress") ? getStorage("lastpickupaddress") : "",
zipcode: inStorage("lastpickupzipcode") ? getStorage("lastpickupzipcode") : ""
})
}, {});
},
on: {
pageBeforeIn: function () {
checkIfAccountGoodWithPaymentMethod(function (ok) {
if (!ok) {
$("#addPaymentMethodNag").css("display", "");
}
}, function (error) {
$("#addPaymentMethodNag").css("display", "");
});
}
}
},
2022-01-19 15:33:40 -07:00
{
path: '/shop',
name: 'shop',
async: loadShopPage,
on: {
pageBeforeIn: function () {
checkIfAccountGoodWithPaymentMethod(function (ok) {
if (!ok) {
$("#addPaymentMethodNag").css("display", "");
}
}, function (error) {
$("#addPaymentMethodNag").css("display", "");
});
updateCart();
}
}
},
2021-12-18 18:31:04 -07:00
{
path: '/telegram',
name: 'telegram',
url: './pages/telegram.html',
on: {
pageBeforeIn: function () {
checkIfAccountGoodWithPaymentMethod(function (ok) {
if (!ok) {
$("#addPaymentMethodNag").css("display", "");
}
}, function (error) {
$("#addPaymentMethodNag").css("display", "");
});
}
}
},
2020-10-10 19:26:30 -06:00
{
path: '/track',
url: './pages/track.html',
name: 'track',
on: {
pageBeforeIn: function () {
2021-01-22 12:06:20 -07:00
addTrackingSuggestions();
$("#trackingcode").val("0");
app.input.validate("#trackingcode");
$("#trackingcode").val("");
}
}
2020-10-10 19:26:30 -06:00
},
2021-01-22 16:32:35 -07:00
{
path: '/rates',
url: './pages/rates.html',
name: 'rates',
on: {
pageAfterIn: function () {
initRateForm();
}
}
},
2021-03-07 00:40:34 -07:00
{
path: '/account',
name: 'account',
2021-10-02 14:34:53 -06:00
content: compiledPages.account(),
on: {
pageAfterIn: function () {
initAccountPage();
}
2021-10-02 14:34:53 -06:00
}
2021-03-07 00:40:34 -07:00
},
2020-10-10 19:26:30 -06:00
{
2021-01-22 12:06:20 -07:00
path: '/track/:code',
2020-10-10 19:26:30 -06:00
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);
}
}
2020-10-10 19:26:30 -06:00
},
2022-02-01 19:52:22 -07:00
{
path: '/receipts',
name: 'receipts',
async: function ( {resolve, reject}) {
app.dialog.preloader("Loading...");
apirequest(SETTINGS.apis.getreceipts, {
accountnumber: getStorage("accountnumber"),
accountkey: getStorage("accountkey")
}, function (success) {
app.dialog.close();
if (success.status == "OK") {
resolve({
content: compiledPages.receipts({
receipts: success.receipts
})
});
} else {
app.dialog.alert(success.msg, "Error");
sendErrorReport("Receipts", "Loading receipt list", success.msg);
reject();
}
}, function (xhr, status, error) {
app.dialog.close();
app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error");
sendErrorReport("Receipts", "Couldn't load receipts", "Server/network problem: " + xhr.status + ": " + xhr.statusText);
reject();
}, "POST");
}
},
2020-10-10 19:26:30 -06:00
{
path: '/credits',
url: './pages/credits.html',
name: 'credits'
},
{
path: '/settings',
name: 'settings',
2021-10-02 14:34:53 -06:00
async: function ( {resolve}) {
2020-10-10 19:26:30 -06:00
var settings = [];
settings.push(
{
setting: "display",
title: "Display and Appearance",
text: "",
onclick: "router.navigate('/settings/display')",
link: true
}
);
settings.push(
{
setting: "resetaccount",
title: "Forget Account",
text: "Log out and disconnect from your Helena Express account.",
onclick: "resetAccountPrompt()",
link: true
},
2020-10-10 19:26:30 -06:00
{
setting: "versions",
2021-01-22 12:06:20 -07:00
title: "Helena Express app v" + app_version,
2022-01-19 16:12:57 -07:00
text: "Copyright &copy; 2019-2022 Helena Express and Netsyms Technologies.",
2020-10-10 19:26:30 -06:00
onclick: ""
},
{
setting: "opensource",
title: "Credits and open source info",
text: "",
onclick: "router.navigate('/credits')",
link: true
},
{
2022-01-19 16:13:38 -07:00
setting: "legal",
title: "Terms of Use and Privacy Policy",
2020-10-10 19:26:30 -06:00
text: "",
2022-01-19 16:12:57 -07:00
onclick: "openBrowser('https://helena.express/appterms?mtm_campaign=HelenaExpressApp')",
2020-10-10 19:26:30 -06:00
link: true
2022-01-20 00:39:12 -07:00
},
{
setting: "analytics",
title: "Analytics",
text: "If turned on, we'll collect some anonymous information to help improve the app. It is not sent to any third parties.",
toggle: true,
checked: getStorage("analytics") !== "false",
onclick: ""
}, );
2020-10-10 19:26:30 -06:00
resolve({
2021-10-02 14:34:53 -06:00
content: compiledPages.settings({
2020-10-10 19:26:30 -06:00
page_title: "Settings",
settings: settings
2021-10-02 14:34:53 -06:00
})
2020-10-10 19:26:30 -06:00
});
},
routes: [
{
path: '/display',
name: 'settings',
2021-10-19 20:07:44 -06:00
async: function ( {resolve}) {
2020-10-10 19:26:30 -06:00
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"
}
]
},
{
setting: "hideaccountnag",
title: "Hide \"Finish Account Setup\"",
text: "",
toggle: true,
checked: getStorage("hideaccountnag") == "true",
onclick: ""
2020-10-10 19:26:30 -06:00
}
];
resolve({
2021-10-02 14:34:53 -06:00
content: compiledPages.settings({
2020-10-10 19:26:30 -06:00
page_title: "Display Settings",
settings: settings
2021-10-02 14:34:53 -06:00
})
2020-10-10 19:26:30 -06:00
});
}
}
]
}
];