From d85e2ac65dbb69e0b376b1b7519f5efd0109d6da Mon Sep 17 00:00:00 2001 From: grandeljay Date: Sun, 27 Feb 2022 12:33:02 +0100 Subject: [PATCH] Remove fetch from product add modal --- src/assets/js/wish.js | 19 ++++++-- src/assets/js/wishlists.js | 91 -------------------------------------- src/pages/wish.php | 6 +-- src/pages/wishlists.php | 9 +--- 4 files changed, 20 insertions(+), 105 deletions(-) diff --git a/src/assets/js/wish.js b/src/assets/js/wish.js index 4d493f67..0fa15d34 100644 --- a/src/assets/js/wish.js +++ b/src/assets/js/wish.js @@ -26,6 +26,15 @@ $(function () { .then(function(response) { var info = response.info; + /** + * Prodiver name + */ + if (info.providerName) { + modalValidate.find('.providerName').text(info.providerName); + } else { + modalValidate.find('.provider').remove(); + } + /** * Title */ @@ -46,9 +55,6 @@ $(function () { if (info.url && info.url !== inputURL.val()) { var elementModalFetch = $('.modal.validate'); - modalValidate.find('.primary.button').popup(); - console.log(modalValidate.find('.primary.button')); - elementModalFetch.find('input.current').val(inputURL.val()); elementModalFetch.find('input.proposed').val(info.url); @@ -91,6 +97,13 @@ $(function () { }) .modal('show'); } else { + $('body').toast({ + class: 'success', + showIcon: 'check', + title: 'Success', + message: 'Wish information updated.' + }); + formWish.removeClass('loading'); } }) diff --git a/src/assets/js/wishlists.js b/src/assets/js/wishlists.js index be8cde48..9b9651de 100644 --- a/src/assets/js/wishlists.js +++ b/src/assets/js/wishlists.js @@ -347,97 +347,6 @@ $(function () { .modal('show'); }); - /** Fetch */ - $(document).on('click', '#wishlist-wish-add-url-validate', function () { - var buttonValidate = $(this); - var inputWishURL = buttonValidate.prev(); - - var elementModalAdd = $('.ui.modal.wishlist-wish-add'); - var elementButtons = elementModalAdd.find('.actions .button'); - var elementTitle = elementModalAdd.find('[name="wish_title"]'); - var elementDescription = elementModalAdd.find('[name="wish_description"]'); - - buttonValidate.addClass('disabled loading'); - elementButtons.addClass('disabled'); - - fetch('/src/api/wishes.php?wish_url=' + inputWishURL.val(), { - method: 'GET' - }) - .then(handleFetchError) - .then(handleFetchResponse) - .then(function(response) { - var info = response.info; - - /** - * Title - */ - if (info.title && elementTitle.length) { - elementTitle.val(info.title); - } - - /** - * Description - */ - if (info.description && elementDescription.length) { - elementDescription.val(info.description); - } - - /** - * URL - */ - if (info.url && info.url !== inputWishURL.val()) { - var elementModalFetch = $('.ui.modal.wishlist-wish-fetch'); - - elementModalFetch.find('input.current').val(inputWishURL.val()); - elementModalFetch.find('input.proposed').val(info.url); - - elementButtons.addClass('disabled'); - - elementModalFetch - .modal({ - allowMultiple: true, - closable: false, - onApprove: function (buttonFetch) { - var formData = new URLSearchParams(); - formData.append('wish_url_current', inputWishURL.val()); - formData.append('wish_url_proposed', info.url); - - buttonFetch.addClass('loading'); - - fetch('/src/api/wishes.php', { - method: 'PUT', - body: formData - }) - .then(response => response.json()) - .then(response => { - if (response.success) { - inputWishURL.val(info.url); - - elementModalFetch.modal('hide'); - } - - buttonFetch.removeClass('loading'); - }); - - return false; - }, - onHide: function() { - buttonValidate.removeClass('disabled loading'); - elementButtons.removeClass('disabled'); - } - }) - .modal('show'); - } else { - buttonValidate.removeClass('disabled loading'); - elementButtons.removeClass('disabled'); - } - }) - .catch(function(error) { - console.log(error); - }); - - }); - /** * Create wishlist */ diff --git a/src/pages/wish.php b/src/pages/wish.php index f7b23762..c4915805 100644 --- a/src/pages/wish.php +++ b/src/pages/wish.php @@ -147,12 +147,12 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;