mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-12-14 23:35:18 +01:00
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
/**
|
|
* On click of "delete", delete the order
|
|
* @param button_id:Integer Order id to remove
|
|
* @param table_id: Id of the table to reload
|
|
*/
|
|
function delete_button (button_id, table_id) {
|
|
$.ajax({
|
|
url: '/api/food/order/' + button_id + '/',
|
|
method: 'DELETE',
|
|
headers: { 'X-CSRFTOKEN': CSRF_TOKEN }
|
|
}).done(function () {
|
|
$('#' + table_id).load(location.pathname + ' #' + table_id + ' > *')
|
|
}).fail(function (xhr, _textStatus, _error) {
|
|
errMsg(xhr.responseJSON, 10000)
|
|
})
|
|
}
|
|
|
|
/**
|
|
* On click of "Serve", mark the order as served
|
|
* @param button_id: Order id
|
|
* @param table_id: Id of the table to reload
|
|
*/
|
|
function serve_button(button_id, table_id, current_state) {
|
|
const new_state = !current_state;
|
|
$.ajax({
|
|
url: '/api/food/order/' + button_id + '/',
|
|
method: 'PATCH',
|
|
headers: { 'X-CSRFTOKEN': CSRF_TOKEN },
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({
|
|
served: new_state
|
|
})
|
|
})
|
|
.done(function () {
|
|
console.log('done');
|
|
if (current_state) {
|
|
console.log('true');
|
|
$('table').load(location.pathname + ' table')
|
|
}
|
|
else {
|
|
console.log('false');
|
|
$('#' + table_id).load(location.pathname + ' #' + table_id + ' > *');
|
|
}
|
|
})
|
|
.fail(function (xhr) {
|
|
errMsg(xhr.responseJSON, 10000);
|
|
});
|
|
} |