Allow fulfilling wishes

This commit is contained in:
grandeljay 2023-02-08 12:40:22 +01:00
parent b338edeff7
commit efe3c87c15
5 changed files with 61 additions and 3 deletions

View file

@ -25,6 +25,7 @@
RewriteRule ^api/statistics/([a-zA-Z0-9=]+)$ /?page=api&module=statistics&table=$1 [QSA,L]
RewriteRule ^api/url/([a-zA-Z0-9=]+)$ /?page=api&module=url&url=$1 [QSA,L]
RewriteRule ^api/wishlists/([0-9]+)$ /?page=api&module=wishlists&wishlist_id=$1 [QSA,L]
RewriteRule ^api/wishlists/([0-9a-f]{40})$ /?page=api&module=wishlists&wishlist_hash=$1 [QSA,L]
</IfModule>
##-- When caching of gzipped JS and CSS files is used, enable this setting

View file

@ -297,13 +297,13 @@ switch ($_SERVER['REQUEST_METHOD']) {
$wish_status = Sanitiser::getStatus($_PUT['wish_status']);
$wish_id = Sanitiser::getNumber($_PUT['wish_id']);
if (Wish::STATUS_TEMPORARY === $status) {
$status = time();
if (Wish::STATUS_TEMPORARY === $wish_status) {
$wish_status = time();
}
$database->query(
'UPDATE `wishes`
SET `status` = :wish_status,
SET `status` = :wish_status
WHERE `id` = :wish_id',
array(
'wish_status' => $wish_status,

View file

@ -142,6 +142,17 @@ switch ($_SERVER['REQUEST_METHOD']) {
} else {
http_response_code(404);
}
} elseif (isset($_GET['wishlist_hash'])) {
/**
* Get wishlist by hash
*/
$wishlist = new Wishlist($_GET['wishlist_hash']);
if ($wishlist->exists) {
$response['results'] = $wishlist;
} else {
http_response_code(404);
}
} elseif (isset($_GET['userid']) || isset($_SESSION['user']->id)) {
/**
* Get user wishlists

View file

@ -1,4 +1,5 @@
const wish_button_mark_as_fulfilled = '.ui.button.wish-fulfilled';
const wish_button_fulfil_wish = '.ui.button.wish-fulfil';
const wish_button_visit = '.ui.button.wish-visit';
const wish_button_options = '.ui.button.wish-options';
const wish_button_options_edit = wish_button_options + ' .item.wish-edit';
@ -9,11 +10,14 @@ function wish_set_to(wish_data) {
wish = wish_data;
$(wish_button_mark_as_fulfilled).removeClass('disabled');
$(wish_button_fulfil_wish).removeClass('disabled');
if (wish.url) {
$(wish_button_visit)
.attr('href', wish.url)
.removeClass('disabled');
} else {
$(wish_button_visit).remove();
}
/**
@ -150,6 +154,36 @@ $(function () {
});
/** */
/**
* Fulfill wish
*/
$(document).on('click', wish_button_fulfil_wish, function() {
const modal_wish_details = $(this).closest('.ui.modal');
const mark_as_fulfilled = {
'method' : 'PUT',
'body' : new URLSearchParams({
'wish_id' : wish.id,
'wish_status' : wishthis.wish.status.fulfilled,
}),
}
$(this).addClass('disabled loading');
fetch('/api/wishes', mark_as_fulfilled)
.then(handleFetchError)
.then(handleFetchResponse)
.then(function(response) {
modal_wish_details.modal('hide');
$('.ui.dropdown.filter.priority').api('query');
})
.catch(handleFetchCatch)
.finally(function() {
$(this).removeClass('disabled loading');
});
});
/** */
/**
* Options: Edit
*/

View file

@ -32,6 +32,18 @@ $(function() {
});
}
/**
* Get wishlist by hash
*/
if (!wishlist && wishthis.$_GET.hash) {
fetch('/api/wishlists/' + wishthis.$_GET.hash, { method: 'GET' })
.then(handleFetchError)
.then(handleFetchResponse)
.then(function(response) {
wishlist = response.results;
});
}
/**
* Fulfil wish
*/