From e04a28f7ccca076002122d6c9f2f9d68dc3c3f6e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 24 Feb 2020 22:36:15 +0100 Subject: [PATCH] TCP 2019 example implementation --- www/index.html | 25 +++++++++++++++++- www/js/index.js | 5 ++++ www/js/store.js | 50 +++++++++++++++++++++++++++++++++++ www/scss/index.scss | 1 + www/scss/partials/_store.scss | 34 ++++++++++++++++++++++++ www/store.html | 18 +++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 www/js/store.js create mode 100644 www/scss/partials/_store.scss create mode 100644 www/store.html diff --git a/www/index.html b/www/index.html index 9fb2f127..6e3f8f3c 100644 --- a/www/index.html +++ b/www/index.html @@ -6,7 +6,7 @@ - + F-sektionen @@ -204,6 +204,15 @@
+ + @@ -945,6 +967,7 @@ + diff --git a/www/js/index.js b/www/js/index.js index 4c198246..2b2e4127 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -207,6 +207,11 @@ var alternativesView = app.views.create('#view-alternatives', { path: '/contact/:contactId', url: './contact.html', }, + { + name: 'store', + path: '/store/', + url: './store.html', + } ] }); diff --git a/www/js/store.js b/www/js/store.js new file mode 100644 index 00000000..46ee0984 --- /dev/null +++ b/www/js/store.js @@ -0,0 +1,50 @@ +$$(document).on('page:init', '.page[data-name="store"]', function () { + let storeProductAPIEndpointURL = API + '/store_products'; + + $.getJSON(storeProductAPIEndpointURL) + .done(function(resp) { + initStore(resp); + }) + .fail(function(resp) { + console.log(resp.statusText); + }); + + function initStore(resp) { + let products = resp.store_products; + products.forEach(function(product) { + product.price /= 100; + if (product.image_url === "") { + product.image_url = "img/missing_thumb.png"; + } + }); + + let templateHTML = app.templates.storeTemplate({products: products}); + let storeContainer = $('.store-content'); + storeContainer.html(templateHTML); + + $('.buy-product').on('click', function() { + productId = $('.buy-product').attr('data-id'); + buyProduct(productId); + }); + } + + function buyProduct(id) { + $.ajax({ + url: API + '/store_orders', + type: 'POST', + dataType: 'json', + data: { + "item": { + "id": id, + "quantity": 1 + } + }, + success: function(resp) { + app.dialog.alert(resp.success, 'Varan är köpt'); + }, + error: function(resp) { + app.dialog.alert(resp.responseJSON.error); + } + }); + } +}); diff --git a/www/scss/index.scss b/www/scss/index.scss index 5c3759b3..7be0685d 100644 --- a/www/scss/index.scss +++ b/www/scss/index.scss @@ -20,3 +20,4 @@ @import 'partials/album'; @import 'partials/about_app'; @import 'partials/cafe'; +@import 'partials/store'; diff --git a/www/scss/partials/_store.scss b/www/scss/partials/_store.scss new file mode 100644 index 00000000..f0cd68d7 --- /dev/null +++ b/www/scss/partials/_store.scss @@ -0,0 +1,34 @@ +.store-content { + .card:nth-child(-n+2) { + margin-top: 16px; + } + + .card { + width: calc(50% - 18px); + float: left; + box-shadow: none; + margin-left: 8px + } + + .card-header { + background-size: cover; + background-repeat: no-repeat; + background-position: center; + background-color: #f8f8f8; + height: 37vh; + } + + .card-content { + text-align: center; + } + + .product-name { + font-size: 19px; + font-weight: bold; + } + + .buy-product { + background-color: $fsek-orange; + margin-top: 10px; + } +} diff --git a/www/store.html b/www/store.html new file mode 100644 index 00000000..6f0ba164 --- /dev/null +++ b/www/store.html @@ -0,0 +1,18 @@ +
+ +
+
+
+
+
+