I have a table with orders that is automatically generated and looks like this:
function orderHandlers() {
$.ajax({
url: "/order",
type: "GET",
contentType: "application/json",
success: function(data) {
const states = {
"new": "Не оплачен",
"paid": "Оплачен",
"assembly": "В сборке",
"delivery": "В доставке",
"delivered": "Доставлен",
"disputed": "Оспаривается"
}
for (let item of data) {
if (item.timestamp) item.datetime = new Date(item.timestamp).toLocaleString('ru-RU');
item.state = states[item.order] || "Неизвестен";
item.amount = item.amount + ' ₽';
item.actions = '';
if (item.state === 'Не оплачен') {
item.actions = `
<a href="./orderCancel.html" class="item-action-btn"> Отменить заказ </a>
`;
}
if ((item.state === 'Оплачен') || (item.state === 'В сборке') || (item.state === 'В доставке')) {
item.actions = "";
}
if (item.state === 'В сборке') {
item.actions = `<a href="" class="item-action-btn"> Задать вопрос </a>`;
}
if (item.state === 'Доставлен') {
item.actions = `<a href="" class="item-action-btn"> Связаться с менеджером </a>`;
}
}
$('.catalog-message').hide();
console.log('[Orders]', data);
renderTable('#user-orders', data, [{
data: '_id'
},
{
data: 'datetime'
},
{
data: 'state'
},
{
data: 'amount'
},
{
data: 'actions'
}
]);
$('#user-orders').show();
},
error: function(error) {
renderTable('#user-order', [], []);
console.log('[Error]', error.responseText);
showToast(error.responseText);
}
});
}
As you can see I have added a link for a cancelation option but I can't get my head around this: how do I actually cancel (pop this object out of Orders array) the order when I click on one of the 'Cancel order' buttons
Edit: added a pic of the table
