diff --git a/www/assets/css/app.css b/www/assets/css/app.css
index 92b472e..6632927 100644
--- a/www/assets/css/app.css
+++ b/www/assets/css/app.css
@@ -109,6 +109,10 @@ Framework7 and FontAwesome both have a .fab class
display: none;
}
+.homepage-card {
+ height: calc(100% - calc(var(--f7-card-margin-vertical) * 2));
+}
+
.no-animation * {
-webkit-transition: 10ms !important;
-moz-transition: 10ms !important;
@@ -191,10 +195,30 @@ Framework7 and FontAwesome both have a .fab class
border-radius: 10px;
}
-.card.pointercursor {
+.pointercursor {
cursor: pointer;
}
+.card-expandable .card-closed-display-none {
+ display: none;
+}
+.card-expandable.card-opened .card-opened-display-none {
+ display: none;
+}
+.card-expandable.card-opening .card-opened-display-none {
+ display: none;
+}
+.card-expandable.card-opened .card-closed-display-none {
+ display: initial;
+}
+.card-expandable.card-opening .card-closed-display-none {
+ display: initial;
+}
+
+.card-expandable.card-opened .card-content, .card-expandable.card-opening .card-content {
+ padding-top: calc(var(--f7-navbar-height) * 1.5);
+}
+
.maplibregl-popup-content {
color: var(--f7-text-color);
background-color: var(--f7-page-bg-color);
diff --git a/www/assets/js/main.js b/www/assets/js/main.js
index 16f69d7..bb5290d 100644
--- a/www/assets/js/main.js
+++ b/www/assets/js/main.js
@@ -14,7 +14,8 @@ var app = new Framework7({
id: "com.netsyms.helenaexpress.app",
theme: "auto",
card: {
- swipeToClose: false
+ swipeToClose: false,
+ hideNavbarOnOpen: false,
},
popup: {
backdrop: true
diff --git a/www/assets/js/shop.js b/www/assets/js/shop.js
new file mode 100644
index 0000000..e7d745a
--- /dev/null
+++ b/www/assets/js/shop.js
@@ -0,0 +1,217 @@
+/*
+ * 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 shopitems = [];
+var shopitems_flattened = [];
+var samedaydeliveryfee = 10.0;
+
+function loadShopPage( {resolve, reject}) {
+ app.dialog.preloader("Opening the shop...");
+ apirequest(SETTINGS.apis.shopitems, [], function (resp) {
+ app.dialog.close();
+ shopitems = resp.items;
+ samedaydeliveryfee = resp.samedaydeliveryfee;
+ for (var cat in shopitems) {
+ for (var i in shopitems[cat]["items"]) {
+ shopitems_flattened[i] = shopitems[cat]["items"][i];
+ }
+ }
+ resolve({
+ content: compiledPages.shop({
+ items: shopitems
+ })
+ }, {});
+ }, function (error) {
+ app.dialog.close();
+ app.dialog.alert("Couldn't open the shop right now. Try again later.", "Whoops!");
+ reject();
+ });
+}
+
+$("body").on("card:opened", ".shop-item-card", function () {
+ app.swiper.destroy("#swiper-" + $(this).data("sku"));
+ app.swiper.create("#swiper-" + $(this).data("sku"), {
+ pagination: {
+ el: "#swiper-pagination-" + $(this).data("sku"),
+ type: "bullets"
+ }
+ });
+});
+
+var shoppingcart = {};
+
+if (inStorage("shoppingcart")) {
+ shoppingcart = JSON.parse(getStorage("shoppingcart"));
+}
+
+function addToCart(sku, qty) {
+ if (typeof qty == 'undefined') {
+ qty = 1;
+ }
+ if (shoppingcart[sku]) {
+ shoppingcart[sku] += qty;
+ } else {
+ shoppingcart[sku] = qty;
+ }
+ app.toast.show({
+ icon: "",
+ text: "Added to cart!",
+ position: "center",
+ horizontalPosition: "center",
+ closeTimeout: 2000,
+ destroyOnClose: true
+ });
+ updateCart();
+}
+
+function removeFromCart(sku, qty) {
+ // If no qty set, delete them all
+ if (typeof qty == "undefined") {
+ qty = 99999;
+ }
+ if (shoppingcart[sku]) {
+ shoppingcart[sku] -= qty;
+ }
+ if (shoppingcart[sku] <= 0) {
+ delete shoppingcart[sku];
+ }
+ updateCart();
+}
+
+function emptyShoppingCart() {
+ shoppingcart = {};
+ updateCart();
+}
+
+function updateCart() {
+ setStorage("shoppingcart", JSON.stringify(shoppingcart));
+ var totalitems = 0;
+ for (var sku in shoppingcart) {
+ totalitems += shoppingcart[sku];
+ }
+ $("#shopping-cart-items-chip-label").text(totalitems + "");
+
+ var cartitems = [];
+ for (var sku in shoppingcart) {
+ var item = shopitems_flattened[sku];
+ item.qty = shoppingcart[sku];
+ item.linetotal = (item.qty * item.price).toFixed(2);
+ cartitems.push(item);
+ }
+
+ $("#shoppingCartContainer").html(compiledPages.shoppingcart_fragment({
+ cartitems: cartitems
+ }));
+}
+
+function openShopCheckout() {
+ // Check if order is mailable or not by checking each item for mailability
+ // Also check if all items are still in stock (cart could have sat around a while)
+ var ordermailable = true;
+ var orderinstock = true;
+ var ordertotal = 0.0;
+ var outofstockitems = [];
+ for (var sku in shoppingcart) {
+ if (shopitems_flattened[sku].mailable != true) {
+ ordermailable = false;
+ }
+ if (shopitems_flattened[sku].instock != true) {
+ orderinstock = false;
+ outofstockitems.push(shopitems_flattened[sku].name);
+ }
+ ordertotal += (shopitems_flattened[sku].price * shoppingcart[sku]);
+ }
+
+ if (!orderinstock) {
+ if (outofstockitems.length == 1) {
+ app.dialog.alert("The following item is out of stock. Remove it from your cart to complete your order.
" + outofstockitems[0], "Out of Stock!");
+ } else {
+ app.dialog.alert("The following items in your cart are out of stock. Remove them from your cart to complete your order.
" + outofstockitems.join("
"), "Out of Stock!");
+ }
+ return;
+ }
+
+ if (ordermailable) {
+ app.dialog.create({
+ title: 'Checkout',
+ text: "Your order can be either mailed to you (1-5 days) or delivered same-day. Either way, it will be sent to your account's address. Your saved payment method will be charged for $" + ordertotal.toFixed(2) + " plus any delivery fee when your order ships.",
+ buttons: [
+ {
+ text: 'Mail (free)'
+ },
+ {
+ text: 'Same-day delivery ($' + samedaydeliveryfee.toFixed(2) + ')'
+ },
+ {
+ text: 'Cancel Checkout',
+ color: "red"
+ }
+ ],
+ verticalButtons: true,
+ onClick: function (dialog, index) {
+ switch (index) {
+ case 0:
+ placeOrder("mail", ordertotal);
+ break;
+ case 1:
+ placeOrder("courier", ordertotal + samedaydeliveryfee);
+ break;
+ }
+ }
+ }).open();
+ } else {
+ app.dialog.create({
+ title: 'Checkout',
+ text: "Your order will be delivered to your account's address. Your saved payment method will be charged for $" + (ordertotal + samedaydeliveryfee).toFixed(2) + " (including delivery fee) when your order ships.",
+ buttons: [
+ {
+ text: 'Confirm Order'
+ },
+ {
+ text: 'Cancel Checkout',
+ color: "red"
+ }
+ ],
+ verticalButtons: true,
+ onClick: function (dialog, index) {
+ switch (index) {
+ case 0:
+ placeOrder("courier", ordertotal + samedaydeliveryfee);
+ break;
+ case 1:
+ break;
+ }
+ }
+ }).open();
+ }
+}
+
+function placeOrder(deliverymethod, ordertotal) {
+ app.dialog.preloader("Placing order...");
+ apirequest(SETTINGS.apis.shopbuy, {
+ cart: JSON.stringify(shoppingcart),
+ shipmethod: deliverymethod,
+ total: (ordertotal * 1.0).toFixed(2),
+ accountnumber: getStorage("accountnumber"),
+ accountkey: getStorage("accountkey")
+ }, function (resp) {
+ app.dialog.close();
+ if (resp.status == "ERROR") {
+ app.dialog.alert(resp.msg, "Error");
+ return;
+ } else {
+ emptyShoppingCart();
+ app.dialog.alert("Your order has been received.", "Order placed!");
+ app.popup.close();
+ return;
+ }
+ }, function (error) {
+ app.dialog.close();
+ app.dialog.alert("Your order might not have gone through due to a network error. If you don't get a confirmation email, try again.", "Whoops!");
+ })
+ console.log(deliverymethod);
+ console.log(shoppingcart);
+}
\ No newline at end of file
diff --git a/www/index.html b/www/index.html
index 1c66926..5826f12 100644
--- a/www/index.html
+++ b/www/index.html
@@ -59,6 +59,7 @@
+
diff --git a/www/pages/shop.html b/www/pages/shop.html
new file mode 100644
index 0000000..1fa7839
--- /dev/null
+++ b/www/pages/shop.html
@@ -0,0 +1,117 @@
+
+
+