From 10eaebeb19a25fdaa5be070b97bedc9eed46ffe9 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 10 Oct 2020 20:44:27 -0600 Subject: [PATCH] Add Offers page with refresh from API (closes #2) --- www/assets/css/app.css | 4 ++++ www/assets/js/offers.js | 51 +++++++++++++++++++++++++++++++++++++++++ www/index.html | 1 + www/pages/offers.html | 46 +++++++++++++++++++++++++++++++++++++ www/routes.js | 28 ++++++++++++++++++---- www/settings.js | 3 ++- 6 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 www/assets/js/offers.js create mode 100644 www/pages/offers.html diff --git a/www/assets/css/app.css b/www/assets/css/app.css index 9be9830..d8e4ca9 100644 --- a/www/assets/css/app.css +++ b/www/assets/css/app.css @@ -82,6 +82,10 @@ Framework7 and FontAwesome both have a .fab class font-size: var(--f7-block-font-size); } +.card-header.no-hairlines:after { + display: none; +} + .no-animation * { -webkit-transition: 10ms !important; -moz-transition: 10ms !important; diff --git a/www/assets/js/offers.js b/www/assets/js/offers.js new file mode 100644 index 0000000..ebe4ffa --- /dev/null +++ b/www/assets/js/offers.js @@ -0,0 +1,51 @@ +/* + * 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 openOffersAsync(routeTo, routeFrom, resolve, reject) { + app.dialog.preloader("Fetching latest deals..."); + + apirequest( + SETTINGS.apis.offers, + {}, + function (resp) { + app.dialog.close(); + if (resp.status == "ERROR") { + app.dialog.alert(resp.msg, "Error"); + reject(); + } else { + var context = { + offers: [] + }; + + for (var i = 0; i < resp.offers.length; i++) { + if (resp.offers[i].valid === true) { + // no expiration + resp.offers[i].expires = "Limited time offer"; + } else { + resp.offers[i].expires = "Expires " + formatTimestamp("l F j, Y", resp.offers[i].valid.to); + } + context.offers.push(resp.offers[i]); + } + + resolve({ + templateUrl: "pages/offers.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"); +} \ No newline at end of file diff --git a/www/index.html b/www/index.html index 3bb7372..f931442 100644 --- a/www/index.html +++ b/www/index.html @@ -45,6 +45,7 @@ + \ No newline at end of file diff --git a/www/pages/offers.html b/www/pages/offers.html new file mode 100644 index 0000000..0f26ff3 --- /dev/null +++ b/www/pages/offers.html @@ -0,0 +1,46 @@ + + +
+ + + +
+
+
+
+ {{#each offers}} +
+
+
+
+
+

+

{{title}}

+ {{expires}} +
+
+
+

{{text}} +

+
+
+
+ {{/each}} +
+
+
+ +
+
\ No newline at end of file diff --git a/www/routes.js b/www/routes.js index 28b210a..eacca25 100644 --- a/www/routes.js +++ b/www/routes.js @@ -19,6 +19,11 @@ var routes = [ href: "/bookrepair", icon: "fal fa-calendar-check" }, + { + title: "Live Chat", + href: "/chat", + icon: "fal fa-comments" + }, { title: "Repair Status", href: "/track", @@ -27,13 +32,18 @@ var routes = [ { title: "Pay Bill", href: "/pay", - icon: "fal fa-file-invoice-dollar" + icon: "fal fa-file-invoice" }, { - title: "View Offers", + title: "Get Deals", href: "/offers", - icon: "fal fa-badge-percent" - } + icon: "fal fa-badge-dollar" + }, + { + title: "View Services", + href: "/services", + icon: "fal fa-magic" + }, ] } }); @@ -44,6 +54,16 @@ var routes = [ url: './pages/track.html', name: 'track' }, + { + path: '/offers', + name: 'offers', + async: openOffersAsync, + on: { + pageAfterIn: function () { + JsBarcode(".offerbarcode").init(); + } + } + }, { path: '/track/:id', name: 'trackresult', diff --git a/www/settings.js b/www/settings.js index 871ee95..82f16ea 100644 --- a/www/settings.js +++ b/www/settings.js @@ -6,7 +6,8 @@ var SETTINGS = { apis: { - track: "https://track.netsyms.com/public/api.php" + track: "https://track.netsyms.com/public/api.php", + offers: "https://apis.netsyms.net/repairapp/offers.php" }, branding: { apptitle: "Netsyms PC Repair",