Allow editing/saving wish

This commit is contained in:
grandeljay 2023-01-28 12:24:00 +01:00
parent c8eb1a3b10
commit aa59b488dd
2 changed files with 36 additions and 1 deletions

View file

@ -174,6 +174,9 @@ $(function () {
var wish_local = wish; var wish_local = wish;
wish_edit wish_edit
.modal({
'onApprove' : wishSave,
})
.modal('show') .modal('show')
.addClass(wish_edit_size); .addClass(wish_edit_size);
@ -183,6 +186,7 @@ $(function () {
/** General */ /** General */
$('[name="wish_id"]').val(wish_local.id); $('[name="wish_id"]').val(wish_local.id);
$('[name="wishlist_id"]').val(wish_local.wishlist);
$('[name="wish_title"]').val(wish_local.title); $('[name="wish_title"]').val(wish_local.title);
$('[name="wish_description"]').val(wish_local.description); $('[name="wish_description"]').val(wish_local.description);
$('[name="wish_image"]').val(wish_local.image); $('[name="wish_image"]').val(wish_local.image);
@ -197,8 +201,38 @@ $(function () {
/** Product */ /** Product */
$('[name="wish_price"]').val(wish_local.price); $('[name="wish_price"]').val(wish_local.price);
/**
* Save values
*/
function wishSave() {
const form_wish_edit = '.ui.form.wishlist-wish-edit';
$(form_wish_edit).addClass('loading');
var wish_data = new URLSearchParams(
new FormData(
wish_edit.find(form_wish_edit)[0]
)
);
fetch('/api/wishes', {
'method' : 'POST',
'body' : wish_data,
})
.then(handleFetchError)
.then(handleFetchResponse)
.then(function(response) {
wish_edit.modal('hide');
$('body').toast({ message: wishthis.strings.toast.wish.update });
$('.ui.dropdown.filter.priority').api('query');
});
return false;
}
}); });
/** */
/** /**
* Options: Delete * Options: Delete

View file

@ -167,6 +167,7 @@ namespace wishthis;
<form class="ui form wishlist-wish-edit" method="POST"> <form class="ui form wishlist-wish-edit" method="POST">
<input type="hidden" name="wish_id" /> <input type="hidden" name="wish_id" />
<input type="hidden" name="wishlist_id" />
<?php include 'wish-add.php' ?> <?php include 'wish-add.php' ?>