Wish adding wish not working

This commit is contained in:
grandeljay 2022-11-25 12:22:11 +01:00
parent 36d83b456f
commit fc88075bfc
3 changed files with 41 additions and 66 deletions

View file

@ -83,7 +83,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
* Save wish * Save wish
*/ */
if ( if (
empty($_POST['wish_title']) empty($_POST['wish_title'])
&& empty($_POST['wish_description']) && empty($_POST['wish_description'])
&& empty($_POST['wish_url']) && empty($_POST['wish_url'])
) { ) {

View file

@ -400,7 +400,7 @@ $(function () {
method : 'PUT', method : 'PUT',
data : { data : {
'wish_id' : card.attr('data-id'), 'wish_id' : card.attr('data-id'),
'wish_status' : wishthis.strings.wish.status.fulfilled, 'wish_status' : wishthis.strings.modal.wish.status.fulfilled,
}, },
on : 'now', on : 'now',
onSuccess : function(response, element, xhr) { onSuccess : function(response, element, xhr) {
@ -505,16 +505,16 @@ $(function () {
modalDefault modalDefault
.modal({ .modal({
title : wishthis.strings.wish.delete.title, title : wishthis.strings.modal.wish.delete.title,
content : wishthis.strings.wish.delete.content, content : wishthis.strings.modal.wish.delete.content,
class : 'tiny', class : 'tiny',
actions : [ actions : [
{ {
text : wishthis.strings.wish.delete.approve, text : wishthis.strings.modal.wish.delete.approve,
class: 'approve primary' class: 'approve primary'
}, },
{ {
text: wishthis.strings.wish.delete.deny text: wishthis.strings.modal.wish.delete.deny
} }
], ],
autoShow : true, autoShow : true,
@ -752,69 +752,46 @@ $(function () {
} }
}); });
} else { } else {
/** Save form edit fields */ insertWish(formAddOrEdit, modalAddOrEdit, buttonAddOrSave);
/** 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');
});
/** */
} }
}) })
.catch(handleFetchCatch); .catch(handleFetchCatch);
} else { } else {
/** Save form edit fields */ insertWish(formAddOrEdit, modalAddOrEdit, buttonAddOrSave);
/** 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');
});
/** */
} }
} }
/**
* 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 * Update URL
*/ */

View file

@ -139,9 +139,7 @@ class Page
* Install * Install
*/ */
if (!isset($options) || !$options || !$options->getOption('isInstalled')) { if (!isset($options) || !$options || !$options->getOption('isInstalled')) {
global $page; if ('api' !== $this->name) {
if ('api' !== $page) {
redirect(Page::PAGE_INSTALL); redirect(Page::PAGE_INSTALL);
} }
} }
@ -190,7 +188,7 @@ class Page
/** /**
* Redirect * Redirect
*/ */
if ($options && $options->getOption('isInstalled') && isset($_GET)) { if ($options && $options->getOption('isInstalled') && isset($_GET) && 'api' !== $this->name) {
$url = new URL($_SERVER['REQUEST_URI']); $url = new URL($_SERVER['REQUEST_URI']);
if ($url->url && false === $url->isPretty()) { if ($url->url && false === $url->isPretty()) {