diff --git a/locales/en.json b/locales/en.json index 3eb3839..dc3b259 100644 --- a/locales/en.json +++ b/locales/en.json @@ -71,7 +71,8 @@ "firstDate": "First date", "lastDate": "Last date", "paid": "Paid", - "given": "Given" + "given": "Given", + "chooseUser": "Choose an user" }, "payment": { "successful": "Payment successful !", diff --git a/locales/fr.json b/locales/fr.json index e3690bc..04b7836 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -71,7 +71,8 @@ "firstDate": "Première date", "lastDate": "Dernière date", "paid": "Payé", - "given": "Donné" + "given": "Donné", + "chooseUser": "Choisissez un utilisateur" }, "payment": { "successful": "Paiement réussi !", diff --git a/public/javascripts/admin/orders/add.js b/public/javascripts/admin/orders/add.js index 7955e1d..62337de 100644 --- a/public/javascripts/admin/orders/add.js +++ b/public/javascripts/admin/orders/add.js @@ -1,40 +1,59 @@ -const orderAction = document.getElementById("order-action"); -const rmButton = document.getElementById("remove-order"); +const orders = document.getElementById("orders"); +const sandwich = document.getElementById("sandwich"); +const day = document.getElementById("day"); const locals = { - order: document.querySelector("#order1>h2").innerHTML.replace(" 1", ""), - sandwich: document.querySelector("label[for='sandwich1']").innerHTML, - day: document.querySelector("label[for='day1']").innerHTML + sandwich: document.querySelector("#oderCreator label").innerHTML, + day: document.querySelector("label[for=day]").innerText, + give: document.querySelector("p label span").innerText }; function lastOrderId() { - let list = document.querySelectorAll("div.order h2"); - return parseInt(list[list.length-1].innerText.replace(locals.order+" ", "")); + if (orders.lastChild) + return parseInt(orders.lastChild.id.replace("order", "")); + return 0; } -document.getElementById("add-order").addEventListener("click", () => { +document.getElementById("addOrder").addEventListener("click", () => { + if (!sandwich.value || !day.value) + return; + let id = lastOrderId() + 1; - orderAction.insertAdjacentHTML("beforebegin", `
-

${locals.order} ${id}

-
+ + orders.insertAdjacentHTML("beforeend", `
+
+ -
-
- - +
+ +
-
- - +
+

+ +

+ remove
`); - document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"}); - rmButton.classList.remove("hide"); + + sandwich.selectedIndex = 0; + day.value = ""; + + let order = document.getElementById("order"+id); + order.querySelector("a").addEventListener("click", () => { + order.remove(); + if (lastOrderId() === 0) { + sandwich.required = true; + day.required = true; + } + }); + + document.getElementById("order"+id).scrollIntoView({behavior: "smooth"}); }); -rmButton.addEventListener("click", () => { - let id = lastOrderId(); - document.getElementById("order"+id).remove(); - if (id === 2) - rmButton.classList.add("hide"); +document.querySelector("form").addEventListener("submit", () => { + return lastOrderId(); }); diff --git a/public/javascripts/admin/orders/edit.js b/public/javascripts/admin/orders/edit.js new file mode 100644 index 0000000..1e2f9ce --- /dev/null +++ b/public/javascripts/admin/orders/edit.js @@ -0,0 +1,3 @@ +for (let e of document.getElementById("orders").children) { + e.querySelector("a").addEventListener("click", () => e.remove()); +} diff --git a/public/javascripts/admin/orders/index.js b/public/javascripts/admin/orders/index.js index eeb95e1..814efa7 100644 --- a/public/javascripts/admin/orders/index.js +++ b/public/javascripts/admin/orders/index.js @@ -1,5 +1,4 @@ -document.querySelectorAll(".order form") - .forEach(e => e.addEventListener("submit", ev => { +document.querySelectorAll(".delete").forEach(e => e.addEventListener("click", ev => { if (!confirm("Do you really want to remove this ?")) ev.preventDefault(); })); diff --git a/public/javascripts/index.js b/public/javascripts/index.js index 0211d55..047b3e4 100644 --- a/public/javascripts/index.js +++ b/public/javascripts/index.js @@ -18,8 +18,6 @@ document.getElementById("addOrder").addEventListener("click", () => { let id = lastOrderId() + 1; - //ToDo submit button check - orders.insertAdjacentHTML("beforeend", `
diff --git a/views/admin/orders/add.pug b/views/admin/orders/add.pug index 314affc..85aab6b 100644 --- a/views/admin/orders/add.pug +++ b/views/admin/orders/add.pug @@ -1,56 +1,59 @@ extends ../../layout block content - div.card + span#dummy.hide=__("admin.given") + div.container h1=__("admin.ordersManagement") - form#order(method="POST") - div.field - label(for="department")=__("department") + ":" - +list("department", "department-list", "department", "", "off", true) - datalist#department-list - each department in departments - option(value=department.name) + div.row + form#order.col.s12(method="POST") + div.row + div.input-field.col.s12 + select(name="department" required) + option(value="" disabled selected hidden)=__("chooseDepartment") + each department in departments + option(value=department.name)=department.name + label=__("department") + ":" - div.field - label(for="firstname")=__("firstName") + ":" - input#firstname(type="text" name="firstName" required) - div.field - label(for="lastname")=__("lastName") + ":" - input#lastname(type="text" name="lastName" required) + div.row + div.input-field.col.s12 + select(name="username") + option(value="" disabled selected hidden)=__("admin.chooseUser") + each user in users + option(value=user.username)=user.username + label=__("username") + ":" - div.field - label(for="username")=__("username") - +list("username", "usernames", "username", "", "off") + div.row + div.input-field.col.s6 + input#firstname(type="text" name="firstName" required) + label(for="firstname")=__("firstName") + ":" + div.input-field.col.s6 + input#lastname(type="text" name="lastName" required) + label(for="lastname")=__("lastName") + ":" - div#order1.order - h2=__("order") + " 1" - div.field - label(for="sandwich1")=__("sandwich") + ":" - +list("sandwich1", "sandwich-list", "sandwiches[1]", "", "off", true) - div.field - label(for="day1")=__("index.day") + ":" - input#day1(type="date" name="dates[1]" required) - div.field - label(for="given1")=__("admin.given") - input#given1(type="checkbox" name="give[1]") + div#oderCreator.row + h5=__("order") + div.input-field.col.s6 + select#sandwich + option(value="" disabled selected hidden)=__("index.chooseSandwich") + each sandwich in sandwiches + option(value=sandwich.name)=sandwich.name + label=__("sandwich") + ":" + div.input-field.col.s6 + input#day(type="date") + label(for="day")=__("index.day") + ":" + a#addOrder.btn-floating.btn-large.waves-effect.waves-light.blue: i.material-icons add - div#order-action - a#add-order + - a#remove-order.hide - + div#orders - div.field - label(for="paid")=__("admin.paid") - input#paid(type="checkbox" name="paid") - - div.field - input#send(type="submit" value=__("admin.add")) - - datalist#sandwich-list - each sandwich in sandwiches - option(value=sandwich.name) - datalist#usernames - each user in users - option(value=user.username) + div.row.center + div.input-field.col.s12 + p + label(for="paid") + input#paid(type="checkbox" name="paid") + span=__("admin.paid") + div.row.center + div.input-field.col.s12 + +submit(__("admin.add")) script(src="/javascripts/admin/orders/add.js") diff --git a/views/admin/orders/date.pug b/views/admin/orders/date.pug index 9b9b45f..c7f0304 100644 --- a/views/admin/orders/date.pug +++ b/views/admin/orders/date.pug @@ -1,14 +1,17 @@ extends ../../layout block content - div.card#ordersManagement + div.container h1=__("admin.ordersDate") - form(action="/admin/orders/date" method="POST") - div.field - label(for="firstDate")=__("admin.firstDate") - input#firstDate(type="date" name="firstDate" value=date? date.firstDate: "" required) - div.field - label(for="lastDate")=__("admin.lastDate") - input#lastDate(type="date" name="lastDate" value=date? date.lastDate: "" required) - div.field - input(type="submit" value=__("save")) + div.row + form(action="/admin/orders/date" method="POST") + div.row + div.input-field.col.s6 + label(for="firstDate")=__("admin.firstDate") + input#firstDate(type="date" name="firstDate" value=date? date.firstDate: "" required) + div.input-field.col.s6 + label(for="lastDate")=__("admin.lastDate") + input#lastDate(type="date" name="lastDate" value=date? date.lastDate: "" required) + div.row + div.input-field.col.s12 + +submit(__("save")) diff --git a/views/admin/orders/edit.pug b/views/admin/orders/edit.pug index 33a45b2..ced9729 100644 --- a/views/admin/orders/edit.pug +++ b/views/admin/orders/edit.pug @@ -1,63 +1,75 @@ extends ../../layout block content - div.card + div.container h1=__("admin.ordersManagement") - form#order(method="POST") - input(type="hidden" name="id" value=order.id) - div.field - label(for="department")=__("department") + ":" - +list("department", "department-list", "department", order.Department.name, "off", true) - datalist#department-list - each department in departments - option(value=department.name) + div.row + form#order.col.s12(method="POST") + input(type="hidden" name="id" value=order.id) + div.row + div.input-field.col.s12 + select(name="department" required) + each department in departments + option(value=department.name selected=order.Department.name === department.name)=department.name + label=__("department") + ":" - div.field - label(for="firstname")=__("firstName") + ":" - input#firstname(type="text" name="firstName" value=order.firstName required) - div.field - label(for="lastname")=__("lastName") + ":" - input#lastname(type="text" name="lastName" value=order.lastName required) + div.row + div.input-field.col.s12 + select(name="username") + each user in users + option(value=user.username selected=order.User && order.User.username === user.username)=user.username + label=__("username") + ":" - div.field - label(for="username")=__("username") - +list("username", "usernames", "username", order.User ? order.User.username : "", "off") + div.row + div.input-field.col.s6 + input#firstname(type="text" name="firstName" value=order.firstName required) + label(for="firstname")=__("firstName") + ":" + div.input-field.col.s6 + input#lastname(type="text" name="lastName" value=order.lastName required) + label(for="lastname")=__("lastName") + ":" - - i = 0; - each sandwich in order.Sandwiches - - i++; - div.order(id="order"+i) - h2=__("order") + " " + i - div.field - label(for="sandwich"+i)=__("sandwich") + ":" - +list("#sandwich"+i, "sandwich-list", "sandwiches["+i+"]", sandwich.name, "off", true) - div.field - label(for="day"+i)=__("index.day") + ":" - input(id="#day"+i type="date" name="dates["+i+"]" value=sandwich.SandwichOrder.date required) - div.field - label(for="given"+i)=__("admin.given") - input(id="given"+i type="checkbox" name="give["+i+"]" checked=sandwich.SandwichOrder.give) + div#oderCreator.row + h5=__("order") + div.input-field.col.s6 + select#sandwich + option(value="" disabled selected hidden)=__("index.chooseSandwich") + each sandwich in sandwiches + option(value=sandwich.name)=sandwich.name + label=__("sandwich") + ":" + div.input-field.col.s6 + input#day(type="date") + label(for="day")=__("index.day") + ":" + a#addOrder.btn-floating.btn-large.waves-effect.waves-light.blue: i.material-icons add - div#order-action - a#add-order + - if i > 1 - a#remove-order - - else - a#remove-order.hide - + div#orders + - i = 0; + each sandwich in order.Sandwiches + - i++; + div.row(id="order"+i) + div.input-field.col.s6 + input(id="sandwich"+i type="text" name="sandwiches[#{i}]" value=sandwich.name readonly required) + label(for="sandwich"+i)=__("sandwich") + div.input-field.col.s6 + input(id="date"+i type="date" name="dates[#{i}]" value=sandwich.SandwichOrder.date readonly required) + label(for="date"+i)=__("index.day") + div.input-field.col.s12.center + p + label + input(type="checkbox" name="give[#{i}]" checked=sandwich.SandwichOrder.give) + span=__("admin.given") + a.btn-floating.btn-large.waves-effect.waves-light.red + i.material-icons remove - div.field - label(for="paid")=__("admin.paid") - input#paid(type="checkbox" name="paid" checked=order.paid) - - div.field - input#send(type="submit" value=__("save")) - - datalist#sandwich-list - each sandwich in sandwiches - option(value=sandwich.name) - datalist#usernames - each user in users - option(value=user.username) + div.row.center + div.input-field.col.s12 + p + label(for="paid") + input#paid(type="checkbox" name="paid" checked=order.paid) + span=__("admin.paid") + div.row.center + div.input-field.col.s12 + +submit(__("save")) script(src="/javascripts/admin/orders/add.js") + script(src="/javascripts/admin/orders/edit.js") diff --git a/views/admin/orders/index.pug b/views/admin/orders/index.pug index 2fa516c..8adc1d6 100644 --- a/views/admin/orders/index.pug +++ b/views/admin/orders/index.pug @@ -1,23 +1,23 @@ extends ../../layout block content - div.card#ordersManagement + div.container h1=__("admin.ordersManagement") - a.add(href="/admin/orders/add") - button=__("admin.add") - div + ul.collection each order in orders - div.order - div.title - h2=order.id - h3 #{order.firstName} #{order.lastName} - #{order.price}€ - each sandwich in order.Sandwiches - div.sandwich + li.collection-item + div #{order.id} | #{order.firstName} #{order.lastName} - #{order.price}€ + div.secondary-content + a(href="/admin/orders/edit?id=" + order.id) + i.material-icons edit + a.delete(href="/admin/orders/delete?id=" + order.id) + i.material-icons remove + each sandwich in order.Sandwiches p #{sandwich.name} - #{sandwich.SandwichOrder.date} - div.buttons - a.edit(href="/admin/orders/edit?id=" + order.id) - button=__("admin.edit") - a.remove(href="/admin/orders/delete?id=" + order.id) - button=__("admin.remove") + + + div.fixed-action-btn + a.btn-floating.btn-large.blue(href="/admin/orders/add") + i.large.material-icons add script(src="/javascripts/admin/orders/index.js")