Add wishlist-delete

This commit is contained in:
Jay Trees 2022-01-17 16:06:17 +01:00
parent e60e82d522
commit 8913337de7
4 changed files with 91 additions and 11 deletions

View file

@ -32,6 +32,16 @@ switch ($_SERVER['REQUEST_METHOD']) {
$response['success'] = true;
}
break;
case 'DELETE':
parse_str(file_get_contents("php://input"), $_DELETE);
$database->query('DELETE FROM `wishlists`
WHERE `id` = ' . $_DELETE['wishlistID'] . '
;');
$response['success'] = true;
break;
}
echo json_encode($response);

View file

@ -8,24 +8,26 @@ $(function() {
* Fomantic UI
*/
$.fn.api.settings.api = {
'get wishlists' : '/includes/api/wishlists.php'
'get wishlists' : '/includes/api/wishlists.php',
'delete wishlist' : '/includes/api/wishlists.php'
};
$('.ui.dropdown.wishlists').dropdown({
filterRemoteData: true
});
wishlistRefresh();
});
function wishlistRefresh() {
$('.ui.dropdown.wishlists').api({
action: 'get wishlists',
method: 'GET',
on: 'now',
onResponse: function(response) {
console.log('onResponse');
// make some adjustments to response
return response;
},
successTest: function(response) {
console.log('successTest');
return response.success || false;
},
onComplete: function(response, element, xhr) {
@ -54,4 +56,4 @@ $(function() {
// navigated to a new page, CORS issue, or user canceled request
}
});
});
}

View file

@ -1,7 +1,75 @@
$(function() {
/**
* Delete Wishlist
*/
$('.ui.dropdown.wishlists').on('change', function() {
$('[name="wishlist_delete_id"]').val(
$('.ui.dropdown.wishlists').dropdown('get value')
);
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
$('[name="wishlist_delete_id"]').val(wishlistValue);
if (wishlistValue) {
$('.wishlist-view').removeClass('disabled');
$('.wishlist-delete button').removeClass('disabled');
} else {
$('.wishlist-view').addClass('disabled');
$('.wishlist-delete button').addClass('disabled');
}
});
$('.wishlist-delete').on('submit', function(event) {
var wishlistValue = $('.ui.dropdown.wishlists').dropdown('get value');
if (wishlistValue) {
$('body')
.modal({
title: 'Really delete?',
class: 'tiny',
content: 'Do you really want to delete the wishlist <strong>' + $('.ui.dropdown.wishlists').dropdown('get text') + '</strong>?',
actions: [
{
text: 'Yes, delete',
class: 'approve red'
},
{
text: 'No, keep',
class: 'deny'
},
],
onApprove: function() {
$('.ui.dropdown.wishlists').api({
action: 'delete wishlist',
method: 'DELETE',
data: {
wishlistID: wishlistValue
},
on: 'now',
onResponse: function(response) {
return response;
},
successTest: function(response) {
return response.success || false;
},
onComplete: function(response, element, xhr) {
},
onSuccess: function(response, element, xhr) {
wishlistRefresh();
},
onFailure: function(response, element, xhr) {
},
onError: function(errorMessage, element, xhr) {
},
onAbort: function(errorMessage, element, xhr) {
}
});
}
})
.modal('show');
}
event.preventDefault();
});
});

View file

@ -51,7 +51,7 @@ if (isset($_POST['wishlist_delete_id'])) {
</select>
</div>
<input class="ui primary button" type="submit" value="View" />
<input class="ui primary button wishlist-view disabled" type="submit" value="View" />
</form>
</div>
@ -64,10 +64,10 @@ if (isset($_POST['wishlist_delete_id'])) {
Share
</button>
<form class="ui form" method="post" style="display: inline-block;">
<form class="ui form wishlist-delete" method="post" style="display: inline-block;">
<input type="hidden" name="wishlist_delete_id" />
<button class="ui small labeled red icon button" type="submit">
<button class="ui small labeled red icon button disabled" type="submit">
<i class="trash icon"></i>
Delete
</button>