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

@ -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,46 +752,25 @@ $(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 */
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('/?page=api&module=wishes', {
method : 'POST',
body : formData
fetch('/api/wishes', {
'method' : 'POST',
'body' : formData,
})
.then(handleFetchError)
.then(handleFetchResponse)
@ -811,8 +790,6 @@ $(function () {
formAddOrEdit.removeClass('loading');
buttonAddOrSave.removeClass('disabled');
});
/** */
}
}
/**

View file

@ -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()) {