Switch-construction in click

This commit is contained in:
2026-01-03 18:33:53 +03:00
parent cd1f3a1e87
commit 08ddf65ec1

View File

@@ -418,7 +418,7 @@ function initializeApp() {
];
if (requiredElements.some((element) => !element)) {
console.error('Missing required elements. Проверьте разметку страницы.');
console.error('Missing required elements.');
return;
}
@@ -510,87 +510,87 @@ function initializeApp() {
} = event.target.dataset;
try {
if (action === 'delete-order') {
await fetchJson(`/api/orders/${id}`, {
method: 'DELETE'
});
await refreshData();
return;
}
if (action === 'edit-order') {
const newName = prompt('Введите новое ФИО заказчика', '');
if (newName === null) {
switch (action) {
case 'delete-order': {
await fetchJson(`/api/orders/${id}`, {
method: 'DELETE'
});
await refreshData();
return;
}
const newDate = prompt('Введите дату заказа (YYYY-MM-DD)', currentDate);
if (!newDate) {
case 'edit-order': {
const newName = prompt('Введите новое ФИО заказчика', '');
if (newName === null) {
return;
}
const newDate = prompt('Введите дату заказа (YYYY-MM-DD)', currentDate);
if (!newDate) {
return;
}
Date
await fetchJson(`/api/orders/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
customerName: newName,
orderDate: newDate
})
});
await refreshData();
return;
}
Date
await fetchJson(`/api/orders/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
customerName: newName,
orderDate: newDate
})
});
await refreshData();
return;
}
case 'save-item': {
const quantityInput = ordersContainer.querySelector(
`[data-action="item-quantity"][data-item-id="${itemId}"]`
);
const productSelect = ordersContainer.querySelector(
`[data-action="item-product"][data-item-id="${itemId}"]`
);
if (action === 'save-item') {
const quantityInput = ordersContainer.querySelector(
`[data-action="item-quantity"][data-item-id="${itemId}"]`
);
const productSelect = ordersContainer.querySelector(
`[data-action="item-product"][data-item-id="${itemId}"]`
);
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
productId: productSelect.value,
quantity: Number.parseInt(quantityInput.value, 10)
})
});
await refreshData();
return;
}
if (action === 'delete-item') {
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
method: 'DELETE'
});
await refreshData();
return;
}
if (action === 'move-item') {
const targetSelect = ordersContainer.querySelector(
`[data-action="move-target"][data-item-id="${itemId}"]`
);
if (!targetSelect.value) {
showNotification('Выберите заказ для перемещения.', 'warning');
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
productId: productSelect.value,
quantity: Number.parseInt(quantityInput.value, 10)
})
});
await refreshData();
return;
}
await fetchJson(`/api/order-items/${itemId}/move`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
targetOrderId: targetSelect.value
})
});
await refreshData();
return;
case 'delete-item': {
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
method: 'DELETE'
});
await refreshData();
return;
}
case 'move-item': {
const targetSelect = ordersContainer.querySelector(
`[data-action="move-target"][data-item-id="${itemId}"]`
);
if (!targetSelect.value) {
showNotification('Выберите заказ для перемещения.', 'warning');
return;
}
await fetchJson(`/api/order-items/${itemId}/move`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
targetOrderId: targetSelect.value
})
});
await refreshData();
return;
}
default:
return;
}
} catch (error) {
showNotification(error.message, 'warning');