Archived
1
0
Fork 0

Orders management rework

This commit is contained in:
Ethanell 2020-09-28 22:55:35 +02:00
parent cd6d224940
commit 84cd60e52c
10 changed files with 190 additions and 151 deletions

View file

@ -71,7 +71,8 @@
"firstDate": "First date", "firstDate": "First date",
"lastDate": "Last date", "lastDate": "Last date",
"paid": "Paid", "paid": "Paid",
"given": "Given" "given": "Given",
"chooseUser": "Choose an user"
}, },
"payment": { "payment": {
"successful": "Payment successful !", "successful": "Payment successful !",

View file

@ -71,7 +71,8 @@
"firstDate": "Première date", "firstDate": "Première date",
"lastDate": "Dernière date", "lastDate": "Dernière date",
"paid": "Payé", "paid": "Payé",
"given": "Donné" "given": "Donné",
"chooseUser": "Choisissez un utilisateur"
}, },
"payment": { "payment": {
"successful": "Paiement réussi !", "successful": "Paiement réussi !",

View file

@ -1,40 +1,59 @@
const orderAction = document.getElementById("order-action"); const orders = document.getElementById("orders");
const rmButton = document.getElementById("remove-order"); const sandwich = document.getElementById("sandwich");
const day = document.getElementById("day");
const locals = { const locals = {
order: document.querySelector("#order1>h2").innerHTML.replace(" 1", ""), sandwich: document.querySelector("#oderCreator label").innerHTML,
sandwich: document.querySelector("label[for='sandwich1']").innerHTML, day: document.querySelector("label[for=day]").innerText,
day: document.querySelector("label[for='day1']").innerHTML give: document.querySelector("p label span").innerText
}; };
function lastOrderId() { function lastOrderId() {
let list = document.querySelectorAll("div.order h2"); if (orders.lastChild)
return parseInt(list[list.length-1].innerText.replace(locals.order+" ", "")); 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; let id = lastOrderId() + 1;
orderAction.insertAdjacentHTML("beforebegin", `<div id="order${id}" class="order">
<h2>${locals.order} ${id}</h2> orders.insertAdjacentHTML("beforeend", `<div id="order${id}" class="row">
<div class="field"> <div class="input-field col s6">
<input id="sandwich${id}" type="text" name="sandwiches[${id}]" value="${sandwich.value}" readonly required>
<label for="sandwich${id}">${locals.sandwich}</label> <label for="sandwich${id}">${locals.sandwich}</label>
<span class="list_arrow"><input id="sandwich${id}" type="list" list="sandwich-list" name="sandwiches[${id}]" autocomplete="off" required></span>
</div> </div>
<div class="field"> <div class="input-field col s6">
<label for="day${id}">${locals.day}</label> <input id="date${id}" type="date" name="dates[${id}]" value="${day.value}" readonly required>
<input id="day${id}" type="date" name="dates[${id}]" required> <label for="date${id}">${locals.day}</label>
</div> </div>
<div class="field"> <div class="input-field col s12 center">
<label for="give${id}">${locals.day}</label> <p>
<input id="give${id}" type="checkbox" name="give[${id}]"> <label>
<input type="checkbox" name="give[${id}]">
<span>${locals.give}</span>
</label>
</p>
</div> </div>
<a class="btn-floating btn-large waves-effect waves-light red"><i class="material-icons">remove</i></a>
</div>`); </div>`);
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", () => { document.querySelector("form").addEventListener("submit", () => {
let id = lastOrderId(); return lastOrderId();
document.getElementById("order"+id).remove();
if (id === 2)
rmButton.classList.add("hide");
}); });

View file

@ -0,0 +1,3 @@
for (let e of document.getElementById("orders").children) {
e.querySelector("a").addEventListener("click", () => e.remove());
}

View file

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

View file

@ -18,8 +18,6 @@ document.getElementById("addOrder").addEventListener("click", () => {
let id = lastOrderId() + 1; let id = lastOrderId() + 1;
//ToDo submit button check
orders.insertAdjacentHTML("beforeend", `<div id="order${id}" class="row"> orders.insertAdjacentHTML("beforeend", `<div id="order${id}" class="row">
<div class="input-field col s6"> <div class="input-field col s6">
<input id="sandwich${id}" type="text" name="sandwiches[${id}]" value="${sandwich.value}" readonly required> <input id="sandwich${id}" type="text" name="sandwiches[${id}]" value="${sandwich.value}" readonly required>

View file

@ -1,56 +1,59 @@
extends ../../layout extends ../../layout
block content block content
div.card span#dummy.hide=__("admin.given")
div.container
h1=__("admin.ordersManagement") h1=__("admin.ordersManagement")
form#order(method="POST") div.row
div.field form#order.col.s12(method="POST")
label(for="department")=__("department") + ":" div.row
+list("department", "department-list", "department", "", "off", true) div.input-field.col.s12
datalist#department-list select(name="department" required)
each department in departments option(value="" disabled selected hidden)=__("chooseDepartment")
option(value=department.name) each department in departments
option(value=department.name)=department.name
label=__("department") + ":"
div.field div.row
label(for="firstname")=__("firstName") + ":" div.input-field.col.s12
input#firstname(type="text" name="firstName" required) select(name="username")
div.field option(value="" disabled selected hidden)=__("admin.chooseUser")
label(for="lastname")=__("lastName") + ":" each user in users
input#lastname(type="text" name="lastName" required) option(value=user.username)=user.username
label=__("username") + ":"
div.field div.row
label(for="username")=__("username") div.input-field.col.s6
+list("username", "usernames", "username", "", "off") 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 div#oderCreator.row
h2=__("order") + " 1" h5=__("order")
div.field div.input-field.col.s6
label(for="sandwich1")=__("sandwich") + ":" select#sandwich
+list("sandwich1", "sandwich-list", "sandwiches[1]", "", "off", true) option(value="" disabled selected hidden)=__("index.chooseSandwich")
div.field each sandwich in sandwiches
label(for="day1")=__("index.day") + ":" option(value=sandwich.name)=sandwich.name
input#day1(type="date" name="dates[1]" required) label=__("sandwich") + ":"
div.field div.input-field.col.s6
label(for="given1")=__("admin.given") input#day(type="date")
input#given1(type="checkbox" name="give[1]") label(for="day")=__("index.day") + ":"
a#addOrder.btn-floating.btn-large.waves-effect.waves-light.blue: i.material-icons add
div#order-action div#orders
a#add-order +
a#remove-order.hide -
div.field div.row.center
label(for="paid")=__("admin.paid") div.input-field.col.s12
input#paid(type="checkbox" name="paid") p
label(for="paid")
div.field input#paid(type="checkbox" name="paid")
input#send(type="submit" value=__("admin.add")) span=__("admin.paid")
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
+submit(__("admin.add"))
script(src="/javascripts/admin/orders/add.js") script(src="/javascripts/admin/orders/add.js")

View file

@ -1,14 +1,17 @@
extends ../../layout extends ../../layout
block content block content
div.card#ordersManagement div.container
h1=__("admin.ordersDate") h1=__("admin.ordersDate")
form(action="/admin/orders/date" method="POST") div.row
div.field form(action="/admin/orders/date" method="POST")
label(for="firstDate")=__("admin.firstDate") div.row
input#firstDate(type="date" name="firstDate" value=date? date.firstDate: "" required) div.input-field.col.s6
div.field label(for="firstDate")=__("admin.firstDate")
label(for="lastDate")=__("admin.lastDate") input#firstDate(type="date" name="firstDate" value=date? date.firstDate: "" required)
input#lastDate(type="date" name="lastDate" value=date? date.lastDate: "" required) div.input-field.col.s6
div.field label(for="lastDate")=__("admin.lastDate")
input(type="submit" value=__("save")) input#lastDate(type="date" name="lastDate" value=date? date.lastDate: "" required)
div.row
div.input-field.col.s12
+submit(__("save"))

View file

@ -1,63 +1,75 @@
extends ../../layout extends ../../layout
block content block content
div.card div.container
h1=__("admin.ordersManagement") h1=__("admin.ordersManagement")
form#order(method="POST") div.row
input(type="hidden" name="id" value=order.id) form#order.col.s12(method="POST")
div.field input(type="hidden" name="id" value=order.id)
label(for="department")=__("department") + ":" div.row
+list("department", "department-list", "department", order.Department.name, "off", true) div.input-field.col.s12
datalist#department-list select(name="department" required)
each department in departments each department in departments
option(value=department.name) option(value=department.name selected=order.Department.name === department.name)=department.name
label=__("department") + ":"
div.field div.row
label(for="firstname")=__("firstName") + ":" div.input-field.col.s12
input#firstname(type="text" name="firstName" value=order.firstName required) select(name="username")
div.field each user in users
label(for="lastname")=__("lastName") + ":" option(value=user.username selected=order.User && order.User.username === user.username)=user.username
input#lastname(type="text" name="lastName" value=order.lastName required) label=__("username") + ":"
div.field div.row
label(for="username")=__("username") div.input-field.col.s6
+list("username", "usernames", "username", order.User ? order.User.username : "", "off") 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; div#oderCreator.row
each sandwich in order.Sandwiches h5=__("order")
- i++; div.input-field.col.s6
div.order(id="order"+i) select#sandwich
h2=__("order") + " " + i option(value="" disabled selected hidden)=__("index.chooseSandwich")
div.field each sandwich in sandwiches
label(for="sandwich"+i)=__("sandwich") + ":" option(value=sandwich.name)=sandwich.name
+list("#sandwich"+i, "sandwich-list", "sandwiches["+i+"]", sandwich.name, "off", true) label=__("sandwich") + ":"
div.field div.input-field.col.s6
label(for="day"+i)=__("index.day") + ":" input#day(type="date")
input(id="#day"+i type="date" name="dates["+i+"]" value=sandwich.SandwichOrder.date required) label(for="day")=__("index.day") + ":"
div.field a#addOrder.btn-floating.btn-large.waves-effect.waves-light.blue: i.material-icons add
label(for="given"+i)=__("admin.given")
input(id="given"+i type="checkbox" name="give["+i+"]" checked=sandwich.SandwichOrder.give)
div#order-action div#orders
a#add-order + - i = 0;
if i > 1 each sandwich in order.Sandwiches
a#remove-order - - i++;
else div.row(id="order"+i)
a#remove-order.hide - 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 div.row.center
label(for="paid")=__("admin.paid") div.input-field.col.s12
input#paid(type="checkbox" name="paid" checked=order.paid) p
label(for="paid")
div.field input#paid(type="checkbox" name="paid" checked=order.paid)
input#send(type="submit" value=__("save")) span=__("admin.paid")
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
+submit(__("save"))
script(src="/javascripts/admin/orders/add.js") script(src="/javascripts/admin/orders/add.js")
script(src="/javascripts/admin/orders/edit.js")

View file

@ -1,23 +1,23 @@
extends ../../layout extends ../../layout
block content block content
div.card#ordersManagement div.container
h1=__("admin.ordersManagement") h1=__("admin.ordersManagement")
a.add(href="/admin/orders/add") ul.collection
button=__("admin.add")
div
each order in orders each order in orders
div.order li.collection-item
div.title div #{order.id} | #{order.firstName} #{order.lastName} - #{order.price}€
h2=order.id div.secondary-content
h3 #{order.firstName} #{order.lastName} - #{order.price}€ a(href="/admin/orders/edit?id=" + order.id)
each sandwich in order.Sandwiches i.material-icons edit
div.sandwich a.delete(href="/admin/orders/delete?id=" + order.id)
i.material-icons remove
each sandwich in order.Sandwiches
p #{sandwich.name} - #{sandwich.SandwichOrder.date} p #{sandwich.name} - #{sandwich.SandwichOrder.date}
div.buttons
a.edit(href="/admin/orders/edit?id=" + order.id)
button=__("admin.edit") div.fixed-action-btn
a.remove(href="/admin/orders/delete?id=" + order.id) a.btn-floating.btn-large.blue(href="/admin/orders/add")
button=__("admin.remove") i.large.material-icons add
script(src="/javascripts/admin/orders/index.js") script(src="/javascripts/admin/orders/index.js")