2020-05-29 19:44:12 +02:00
|
|
|
const socket = io();
|
|
|
|
const dish = document.querySelector("#dish ul");
|
|
|
|
const ingredient = document.querySelector("#ingredient ul");
|
|
|
|
const sauce = document.querySelector("#sauce ul");
|
|
|
|
const drink = document.querySelector("#drink ul");
|
|
|
|
const dessert = document.querySelector("#dessert ul");
|
|
|
|
const list = document.querySelector(".list");
|
|
|
|
|
2020-05-31 22:23:36 +02:00
|
|
|
let current = {dish: null, ingredient: [], sauce: [], drink: null, dessert: null};
|
2020-05-29 19:44:12 +02:00
|
|
|
let radios = {dish: null, drink: null, dessert: null};
|
|
|
|
let db = {dish: {}, ingredient: {}, sauce: {}, drink: {}, dessert: {}};
|
|
|
|
|
|
|
|
|
|
|
|
function addCmd(command) {
|
|
|
|
list.insertAdjacentHTML("beforeend", `<div class="com" id="cmd${command.number}">
|
|
|
|
<button class="give">Give</button>
|
|
|
|
<h1>${command.number}</h1>
|
2020-05-29 21:47:40 +02:00
|
|
|
<div class="spec">
|
2020-05-29 19:44:12 +02:00
|
|
|
<h2>${command.sandwich}</h2>
|
|
|
|
<h3>${command.client}</h3>
|
|
|
|
<p>${command.dish}</p>
|
|
|
|
<p>${command.ingredients}</p>
|
|
|
|
<p>${command.sauces}</p>
|
|
|
|
<p>${command.drink}</p>
|
|
|
|
<p>${command.dessert}</p>
|
|
|
|
<button class="cancel">Cancel</button>
|
|
|
|
<button class="error">Error</button>
|
|
|
|
</div>
|
|
|
|
</div>`);
|
|
|
|
let e = document.querySelector(`.list #cmd${command.number}`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener( "click" ,ev => {
|
|
|
|
ev.stopPropagation();
|
|
|
|
e.classList.toggle("show-spec");
|
|
|
|
});
|
2020-05-29 19:44:12 +02:00
|
|
|
e.querySelector(".give").addEventListener("click", ev => {
|
2020-05-28 22:25:55 +02:00
|
|
|
ev.stopPropagation();
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.emit("give command", command.number);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
2020-05-29 19:44:12 +02:00
|
|
|
e.querySelector(".cancel").addEventListener("click", ev => {
|
2020-05-28 22:25:55 +02:00
|
|
|
ev.stopPropagation();
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.emit("clear command", command.number);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
2020-05-29 19:44:12 +02:00
|
|
|
e.querySelector(".error").addEventListener("click", ev => {
|
2020-05-28 22:25:55 +02:00
|
|
|
ev.stopPropagation();
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.emit("error command", command.number);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
2020-05-29 19:44:12 +02:00
|
|
|
if (command.error)
|
|
|
|
error(e)
|
|
|
|
else if (command.give)
|
|
|
|
give(e)
|
|
|
|
else if (command.done)
|
|
|
|
done(e)
|
|
|
|
else if (command.WIP)
|
|
|
|
WIP(e, command.sandwich)
|
|
|
|
document.querySelector("#resume>h1").innerHTML = `Command ${command.number+1}`;
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function addDish(d) {
|
2020-05-31 22:23:36 +02:00
|
|
|
db.dish[d.id] = d;
|
2020-05-29 19:44:12 +02:00
|
|
|
dish.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dish" id="dish${d.id}"><label for="dish${d.id}">${d.name}</label></li>`);
|
|
|
|
let e = document.querySelector(`input[id=dish${d.id}]`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener("click", () => {
|
2020-05-29 19:44:12 +02:00
|
|
|
radioCheck(e);
|
2020-05-28 22:25:55 +02:00
|
|
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
|
|
|
if (el.checked)
|
|
|
|
el.click();
|
|
|
|
});
|
|
|
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => {
|
2020-05-30 16:11:58 +02:00
|
|
|
el.disabled = !(e.checked && !(db.dish[e.id.replace(e.name, "")]["max" + el.name.charAt(0).toUpperCase() + el.name.slice(1)+"s"] === 0));
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function addIngredient(i) {
|
2020-05-31 22:23:36 +02:00
|
|
|
db.ingredient[i.id] = i;
|
2020-05-29 19:44:12 +02:00
|
|
|
ingredient.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="ingredient" id="ingredient${i.id}"><label for="ingredient${i.id}">${i.name}</label></li>`);
|
|
|
|
let e = document.querySelector(`input[id=ingredient${i.id}]`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener("click", () => {
|
2020-05-30 16:11:58 +02:00
|
|
|
checkCheck(e)
|
2020-05-28 22:25:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function addSauce(s) {
|
2020-05-31 22:23:36 +02:00
|
|
|
db.sauce[s.id] = s;
|
2020-05-29 19:44:12 +02:00
|
|
|
sauce.insertAdjacentHTML("beforeend", `<li><input type="checkbox" disabled=true name="sauce" id="sauce${s.id}"><label for="sauce${s.id}">${s.name}</label></li>`);
|
|
|
|
let e = document.querySelector(`input[id=sauce${s.id}]`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener("click", () => {
|
2020-05-30 16:11:58 +02:00
|
|
|
checkCheck(e)
|
2020-05-28 22:25:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function addDrink(d) {
|
2020-05-31 22:23:36 +02:00
|
|
|
db.drink[d.id] = d;
|
2020-05-29 19:44:12 +02:00
|
|
|
drink.insertAdjacentHTML("beforeend", `<li><input type="radio" name="drink" id="drink${d.id}"><label for="drink${d.id}">${d.name}</label></li>`);
|
|
|
|
let e = document.querySelector(`input[id=drink${d.id}]`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener("click", () => {
|
2020-05-29 19:44:12 +02:00
|
|
|
radioCheck(e)
|
2020-05-28 22:25:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function addDessert(d) {
|
2020-05-31 22:23:36 +02:00
|
|
|
db.dessert[d.id] = d;
|
2020-05-29 19:44:12 +02:00
|
|
|
dessert.insertAdjacentHTML("beforeend", `<li><input type="radio" name="dessert" id="dessert${d.id}"><label for="dessert${d.id}">${d.name}</label></li>`);
|
|
|
|
let e = document.querySelector(`input[id=dessert${d.id}]`);
|
2020-05-28 22:25:55 +02:00
|
|
|
e.addEventListener("click", () => {
|
2020-05-29 19:44:12 +02:00
|
|
|
radioCheck(e)
|
2020-05-28 22:25:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-31 23:19:00 +02:00
|
|
|
function removeDish(d) {
|
|
|
|
dish.querySelector("#dish"+d).parentElement.remove();
|
|
|
|
delete db.dish[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeIngredient(d) {
|
|
|
|
ingredient.querySelector("#ingredient"+d).parentElement.remove();
|
|
|
|
delete db.ingredient[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeSauce(d) {
|
|
|
|
sauce.querySelector("#sauce"+d).parentElement.remove();
|
|
|
|
delete db.sauce[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeDrink(d) {
|
|
|
|
drink.querySelector("#drink"+d).parentElement.remove();
|
|
|
|
delete db.drink[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeDessert(d) {
|
|
|
|
dessert.querySelector("#dessert"+d).parentElement.remove();
|
|
|
|
delete db.dessert[d];
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
function radioCheck (e) {
|
2020-05-28 22:25:55 +02:00
|
|
|
if (e.checked) {
|
|
|
|
let curr, name;
|
2020-05-29 19:44:12 +02:00
|
|
|
if (e.id.replace(e.name, "") === radios[e.name]) {
|
2020-05-28 22:25:55 +02:00
|
|
|
e.checked = false;
|
2020-05-29 19:44:12 +02:00
|
|
|
radios[e.name] = null;
|
2020-05-28 22:25:55 +02:00
|
|
|
curr = null;
|
|
|
|
name = null;
|
|
|
|
} else {
|
2020-05-29 19:44:12 +02:00
|
|
|
radios[e.name] = e.id.replace(e.name, "");
|
|
|
|
curr = e.id.replace(e.name, "");
|
2020-05-28 22:25:55 +02:00
|
|
|
name = document.querySelector(`label[for=${e.id}]`).innerHTML;
|
|
|
|
}
|
2020-05-29 19:44:12 +02:00
|
|
|
current[e.name] = curr;
|
2020-05-28 22:25:55 +02:00
|
|
|
price();
|
2020-05-29 19:44:12 +02:00
|
|
|
document.getElementById("p-"+e.name).innerHTML = name;
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:11:58 +02:00
|
|
|
function checkCheck(e) {
|
2020-05-28 22:25:55 +02:00
|
|
|
if (e.checked)
|
2020-05-29 19:44:12 +02:00
|
|
|
current[e.name].push(e.id.replace(e.name, ""));
|
2020-05-28 22:25:55 +02:00
|
|
|
else
|
2020-05-29 19:44:12 +02:00
|
|
|
current[e.name].splice(current[e.name].indexOf(e.id.replace(e.name, "")), 1);
|
|
|
|
document.querySelectorAll(`input[name=${e.name}]`).forEach( e => {
|
2020-05-28 22:25:55 +02:00
|
|
|
if (!e.checked)
|
2020-05-30 16:11:58 +02:00
|
|
|
e.disabled = current[e.name].length === db.dish[current.dish]["max"+e.name.charAt(0).toUpperCase() + e.name.slice(1)+"s"];
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
price();
|
2020-05-29 19:44:12 +02:00
|
|
|
let names = [];
|
|
|
|
current[e.name].forEach(el=>names.push(document.querySelector(`label[for=${e.name}${el}]`).innerHTML));
|
|
|
|
document.getElementById("p-"+e.name).innerHTML = names.join(" - ");
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clear(e) {
|
2020-05-29 19:44:12 +02:00
|
|
|
e.classList.remove("done");
|
|
|
|
e.classList.remove("give");
|
|
|
|
e.classList.remove("warning");
|
2020-05-28 22:25:55 +02:00
|
|
|
e.classList.remove("WIP");
|
|
|
|
e.classList.remove("show-spec");
|
|
|
|
list.prepend(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function WIP(e, name) {
|
|
|
|
e.classList.remove("show-spec");
|
|
|
|
e.classList.add("WIP");
|
|
|
|
e.querySelector("h2").innerHTML = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function done(e) {
|
|
|
|
e.classList.remove("show-spec");
|
2020-05-29 21:47:40 +02:00
|
|
|
e.classList.add("done");
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function give(e) {
|
|
|
|
e.classList.remove("show-spec");
|
2020-05-29 21:47:40 +02:00
|
|
|
e.classList.add("give");
|
2020-05-28 22:25:55 +02:00
|
|
|
list.appendChild(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function error(e) {
|
|
|
|
e.classList.remove("show-spec");
|
2020-05-29 19:44:12 +02:00
|
|
|
e.classList.add("warning");
|
2020-05-28 22:25:55 +02:00
|
|
|
list.appendChild(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function price() {
|
2020-05-30 16:48:50 +02:00
|
|
|
socket.emit("price", current);
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 15:42:04 +02:00
|
|
|
function addUser() {
|
|
|
|
let firstName, lastName;
|
|
|
|
do {
|
|
|
|
firstName = prompt("First name");
|
|
|
|
} while (firstName === "");
|
|
|
|
if (firstName) {
|
|
|
|
do {
|
|
|
|
lastName = prompt("Last name");
|
|
|
|
} while (lastName === "");
|
|
|
|
if (lastName)
|
|
|
|
socket.emit("add user", {username: current.client, firstName: firstName, lastName: lastName});
|
|
|
|
}
|
|
|
|
if (!firstName|| !lastName) {
|
|
|
|
alert("User creation aborted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addCommand() {
|
|
|
|
current.pc = null;
|
|
|
|
socket.emit("add command", current);
|
|
|
|
clearSelections();
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearSelections() {
|
|
|
|
current = {dish: null, ingredient: [], sauce: [], drink: null, dessert: null, price: {}};
|
|
|
|
document.querySelectorAll("input[name=dish],input[name=drink],input[name=dessert]").forEach( e => {
|
|
|
|
e.checked = false;
|
|
|
|
});
|
|
|
|
document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( e => {
|
|
|
|
e.checked = false;
|
|
|
|
e.disabled = true;
|
|
|
|
});
|
|
|
|
document.querySelectorAll("#resume p").forEach( e => {
|
|
|
|
e.innerHTML = ""
|
|
|
|
});
|
|
|
|
let user = document.getElementById("user");
|
|
|
|
user.value = "";
|
|
|
|
user.style.color = "";
|
|
|
|
document.getElementById("user_list").innerHTML = "";
|
|
|
|
document.querySelector("#resume h2").innerHTML = "0€";
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
socket.on("connected", () => {
|
|
|
|
socket.emit("list dish");
|
|
|
|
socket.emit("list ingredient");
|
|
|
|
socket.emit("list sauce");
|
|
|
|
socket.emit("list drink");
|
|
|
|
socket.emit("list dessert");
|
|
|
|
socket.emit("list command");
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("list command", data => {
|
|
|
|
let child = list.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
list.removeChild(child);
|
|
|
|
child = list.lastElementChild;
|
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let c of data)
|
2020-05-29 19:44:12 +02:00
|
|
|
addCmd(c);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-29 19:44:12 +02:00
|
|
|
socket.on("list dish", data => {
|
|
|
|
let child = dish.lastElementChild;
|
2020-05-28 22:25:55 +02:00
|
|
|
while (child) {
|
2020-05-29 19:44:12 +02:00
|
|
|
dish.removeChild(child);
|
|
|
|
child = dish.lastElementChild;
|
2020-05-28 22:25:55 +02:00
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let d of data)
|
|
|
|
if (d.available)
|
|
|
|
addDish(d);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("list ingredient", data => {
|
|
|
|
let child = ingredient.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
ingredient.removeChild(child);
|
|
|
|
child = ingredient.lastElementChild;
|
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let i of data)
|
|
|
|
if (i.available)
|
|
|
|
addIngredient(i);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("list sauce", data => {
|
|
|
|
let child = sauce.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
sauce.removeChild(child);
|
|
|
|
child = sauce.lastElementChild;
|
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let s of data)
|
|
|
|
if (s.available)
|
|
|
|
addSauce(s);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("list drink", data => {
|
|
|
|
let child = drink.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
drink.removeChild(child);
|
|
|
|
child = drink.lastElementChild;
|
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let d of data)
|
|
|
|
if (d.available)
|
|
|
|
addDrink(d);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("list dessert", data => {
|
|
|
|
let child = dessert.lastElementChild;
|
|
|
|
while (child) {
|
|
|
|
dessert.removeChild(child);
|
|
|
|
child = dessert.lastElementChild;
|
|
|
|
}
|
2020-05-31 22:23:36 +02:00
|
|
|
for (let d of data)
|
|
|
|
if (d.available)
|
|
|
|
addDessert(d);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 15:42:04 +02:00
|
|
|
socket.on("list user", data => {
|
|
|
|
let user_list = document.getElementById("user_list");
|
|
|
|
user_list.innerHTML = "";
|
|
|
|
for (let u of data)
|
|
|
|
user_list.insertAdjacentHTML("beforeend", `<option value="${u}">`);
|
|
|
|
|
|
|
|
let user = document.getElementById("user");
|
|
|
|
if (data.indexOf(user.value) === -1)
|
|
|
|
user.style.color = "red";
|
|
|
|
else
|
|
|
|
user.style.color = "";
|
|
|
|
});
|
|
|
|
|
2020-05-28 22:25:55 +02:00
|
|
|
socket.on("new command", data => {
|
2020-05-29 19:44:12 +02:00
|
|
|
addCmd(data);
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.on("clear command", data => {
|
2020-05-29 19:44:12 +02:00
|
|
|
clear(document.querySelector(`.list #cmd${data}`))
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 21:40:36 +02:00
|
|
|
socket.on("WIP command", data => {
|
|
|
|
WIP(document.querySelector(`.list #cmd${data.number}`), data.sandwich)
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 21:40:36 +02:00
|
|
|
socket.on("done command", data => {
|
2020-05-29 19:44:12 +02:00
|
|
|
done(document.querySelector(`.list #cmd${data}`))
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.on("give command", data => {
|
2020-05-29 19:44:12 +02:00
|
|
|
give(document.querySelector(`.list #cmd${data}`))
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-29 21:47:40 +02:00
|
|
|
socket.on("error command", data => {
|
2020-05-29 19:44:12 +02:00
|
|
|
error(document.querySelector(`.list #cmd${data}`))
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 15:42:04 +02:00
|
|
|
socket.on("add user", data => {
|
|
|
|
if (data === current.client)
|
|
|
|
addCommand();
|
|
|
|
});
|
|
|
|
|
2020-05-31 22:23:36 +02:00
|
|
|
socket.on("set dish", data => {
|
2020-05-31 23:19:00 +02:00
|
|
|
if (data.available && db.dish[data.id] === undefined)
|
2020-05-31 22:23:36 +02:00
|
|
|
addDish(data);
|
2020-05-31 23:19:00 +02:00
|
|
|
else if (!data.available && db.dish[data.id] !== undefined)
|
|
|
|
removeDish(data.id);
|
|
|
|
else
|
2020-05-31 22:23:36 +02:00
|
|
|
db.dish[data.id] = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("set ingredient", data => {
|
2020-05-31 23:19:00 +02:00
|
|
|
if (data.available && db.ingredient[data.id] === undefined)
|
2020-05-31 22:23:36 +02:00
|
|
|
addIngredient(data);
|
2020-05-31 23:19:00 +02:00
|
|
|
else if (!data.available && db.ingredient[data.id] !== undefined)
|
|
|
|
removeIngredient(data.id);
|
|
|
|
else
|
2020-05-31 22:23:36 +02:00
|
|
|
db.ingredient[data.id] = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("set sauce", data => {
|
2020-05-31 23:19:00 +02:00
|
|
|
if (data.available && db.sauce[data.id] === undefined)
|
2020-05-31 22:23:36 +02:00
|
|
|
addSauce(data);
|
2020-05-31 23:19:00 +02:00
|
|
|
else if (!data.available && db.sauce[data.id] !== undefined)
|
|
|
|
removeSauce(data.id);
|
|
|
|
else
|
2020-05-31 22:23:36 +02:00
|
|
|
db.sauce[data.id] = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("set drink", data => {
|
2020-05-31 23:19:00 +02:00
|
|
|
if (data.available && db.drink[data.id] === undefined)
|
2020-05-31 22:23:36 +02:00
|
|
|
addDrink(data);
|
2020-05-31 23:19:00 +02:00
|
|
|
else if (!data.available && db.drink[data.id] !== undefined)
|
|
|
|
removeDrink(data.id);
|
|
|
|
else
|
2020-05-31 22:23:36 +02:00
|
|
|
db.drink[data.id] = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("set dessert", data => {
|
2020-05-31 23:19:00 +02:00
|
|
|
if (data.available && db.dessert[data.id] === undefined)
|
2020-05-31 22:23:36 +02:00
|
|
|
addDessert(data);
|
2020-05-31 23:19:00 +02:00
|
|
|
else if (!data.available && db.dessert[data.id] !== undefined)
|
|
|
|
removeDessert(data.id)
|
|
|
|
else
|
2020-05-31 22:23:36 +02:00
|
|
|
db.dessert[data.id] = data;
|
2020-05-31 23:19:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("remove dish", data => {
|
|
|
|
if (db.dish[data])
|
|
|
|
removeDish(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("remove ingredient", data => {
|
|
|
|
if (db.ingredient[data])
|
|
|
|
removeIngredient(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("remove sauce", data => {
|
|
|
|
if (db.sauce[data])
|
|
|
|
removeSauce(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("remove drink", data => {
|
|
|
|
if (db.drink[data])
|
|
|
|
removeDrink(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("remove dessert", data => {
|
|
|
|
if (db.dessert[data])
|
|
|
|
removeDessert(data);
|
2020-05-31 22:23:36 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 16:48:50 +02:00
|
|
|
socket.on("price", data => {
|
|
|
|
document.querySelector("#resume h2").innerHTML = data+"€";
|
|
|
|
})
|
|
|
|
|
2020-05-30 15:42:04 +02:00
|
|
|
socket.on("fail add user", () => {
|
|
|
|
alert("User creation fail !");
|
|
|
|
addUser();
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("internal error", () => {
|
|
|
|
alert("An error occurred !");
|
2020-05-29 19:44:12 +02:00
|
|
|
})
|
|
|
|
|
2020-05-28 22:25:55 +02:00
|
|
|
document.querySelector(".validation").addEventListener("click", ev => {
|
|
|
|
ev.stopPropagation();
|
2020-05-30 15:42:04 +02:00
|
|
|
if (!current.dish && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert)
|
2020-05-28 22:25:55 +02:00
|
|
|
alert("Empty command !");
|
2020-05-30 15:42:04 +02:00
|
|
|
else if (user.style.color === "red")
|
|
|
|
addUser();
|
|
|
|
else
|
|
|
|
addCommand();
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|
|
|
|
|
2020-05-30 15:42:04 +02:00
|
|
|
document.getElementById("user").addEventListener("keyup", ev => {
|
2020-05-28 22:25:55 +02:00
|
|
|
let input = ev.target;
|
|
|
|
let min_characters = 0;
|
|
|
|
if (input.value.length < min_characters)
|
|
|
|
return;
|
2020-05-30 15:42:04 +02:00
|
|
|
socket.emit("list user", input.value);
|
|
|
|
current.client = input.value;
|
2020-05-28 22:25:55 +02:00
|
|
|
});
|