From 4201eae888233b192962479d38106e1251de1b5a Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 20 Aug 2020 20:45:23 +0200 Subject: [PATCH] Add confirmation on command/sandwich suppression --- public/javascripts/admin/orders.js | 5 +++++ routes/admin/orders.js | 4 ---- views/admin/orders.pug | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 public/javascripts/admin/orders.js diff --git a/public/javascripts/admin/orders.js b/public/javascripts/admin/orders.js new file mode 100644 index 0000000..eeb95e1 --- /dev/null +++ b/public/javascripts/admin/orders.js @@ -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(); + })); diff --git a/routes/admin/orders.js b/routes/admin/orders.js index cd9c0e7..81c1ea9 100644 --- a/routes/admin/orders.js +++ b/routes/admin/orders.js @@ -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 !"); diff --git a/views/admin/orders.pug b/views/admin/orders.pug index e267522..6b04be8 100644 --- a/views/admin/orders.pug +++ b/views/admin/orders.pug @@ -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")