Add confirmation on command/sandwich suppression
This commit is contained in:
parent
63264d8f94
commit
4201eae888
3 changed files with 7 additions and 4 deletions
5
public/javascripts/admin/orders.js
Normal file
5
public/javascripts/admin/orders.js
Normal 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();
|
||||
}));
|
|
@ -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 !");
|
||||
|
|
|
@ -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")
|
||||
|
|
Reference in a new issue