mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-11-04 17:12:28 +01:00
Alpha version (without tests)
This commit is contained in:
46
apps/food/static/food/js/order.js
Normal file
46
apps/food/static/food/js/order.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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) {
|
||||
console.log("update")
|
||||
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 () {
|
||||
if (current_state) {
|
||||
$('table').load(location.pathname + ' table')
|
||||
}
|
||||
else {
|
||||
$('#' + table_id).load(location.pathname + ' #' + table_id + ' > *');
|
||||
}
|
||||
})
|
||||
.fail(function (xhr) {
|
||||
errMsg(xhr.responseJSON, 10000);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user