Archived
1
0
Fork 0

Add confirmation on command/sandwich suppression

This commit is contained in:
Ethanell 2020-08-20 20:45:23 +02:00
parent 63264d8f94
commit 4201eae888
3 changed files with 7 additions and 4 deletions

View file

@ -0,0 +1,5 @@
document.querySelectorAll(".order form")
.forEach(e => e.addEventListener("submit", ev => {
if (!confirm("Do you really want to remove this ?"))
ev.preventDefault();
}));

View file

@ -28,11 +28,7 @@ router.get("/", sessionCheck(3), async (req, res) => {
try {
let sandwich = await models.SandwichOrder.findByPk(req.body.id);
let order = await models.Order.findByPk(sandwich.OrderId, {include: models.Sandwich});
await sandwich.destroy();
await order.reload();
if (!order.Sandwiches.length)
await order.destroy();
res.redirect("/admin/orders");
} catch (e) {
error(req, res, "Fail to remove sandwich !");

View file

@ -18,3 +18,5 @@ block content
form(action="/admin/orders/sandwich/delete" method="POST")
input.hide(type="number" name="id" value=sandwich.SandwichOrder.id)
input(type="submit" value="x")
script(src="/javascripts/admin/orders.js")