diff --git a/src/api/wishes.php b/src/api/wishes.php index 8e952312..d5105a74 100644 --- a/src/api/wishes.php +++ b/src/api/wishes.php @@ -83,7 +83,7 @@ switch ($_SERVER['REQUEST_METHOD']) { * Save wish */ if ( - empty($_POST['wish_title']) + empty($_POST['wish_title']) && empty($_POST['wish_description']) && empty($_POST['wish_url']) ) { diff --git a/src/assets/js/parts/wishlists.js b/src/assets/js/parts/wishlists.js index f9174258..dee7d331 100644 --- a/src/assets/js/parts/wishlists.js +++ b/src/assets/js/parts/wishlists.js @@ -400,7 +400,7 @@ $(function () { method : 'PUT', data : { 'wish_id' : card.attr('data-id'), - 'wish_status' : wishthis.strings.wish.status.fulfilled, + 'wish_status' : wishthis.strings.modal.wish.status.fulfilled, }, on : 'now', onSuccess : function(response, element, xhr) { @@ -505,16 +505,16 @@ $(function () { modalDefault .modal({ - title : wishthis.strings.wish.delete.title, - content : wishthis.strings.wish.delete.content, + title : wishthis.strings.modal.wish.delete.title, + content : wishthis.strings.modal.wish.delete.content, class : 'tiny', actions : [ { - text : wishthis.strings.wish.delete.approve, + text : wishthis.strings.modal.wish.delete.approve, class: 'approve primary' }, { - text: wishthis.strings.wish.delete.deny + text: wishthis.strings.modal.wish.delete.deny } ], autoShow : true, @@ -752,69 +752,46 @@ $(function () { } }); } else { - /** Save form edit fields */ - /** This code block is a duplicate, please refactor */ - var formData = new URLSearchParams(new FormData(formAddOrEdit[0])); - formData.append('wishlist_id', wishthis.$_GET.id); - - fetch('/?page=api&module=wishes', { - method : 'POST', - body : formData - }) - .then(handleFetchError) - .then(handleFetchResponse) - .then(function(response) { - if (!response.lastInsertId) { - return; - } - - $('body').toast({ message: wishthis.strings.toast.wish.update }); - - $('.ui.dropdown.wishlists').api('query'); - - modalAddOrEdit.modal('hide'); - }) - .catch(handleFetchCatch) - .finally(function() { - formAddOrEdit.removeClass('loading'); - buttonAddOrSave.removeClass('disabled'); - }); - /** */ + insertWish(formAddOrEdit, modalAddOrEdit, buttonAddOrSave); } }) .catch(handleFetchCatch); } else { - /** Save form edit fields */ - /** This code block is a duplicate, please refactor */ - var formData = new URLSearchParams(new FormData(formAddOrEdit[0])); - formData.append('wishlist_id', wishthis.$_GET.id); - - fetch('/?page=api&module=wishes', { - method : 'POST', - body : formData - }) - .then(handleFetchError) - .then(handleFetchResponse) - .then(function(response) { - if (!response.lastInsertId) { - return; - } - - $('body').toast({ message: wishthis.strings.toast.wish.update }); - - $('.ui.dropdown.wishlists').api('query'); - - modalAddOrEdit.modal('hide'); - }) - .catch(handleFetchCatch) - .finally(function() { - formAddOrEdit.removeClass('loading'); - buttonAddOrSave.removeClass('disabled'); - }); - /** */ + insertWish(formAddOrEdit, modalAddOrEdit, buttonAddOrSave); } } + /** + * Insert wish + */ + function insertWish(formAddOrEdit, modalAddOrEdit, buttonAddOrSave) { + var formData = new URLSearchParams(new FormData(formAddOrEdit[0])); + formData.append('wishlist_id', wishthis.$_GET.id); + + fetch('/api/wishes', { + 'method' : 'POST', + 'body' : formData, + }) + .then(handleFetchError) + .then(handleFetchResponse) + .then(function(response) { + if (!response.lastInsertId) { + return; + } + + $('body').toast({ message: wishthis.strings.toast.wish.update }); + + $('.ui.dropdown.wishlists').api('query'); + + modalAddOrEdit.modal('hide'); + }) + .catch(handleFetchCatch) + .finally(function() { + formAddOrEdit.removeClass('loading'); + buttonAddOrSave.removeClass('disabled'); + }); + } + /** * Update URL */ diff --git a/src/classes/page.php b/src/classes/page.php index 41d6a3fd..18d30f56 100644 --- a/src/classes/page.php +++ b/src/classes/page.php @@ -139,9 +139,7 @@ class Page * Install */ if (!isset($options) || !$options || !$options->getOption('isInstalled')) { - global $page; - - if ('api' !== $page) { + if ('api' !== $this->name) { redirect(Page::PAGE_INSTALL); } } @@ -190,7 +188,7 @@ class Page /** * Redirect */ - if ($options && $options->getOption('isInstalled') && isset($_GET)) { + if ($options && $options->getOption('isInstalled') && isset($_GET) && 'api' !== $this->name) { $url = new URL($_SERVER['REQUEST_URI']); if ($url->url && false === $url->isPretty()) {