Client #2
150
public/app.js
150
public/app.js
@@ -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,87 +510,87 @@ function initializeApp() {
|
|||||||
} = event.target.dataset;
|
} = event.target.dataset;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (action === 'delete-order') {
|
switch (action) {
|
||||||
await fetchJson(`/api/orders/${id}`, {
|
case 'delete-order': {
|
||||||
method: 'DELETE'
|
await fetchJson(`/api/orders/${id}`, {
|
||||||
});
|
method: 'DELETE'
|
||||||
await refreshData();
|
});
|
||||||
return;
|
await refreshData();
|
||||||
}
|
|
||||||
|
|
||||||
if (action === 'edit-order') {
|
|
||||||
const newName = prompt('Введите новое ФИО заказчика', '');
|
|
||||||
if (newName === null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newDate = prompt('Введите дату заказа (YYYY-MM-DD)', currentDate);
|
case 'edit-order': {
|
||||||
if (!newDate) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
Date
|
case 'save-item': {
|
||||||
await fetchJson(`/api/orders/${id}`, {
|
const quantityInput = ordersContainer.querySelector(
|
||||||
method: 'PUT',
|
`[data-action="item-quantity"][data-item-id="${itemId}"]`
|
||||||
headers: {
|
);
|
||||||
'Content-Type': 'application/json'
|
const productSelect = ordersContainer.querySelector(
|
||||||
},
|
`[data-action="item-product"][data-item-id="${itemId}"]`
|
||||||
body: JSON.stringify({
|
);
|
||||||
customerName: newName,
|
|
||||||
orderDate: newDate
|
|
||||||
})
|
|
||||||
});
|
|
||||||
await refreshData();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action === 'save-item') {
|
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
|
||||||
const quantityInput = ordersContainer.querySelector(
|
method: 'PUT',
|
||||||
`[data-action="item-quantity"][data-item-id="${itemId}"]`
|
headers: {
|
||||||
);
|
'Content-Type': 'application/json'
|
||||||
const productSelect = ordersContainer.querySelector(
|
},
|
||||||
`[data-action="item-product"][data-item-id="${itemId}"]`
|
body: JSON.stringify({
|
||||||
);
|
productId: productSelect.value,
|
||||||
|
quantity: Number.parseInt(quantityInput.value, 10)
|
||||||
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
|
})
|
||||||
method: 'PUT',
|
});
|
||||||
headers: {
|
await refreshData();
|
||||||
'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');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetchJson(`/api/order-items/${itemId}/move`, {
|
case 'delete-item': {
|
||||||
method: 'POST',
|
await fetchJson(`/api/orders/${orderId}/items/${itemId}`, {
|
||||||
headers: {
|
method: 'DELETE'
|
||||||
'Content-Type': 'application/json'
|
});
|
||||||
},
|
await refreshData();
|
||||||
body: JSON.stringify({
|
return;
|
||||||
targetOrderId: targetSelect.value
|
}
|
||||||
})
|
case 'move-item': {
|
||||||
});
|
const targetSelect = ordersContainer.querySelector(
|
||||||
await refreshData();
|
`[data-action="move-target"][data-item-id="${itemId}"]`
|
||||||
return;
|
);
|
||||||
|
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) {
|
} catch (error) {
|
||||||
showNotification(error.message, 'warning');
|
showNotification(error.message, 'warning');
|
||||||
|
|||||||
Reference in New Issue
Block a user