Switch-construction in click
This commit is contained in:
@@ -418,7 +418,7 @@ function initializeApp() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (requiredElements.some((element) => !element)) {
|
if (requiredElements.some((element) => !element)) {
|
||||||
console.error('Missing required elements. Проверьте разметку страницы.');
|
console.error('Missing required elements.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,15 +510,15 @@ function initializeApp() {
|
|||||||
} = event.target.dataset;
|
} = event.target.dataset;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (action === 'delete-order') {
|
switch (action) {
|
||||||
|
case 'delete-order': {
|
||||||
await fetchJson(`/api/orders/${id}`, {
|
await fetchJson(`/api/orders/${id}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
await refreshData();
|
await refreshData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'edit-order': {
|
||||||
if (action === 'edit-order') {
|
|
||||||
const newName = prompt('Введите новое ФИО заказчика', '');
|
const newName = prompt('Введите новое ФИО заказчика', '');
|
||||||
if (newName === null) {
|
if (newName === null) {
|
||||||
return;
|
return;
|
||||||
@@ -541,8 +541,7 @@ function initializeApp() {
|
|||||||
await refreshData();
|
await refreshData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'save-item': {
|
||||||
if (action === 'save-item') {
|
|
||||||
const quantityInput = ordersContainer.querySelector(
|
const quantityInput = ordersContainer.querySelector(
|
||||||
`[data-action="item-quantity"][data-item-id="${itemId}"]`
|
`[data-action="item-quantity"][data-item-id="${itemId}"]`
|
||||||
);
|
);
|
||||||
@@ -563,16 +562,14 @@ function initializeApp() {
|
|||||||
await refreshData();
|
await refreshData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'delete-item': {
|
||||||
if (action === 'delete-item') {
|
|
||||||
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
|
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
await refreshData();
|
await refreshData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'move-item': {
|
||||||
if (action === 'move-item') {
|
|
||||||
const targetSelect = ordersContainer.querySelector(
|
const targetSelect = ordersContainer.querySelector(
|
||||||
`[data-action="move-target"][data-item-id="${itemId}"]`
|
`[data-action="move-target"][data-item-id="${itemId}"]`
|
||||||
);
|
);
|
||||||
@@ -592,6 +589,9 @@ function initializeApp() {
|
|||||||
await refreshData();
|
await refreshData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showNotification(error.message, 'warning');
|
showNotification(error.message, 'warning');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user