diff --git a/src/api/wishlists.php b/src/api/wishlists.php index d22a959f..8db0e432 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -16,6 +16,30 @@ $response = array( require '../../index.php'; switch ($_SERVER['REQUEST_METHOD']) { + case 'POST': + /** + * Create + */ + if (isset($_POST['wishlist-name'], $_SESSION['user']['id'])) { + $database->query('INSERT INTO `wishlists` + ( + `user`, + `name`, + `hash` + ) VALUES ( + ' . $_SESSION['user']['id'] . ', + "' . $_POST['wishlist-name'] . '", + "' . sha1(time() . $_SESSION['user']['id'] . $_POST['wishlist-name']) . '" + ) + ;'); + + $response['success'] = true; + $response['data'] = array( + 'lastInsertId' => $database->lastInsertId(), + ); + } + break; + case 'GET': if (isset($_GET['userid']) || isset($_SESSION['user']['id'])) { $user = isset($_GET['userid']) ? new User($_GET['userid']) : new User(); diff --git a/src/assets/css/default.css b/src/assets/css/default.css index b8a25a8d..dafc7374 100644 --- a/src/assets/css/default.css +++ b/src/assets/css/default.css @@ -33,10 +33,6 @@ img { /** * Card */ -.wishlist-cards { - margin-top: 1rem; -} - .ui.card { overflow: hidden; } @@ -135,10 +131,3 @@ p .ui.horizontal.label { cursor: default; user-select: none; } - -/** - * Segment - */ -.ui.segments { - overflow: hidden; -} diff --git a/src/assets/js/default.js b/src/assets/js/default.js index 829e5c27..84b68642 100644 --- a/src/assets/js/default.js +++ b/src/assets/js/default.js @@ -10,7 +10,6 @@ if ('serviceWorker' in navigator) { }) } - const urlParams = new URLSearchParams(window.location.search); $(function() { diff --git a/src/assets/js/wishlists.js b/src/assets/js/wishlists.js index 0549fe06..0f0e2f5c 100644 --- a/src/assets/js/wishlists.js +++ b/src/assets/js/wishlists.js @@ -4,27 +4,31 @@ $(function () { */ var wishlists = []; - $('.ui.dropdown.wishlists').api({ - action: 'get wishlists', - method: 'GET', - on: 'now', - onSuccess: function (response, element, xhr) { - wishlists = response.results; + function wishlistsRefresh() { + $('.ui.dropdown.wishlists').api({ + action: 'get wishlists', + method: 'GET', + on: 'now', + onSuccess: function (response, element, xhr) { + wishlists = response.results; - element.dropdown({ - values: wishlists, - placeholder: 'No wishlist selected.' - }) + element.dropdown({ + values: wishlists, + placeholder: 'No wishlist selected.' + }) - if (urlParams.has('wishlist')) { - element.dropdown('set selected', urlParams.get('wishlist')); - } else { - if (wishlists[0]) { - element.dropdown('set selected', wishlists[0].value); + if (urlParams.has('wishlist')) { + element.dropdown('set selected', urlParams.get('wishlist')); + } else { + if (wishlists[0]) { + element.dropdown('set selected', wishlists[0].value); + } } } - } - }); + }); + } + + wishlistsRefresh(); /** * Selection @@ -53,7 +57,11 @@ $(function () { /** * Cards */ - $('.wishlist-cards').html(wishlists[wishlistIndex].cards); + if (wishlistIndex >= 0) { + $('.wishlist-cards').html(wishlists[wishlistIndex].cards); + } else { + $('.wishlist-cards').html(''); + } /** * Generate cache @@ -292,7 +300,7 @@ $(function () { onSuccess: function () { column.fadeOut(); - location.reload(); + wishlistsRefresh(); }, }); } @@ -329,7 +337,7 @@ $(function () { button.removeClass('loading'); - location.reload(); + wishlistsRefresh(); }); return false; @@ -420,4 +428,44 @@ $(function () { }); }); + /** + * Create wishlist + */ + $(document).on('click', '.button.wishlist-create', function () { + var modalWishlistCreate = $('.ui.modal.wishlist-create'); + var formWishlistCreate = modalWishlistCreate.find('.ui.form'); + + modalWishlistCreate + .modal({ + onApprove: function (buttonCreate) { + const formData = new URLSearchParams(new FormData(formWishlistCreate[0])); + + formWishlistCreate.addClass('loading'); + buttonCreate.addClass('loading'); + + fetch('/src/api/wishlists.php', { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(response => { + if(response.success) { + modalWishlistCreate.modal('hide'); + + urlParams.set('wishlist', response.data.lastInsertId); + + wishlistsRefresh(); + } + }) + .finally(() => { + formWishlistCreate.removeClass('loading'); + buttonCreate.removeClass('loading'); + }); + + return false; + } + }) + .modal('show'); + }); + }); diff --git a/src/classes/wishlist.php b/src/classes/wishlist.php index cfac7259..77dafb99 100644 --- a/src/classes/wishlist.php +++ b/src/classes/wishlist.php @@ -81,87 +81,85 @@ class Wishlist $cardIndex = 0; if (!empty($products)) { ?> -
-
- get(false); - $exists = $cache->exists() ? 'true' : 'false'; - ?> -
-
+
+ get(false); + $exists = $cache->exists() ? 'true' : 'false'; + ?> +
+
- image) { ?> -
- + image) { ?> +
+ - favicon) { ?> - - + favicon) { ?> + + - providerName) { ?> - providerName ?> - + providerName) { ?> + providerName ?> + - - + + + +
+ + +
+ title) { ?> +
+ url) { ?> + title ?> + + title ?>
-
- title) { ?> -
- url) { ?> - title ?> - - title ?> - -
- - - keywords) { ?> -
- keywords) ?> -
- - - description) { ?> -
- description ?> -
- -
- -
- - - - Commit - - - - url) { ?> - - - View - - - - - - - Delete - - -
+ keywords) { ?> +
+ keywords) ?> +
+ + description) { ?> +
+ description ?> +
+
+ +
+ + + + Commit + + + + url) { ?> + + + View + + + + + + + Delete + + +
+
- -
+
+
diff --git a/src/pages/wishlist.php b/src/pages/wishlist.php index 25e0c368..fdfbf697 100644 --- a/src/pages/wishlist.php +++ b/src/pages/wishlist.php @@ -68,14 +68,18 @@ $page->navigation();
-
- getCards( - array( - 'exclude' => array('unavailable'), - ) - ); - ?> +
+

Products

+ +
+ getCards( + array( + 'exclude' => array('unavailable'), + ) + ); + ?> +
diff --git a/src/pages/wishlists.php b/src/pages/wishlists.php index b5d023c1..ae5e4381 100644 --- a/src/pages/wishlists.php +++ b/src/pages/wishlists.php @@ -11,47 +11,20 @@ use wishthis\{Page, User, Wishlist}; $page = new page(__FILE__, 'Wishlists'); $page->header(); $page->navigation(); - -/** - * Create - */ -if (isset($_POST['wishlist-create'], $_POST['name'])) { - $database->query('INSERT INTO `wishlists` - ( - `user`, - `name`, - `hash` - ) VALUES ( - ' . $_SESSION['user']['id'] . ', - "' . $_POST['name'] . '", - "' . sha1(time() . $_SESSION['user']['id'] . $_POST['name']) . '" - ) - ;'); - - header('Location: /?page=wishlists'); - die(); -} - -/** - * Delete - */ -if (isset($_POST['wishlist_delete_id'])) { - $database->query('DELETE FROM `wishlists` - WHERE id = ' . $_POST['wishlist_delete_id'] . ' - ;'); -} ?>

title ?>

+

Here you can view and edit all of your wishlists.

-
+

View

-
-
-

View

-

Please select a wishlist to view.

+
+
+

Please select a wishlist to view.

+ +
+ +
+ + + + Add a product + + + + + Share + + +
+ + + +
-
-
-

Create

-

- Choose a new name for your wishlist. - Here's a suggestion to get you started! -

+
+

General options.

-
-
- - -
- - -
-
+ + + Create a wishlist +
-
-

Options

-

Wishlist related options.

+

Products

- - - Add a product - +
+
+
- - - Share - + + -
- - + +