diff --git a/public/javascripts/orders.js b/public/javascripts/orders.js index cc92cb2..aa83013 100644 --- a/public/javascripts/orders.js +++ b/public/javascripts/orders.js @@ -1,25 +1,17 @@ const date = document.getElementById("date"); - -function collapse(e, subDiv) { +document.querySelectorAll("h4").forEach((e) => { e.addEventListener("click", ev => { ev.stopPropagation(); let action; - if (e.classList.contains("collapse")) + if (e.classList.contains("collapsed")) action = "remove"; else action = "add"; - e.querySelectorAll("."+subDiv).forEach(e => e.classList[action]("hide")); - e.classList[action]("collapse"); + e.parentElement.querySelectorAll(".collection").forEach(c => c.classList[action]("hide")); + e.classList[action]("collapsed"); }) -} - - -document.querySelectorAll(".department").forEach(e => collapse(e, "user")); - -document.querySelectorAll(".user").forEach(e => collapse(e, "order")); - -document.querySelectorAll(".order").forEach(e => collapse(e, "sandwich")); +}); date.addEventListener("change", () => window.location.href = "?date="+date.value); diff --git a/routes/orders.js b/routes/orders.js index e56f90d..b0d95f7 100644 --- a/routes/orders.js +++ b/routes/orders.js @@ -30,11 +30,11 @@ router.get("/", sessionCheck(2), async (req, res) => { orders[o.DepartmentName][name][o.id] = o.Sandwiches; } res.render("orders", {title: "SOD - Orders", orders: orders, date: date}); -}).post("/give", sessionCheck(2), async (req, res) => { - if (!req.body.id) +}).get("/give", sessionCheck(2), async (req, res) => { + if (!req.query.id) return error(req, res, "Missing arg !", 400); - let order = await models.SandwichOrder.findByPk(req.body.id, {where: {give: false}}); + let order = await models.SandwichOrder.findByPk(req.query.id, {where: {give: false}}); if (!order) return error(req, res, "Invalid order id !", 400); diff --git a/views/orders.pug b/views/orders.pug index 8581691..82c0b1a 100644 --- a/views/orders.pug +++ b/views/orders.pug @@ -1,25 +1,22 @@ extends layout block content - div#date-selector.card + div.container label(for="date")=__("date") input#date(type="date" value=date) - div#orders.card + div.container h1=__("orders") each user, department in orders - div.department - h2= department + div.container + h4=department each orders, name in user - div.user - h3= name - each order, id in orders - div.order - h4 #{__("order")} N°#{id} - each sandwich in order - div.sandwich - form.give(method="POST" action="/orders/give") - input(type="hidden" name="id" value=sandwich.SandwichOrder.id) - input.give(type="submit" value="v") - h4= sandwich.name + each order, id in orders + ul.collection.with-header + li.collection-header: h5 #{name} - #{__("order")} N°#{id} + each sandwich in order + li.collection-item + div=sandwich.name + a.secondary-content(href="/orders/give?id="+sandwich.SandwichOrder.id) + i.material-icons check script(src="/javascripts/orders.js") diff --git a/views/sandwiches.pug b/views/sandwiches.pug index 356e561..4010ee7 100644 --- a/views/sandwiches.pug +++ b/views/sandwiches.pug @@ -1,13 +1,15 @@ extends layout block content - div#date-selector.card + div.container label(for="date")=__("date") input#date(type="date" value=date) - div.card + div.container h1=__("sandwiches") - each sandwich in sandwiches - div.sandwich - h2 #{sandwich.name}: #{sandwich.dataValues.number} + ul.collection + each sandwich in sandwiches + li.collection-item + div=sandwich.name + a.secondary-content=sandwich.dataValues.number script(src="/javascripts/sandwiches.js")