2020-08-14 20:08:42 +02:00
|
|
|
const commandAction = document.getElementById("command-action");
|
|
|
|
const rmButton = document.getElementById("remove-command");
|
2020-08-18 16:48:09 +02:00
|
|
|
const locals = {
|
|
|
|
command: document.querySelector("#command1>h2").innerHTML.replace(" 1", ""),
|
|
|
|
sandwich: document.querySelector("label[for='sandwich1']").innerHTML,
|
|
|
|
day: document.querySelector("label[for='day1']").innerHTML
|
|
|
|
};
|
2020-08-14 20:08:42 +02:00
|
|
|
|
|
|
|
function lastCommandId() {
|
|
|
|
let list = document.querySelectorAll("div.command h2");
|
|
|
|
return parseInt(list[list.length-1].innerText.replace("Command ", ""));
|
|
|
|
}
|
|
|
|
|
2020-08-15 11:47:36 +02:00
|
|
|
document.getElementById("add-command").addEventListener("click", () => {
|
2020-08-14 20:08:42 +02:00
|
|
|
let id = lastCommandId() + 1;
|
|
|
|
commandAction.insertAdjacentHTML("beforebegin", `<div id="command${id}" class="command">
|
2020-08-18 16:48:09 +02:00
|
|
|
<h2>${locals.command} ${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>
|
|
|
|
<input id="sandwich${id}" type="list" list="sandwich-list" name="sandwich${id}" autocomplete="off" required>
|
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>
|
|
|
|
<input id="da${id}y" type="date" name="date${id}" required>
|
2020-08-14 20:08:42 +02:00
|
|
|
</div>
|
|
|
|
</div>`);
|
|
|
|
document.getElementById("command"+lastCommandId()).scrollIntoView({behavior: "smooth"});
|
|
|
|
rmButton.classList.remove("hide");
|
|
|
|
});
|
|
|
|
|
|
|
|
rmButton.addEventListener("click", () => {
|
|
|
|
let id = lastCommandId();
|
|
|
|
document.getElementById("command"+id).remove();
|
|
|
|
if (id === 2)
|
|
|
|
rmButton.classList.add("hide");
|
|
|
|
});
|