import {alert, confirm} from "./popups.js"; const socket = io(); let db = {dish: {}, ingredient: {}, sauce: {}, drink: {}, dessert: {}}; function editPopup(ob, el) { document.querySelector("body").insertAdjacentHTML("afterbegin", `
`); let e = document.getElementById("popup-container"); if (ob.available) e.querySelector("#available").click() if (ob.maxIngredients !== undefined) e.querySelector("#edit div:last-of-type").insertAdjacentHTML("afterend", ``); if (ob.maxSauces !== undefined) e.querySelector("#edit div:last-of-type").insertAdjacentHTML("afterend", ``); e.querySelector("#cancel").addEventListener("click", () => { e.remove(); }); e.querySelector("#apply").addEventListener("click", () => { socket.emit("set " + el.id.replace(ob.id, ""), { id: ob.id, available: e.querySelector("#available").checked, price: parseFloat(e.querySelector("#price").value), maxIngredients: ob.maxIngredients === undefined ? undefined : parseInt(e.querySelector("#maxIngredients").value), maxSauces: ob.maxSauces === undefined ? undefined : parseInt(e.querySelector("#maxSauces").value), }); e.remove(); }); } async function createPopup(type) { document.querySelector("body").insertAdjacentHTML("afterbegin", ``); let e = document.getElementById("popup-container"); if (type === "dish") { e.querySelector("#edit div:last-of-type").insertAdjacentHTML("afterend", ``); e.querySelector("#edit div:last-of-type").insertAdjacentHTML("afterend", ``); } e.querySelector("#cancel").addEventListener("click", () => { e.remove(); }); e.querySelector("#apply").addEventListener("click", () => { socket.emit("add " + type, { name: e.querySelector("#name").value, available: e.querySelector("#available").checked, price: parseFloat(e.querySelector("#price").value), maxIngredients: type !== "dish" ? undefined : parseInt(e.querySelector("#maxIngredients").value), maxSauces: type !== "dish" ? undefined : parseInt(e.querySelector("#maxSauces").value), }); e.remove(); }); } socket.on("connected", () => { for (let i of ["dish", "ingredient", "sauce", "drink", "dessert"]) socket.emit("list " + i); }); for (let i of ["dish", "ingredient", "sauce", "drink", "dessert"]) { let el = document.querySelector(`#${i} ul`); function add(e) { db[i][e.id] = e; el.insertAdjacentHTML("beforeend", `