From 6ccd38cc9b6e9c66433e733b496862d52b04478d Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Fri, 11 Mar 2022 15:56:42 +0100 Subject: [PATCH] Refactor --- src/assets/js/default.js | 42 ++++++++++---------- src/assets/js/wish.js | 14 +++---- src/assets/js/wishlist.js | 78 +++++++++++++++++++------------------- src/assets/js/wishlists.js | 20 +++++----- 4 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/assets/js/default.js b/src/assets/js/default.js index 0d039f34..d69b7128 100644 --- a/src/assets/js/default.js +++ b/src/assets/js/default.js @@ -55,17 +55,17 @@ $(function() { $('body') .modal({ - title: 'Failure', - content: response, - class: '', - actions: [ + title : 'Failure', + content : response, + class : '', + actions : [ { text: 'Thanks for nothing', class: 'primary' } - ] - }) - .modal('show'); + ], + autoShow: true + }); } $.fn.api.settings.onError = function(response, element, xhr) { if ('string' === typeof response) { @@ -74,17 +74,17 @@ $(function() { $('body') .modal({ - title: 'Error', - content: response, - class: '', - actions: [ + title : 'Error', + content : response, + class : '', + actions : [ { text: 'Thanks for nothing', class: 'primary' } - ] - }) - .modal('show'); + ], + autoShow: true + }); } /** */ @@ -147,15 +147,15 @@ function showError(error) { $('body') .modal({ - title: 'Error', - content: error, - class: '', - actions: [ + title : 'Error', + content : error, + class : '', + actions : [ { text: 'Thanks for nothing', class: 'primary' } - ] - }) - .modal('show'); + ], + autoShow: true + }); } diff --git a/src/assets/js/wish.js b/src/assets/js/wish.js index 0695dab8..bc448999 100644 --- a/src/assets/js/wish.js +++ b/src/assets/js/wish.js @@ -21,7 +21,8 @@ $(function () { modalAutoFill .modal({ - onApprove: function(buttonApprove) { + autoShow : true, + onApprove: function() { formWish.addClass('loading'); fetch('/src/api/wishes.php?wish_url=' + inputURL.val(), { @@ -74,6 +75,7 @@ $(function () { elementModalFetch .modal({ + autoShow: true, onApprove: function (buttonFetch) { var formData = new URLSearchParams(); formData.append('wish_url_current', inputURL.val()); @@ -103,8 +105,7 @@ $(function () { onHide: function() { formWish.removeClass('loading'); } - }) - .modal('show'); + }); } else { $('body').toast({ class: 'primary', @@ -116,8 +117,7 @@ $(function () { }) .catch(handleFetchCatch); } - }) - .modal('show'); + }); }); @@ -129,6 +129,7 @@ $(function () { modalImage .modal({ + autoShow: true, onApprove: function() { var newImageURL = modalImage.find('[name="wish_image"]').val(); @@ -140,8 +141,7 @@ $(function () { message: 'Don\'t forget to save your changes.' }); } - }) - .modal('show'); + }); }); /** diff --git a/src/assets/js/wishlist.js b/src/assets/js/wishlist.js index ab0a22bd..d626e878 100644 --- a/src/assets/js/wishlist.js +++ b/src/assets/js/wishlist.js @@ -22,57 +22,57 @@ $(function() { class: 'deny' } ], + autoShow: true, onApprove: function() { window.close(); }, onDeny: function() { $('.wishlist-own').slideUp(); } - }) - .modal('show'); + }); } /** * Commit to Wish */ $(document).on('click', '.ui.button.commit', function() { - var button = $(this); - var card = button.closest('.ui.card'); - var column = card.closest('.column'); + var button = $(this); + var card = button.closest('.ui.card'); + var column = card.closest('.column'); - $('body') - .modal({ - title: 'Really commit?', - content: 'Would you really like to commit to this purchase? It will no longer appear in the wishlist for others anymore.', - class: 'tiny', - actions: [ - { - text: 'Yes, commit', - class: 'approve primary' - }, - { - text: 'Cancel', - class: '' + $('body') + .modal({ + title: 'Really commit?', + content: 'Would you really like to commit to this purchase? It will no longer appear in the wishlist for others anymore.', + class: 'tiny', + actions: [ + { + text: 'Yes, commit', + class: 'approve primary' + }, + { + text: 'Cancel', + class: '' + } + ], + autoShow : true, + onApprove: function() { + /** + * Update wish status + */ + button.api({ + action: 'update wish status', + method: 'PUT', + data: { + wish_id: card.data('id'), + wish_status: 'unavailable' + }, + on: 'now', + onSuccess: function(response, element, xhr) { + column.fadeOut(); + }, + }); } - ], - onApprove: function() { - /** - * Update wish status - */ - button.api({ - action: 'update wish status', - method: 'PUT', - data: { - wish_id: card.data('id'), - wish_status: 'unavailable' - }, - on: 'now', - onSuccess: function(response, element, xhr) { - column.fadeOut(); - }, - }); - } - }) - .modal('show'); -}); + }); + }); }); diff --git a/src/assets/js/wishlists.js b/src/assets/js/wishlists.js index d8d23d2f..7bd2e690 100644 --- a/src/assets/js/wishlists.js +++ b/src/assets/js/wishlists.js @@ -182,6 +182,7 @@ $(function () { modalRename .modal({ + autoShow: true, onApprove: function(buttonApprove) { buttonApprove.addClass('loading disabled'); @@ -207,8 +208,7 @@ $(function () { return false; } - }) - .modal('show'); + }); }); /** @@ -235,6 +235,7 @@ $(function () { class: 'deny' }, ], + autoShow : true, onApprove: function (buttonApprove) { buttonApprove.addClass('loading'); @@ -268,8 +269,7 @@ $(function () { */ return false; } - }) - .modal('show'); + }); } }); @@ -296,6 +296,7 @@ $(function () { text: 'Cancel' } ], + autoShow: true, onApprove: function (buttonApprove) { buttonApprove.addClass('loading'); @@ -328,8 +329,7 @@ $(function () { */ return false; } - }) - .modal('show'); + }); }); /** @@ -341,6 +341,7 @@ $(function () { modalWishlistWishAdd.find('[name="wishlist_id"]').val($('.ui.dropdown.wishlists').dropdown('get value')); modalWishlistWishAdd .modal({ + autoShow : true, onApprove: function (buttonAdd) { buttonAdd.addClass('loading'); @@ -368,8 +369,7 @@ $(function () { return false; } - }) - .modal('show'); + }); }); /** @@ -381,6 +381,7 @@ $(function () { modalWishlistCreate .modal({ + autoShow: true, onApprove: function (buttonCreate) { const formData = new URLSearchParams(new FormData(formWishlistCreate[0])); @@ -410,8 +411,7 @@ $(function () { return false; } - }) - .modal('show'); + }); }); });