Define a new URL to be used as a preview.
+ + +diff --git a/src/api/wishes.php b/src/api/wishes.php index df82a49b..4fbc3d4f 100644 --- a/src/api/wishes.php +++ b/src/api/wishes.php @@ -9,9 +9,7 @@ use wishthis\{User, Wish, EmbedCache}; $api = true; -$response = array( - 'success' => false, -); +$response = array(); require '../../index.php'; @@ -98,6 +96,16 @@ switch ($_SERVER['REQUEST_METHOD']) { ;'); $response['success'] = true; + } elseif (isset($_PUT['wish_id'], $_PUT['wish_url'])) { + /** + * Update Wish Image + */ + $database + ->query('UPDATE `wishes` + SET `image` = "' . $_PUT['wish_url'] . '" + WHERE `id` = ' . $_PUT['wish_id'] . ';'); + + $response['wish_url'] = $_PUT['wish_url']; } break; diff --git a/src/assets/css/wish.css b/src/assets/css/wish.css index 984de4fe..6f5ad34e 100644 --- a/src/assets/css/wish.css +++ b/src/assets/css/wish.css @@ -1,6 +1,8 @@ -.ui.fluid.image { +.image.preview { height: var(--wishPreviewHeight); object-fit: cover; object-position: 50%; + + cursor: pointer; } diff --git a/src/assets/js/default.js b/src/assets/js/default.js index f8f3ff29..c252dd7f 100644 --- a/src/assets/js/default.js +++ b/src/assets/js/default.js @@ -92,6 +92,9 @@ $(function() { $.fn.toast.settings.displayTime = 'auto'; $.fn.toast.settings.minDisplayTime = 3000; $.fn.toast.settings.showProgress = true; + $.fn.toast.settings.class = 'success'; + $.fn.toast.settings.showIcon = 'check'; + $.fn.toast.settings.title = 'Success'; }); /** diff --git a/src/assets/js/wish.js b/src/assets/js/wish.js index 0fa15d34..615d36ea 100644 --- a/src/assets/js/wish.js +++ b/src/assets/js/wish.js @@ -78,12 +78,7 @@ $(function () { elementModalFetch.modal('hide'); - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wish information updated.' - }); + $('body').toast({ message: 'Wish information updated.' }); } buttonFetch.removeClass('loading'); @@ -97,12 +92,7 @@ $(function () { }) .modal('show'); } else { - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wish information updated.' - }); + $('body').toast({ message: 'Wish information updated.' }); formWish.removeClass('loading'); } @@ -116,4 +106,40 @@ $(function () { }); + /** + * Image + */ + $(document).on('click', '.image.preview', function() { + var modalImage = $('.modal.image'); + + modalImage + .modal({ + onApprove: function(buttonApprove) { + var formImage = modalImage.find('form.image'); + var formData = new URLSearchParams(new FormData(formImage[0])); + + formImage.addClass('loading'); + + fetch('/src/api/wishes.php', { + method: 'PUT', + body: formData + }) + .then(handleFetchError) + .then(handleFetchResponse) + .then(function(response) { + var elementImage = $('.form.wish img.preview'); + elementImage.attr('src', response.wish_url); + + formImage.removeClass('loading'); + modalImage.modal('hide'); + + $('body').toast({ message: 'Wish image successfully updated.' }); + }); + + return false; + } + }) + .modal('show'); + }); + }); diff --git a/src/assets/js/wishlists.js b/src/assets/js/wishlists.js index 1bd58c84..51de990e 100644 --- a/src/assets/js/wishlists.js +++ b/src/assets/js/wishlists.js @@ -200,12 +200,7 @@ $(function () { urlParams.delete('wishlist'); - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wishlist successfully deleted.' - }); + $('body').toast({ message: 'Wishlist successfully deleted.' }); wishlistsRefresh(); @@ -265,12 +260,7 @@ $(function () { onSuccess: function () { column.fadeOut(); - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wish successfully deleted.' - }); + $('body').toast({ message: 'Wish successfully deleted.' }); wishlistsRefresh(); @@ -313,12 +303,7 @@ $(function () { .then(handleFetchResponse) .then(function(response) { if (response.success) { - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wish successfully added.' - }); + $('body').toast({ message: 'Wish successfully added.' }); wishlistsRefresh(); @@ -363,12 +348,7 @@ $(function () { urlParams.set('wishlist', response.data.lastInsertId); - $('body').toast({ - class: 'success', - showIcon: 'check', - title: 'Success', - message: 'Wishlist successfully created.' - }); + $('body').toast({ message: 'Wishlist successfully created.' }); wishlistsRefresh(); } diff --git a/src/classes/wish.php b/src/classes/wish.php index c925a7b7..ecea4f6a 100644 --- a/src/classes/wish.php +++ b/src/classes/wish.php @@ -16,6 +16,7 @@ class Wish public int $wishlist; public ?string $title; public ?string $description; + public ?string $image; public ?string $url; public ?string $status; @@ -52,15 +53,15 @@ class Wish $this->info = $this->cache->get($generateCache); } - if (empty($this->info->image)) { - $this->info->image = '/src/assets/img/no-image.svg'; - } - foreach ($columns as $key => $value) { if (empty($value) && isset($this->info->$key)) { $this->$key = $this->info->$key; } } + + if (empty($this->image)) { + $this->image = '/src/assets/img/no-image.svg'; + } } public function getCard(int $ofUser): string @@ -83,8 +84,8 @@ class Wish
Define a new URL to be used as a preview.
+ + +