2020-08-18 17:54:00 +02:00
|
|
|
const orderAction = document.getElementById("order-action");
|
|
|
|
const rmButton = document.getElementById("remove-order");
|
2020-08-18 16:48:09 +02:00
|
|
|
const locals = {
|
2020-08-18 17:54:00 +02:00
|
|
|
order: document.querySelector("#order1>h2").innerHTML.replace(" 1", ""),
|
2020-08-18 16:48:09 +02:00
|
|
|
sandwich: document.querySelector("label[for='sandwich1']").innerHTML,
|
|
|
|
day: document.querySelector("label[for='day1']").innerHTML
|
|
|
|
};
|
2020-08-24 23:23:46 +02:00
|
|
|
const [min, max] = [document.getElementById("day1").min, document.getElementById("day1").max];
|
2020-08-14 20:08:42 +02:00
|
|
|
|
2020-08-18 17:54:00 +02:00
|
|
|
function lastOrderId() {
|
|
|
|
let list = document.querySelectorAll("div.order h2");
|
|
|
|
return parseInt(list[list.length-1].innerText.replace(locals.order+" ", ""));
|
2020-08-14 20:08:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 17:54:00 +02:00
|
|
|
document.getElementById("add-order").addEventListener("click", () => {
|
|
|
|
let id = lastOrderId() + 1;
|
|
|
|
orderAction.insertAdjacentHTML("beforebegin", `<div id="order${id}" class="order">
|
|
|
|
<h2>${locals.order} ${id}</h2>
|
2020-08-14 20:08:42 +02:00
|
|
|
<div class="field">
|
2020-08-18 16:48:09 +02:00
|
|
|
<label for="sandwich${id}">${locals.sandwich}</label>
|
2020-09-13 21:17:13 +02:00
|
|
|
<span class="list_arrow"><input id="sandwich${id}" type="list" list="sandwich-list" name="sandwiches[${id}]" autocomplete="off" required></span>
|
2020-08-14 20:08:42 +02:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-18 16:48:09 +02:00
|
|
|
<label for="day${id}">${locals.day}</label>
|
2020-09-13 18:56:13 +02:00
|
|
|
<input id="da${id}y" type="date" min="${min}" max="${max}" name="dates[${id}]" required>
|
2020-08-14 20:08:42 +02:00
|
|
|
</div>
|
|
|
|
</div>`);
|
2020-08-18 17:54:00 +02:00
|
|
|
document.getElementById("order"+lastOrderId()).scrollIntoView({behavior: "smooth"});
|
2020-08-14 20:08:42 +02:00
|
|
|
rmButton.classList.remove("hide");
|
|
|
|
});
|
|
|
|
|
|
|
|
rmButton.addEventListener("click", () => {
|
2020-08-18 17:54:00 +02:00
|
|
|
let id = lastOrderId();
|
|
|
|
document.getElementById("order"+id).remove();
|
2020-08-14 20:08:42 +02:00
|
|
|
if (id === 2)
|
|
|
|
rmButton.classList.add("hide");
|
|
|
|
});
|