let newOrder = { display: function(Order){ document.getElementById("sidebarDiv").classList.add("sidebarWide"); document.getElementById("newOrderIngredientList").style.display = "flex"; let selectedList = document.getElementById("selectedIngredientList"); while(selectedList.children.length > 0){ selectedList.removeChild(selectedList.firstChild); } let ingredientList = document.getElementById("newOrderIngredients"); while(ingredientList.children.length > 0){ ingredientList.removeChild(ingredientList.firstChild); } for(let i = 0; i < merchant.ingredients.length; i++){ let ingredient = document.createElement("button"); ingredient.classList = "newOrderIngredient"; ingredient.innerText = merchant.ingredients[i].ingredient.name; ingredient.onclick = ()=>{this.addIngredient(merchant.ingredients[i].ingredient, ingredient)}; ingredientList.appendChild(ingredient); } document.getElementById("submitNewOrder").onclick = ()=>{this.submit()}; }, addIngredient: function(ingredient, element){ element.style.display = "none"; let div = document.getElementById("selectedIngredient").content.children[0].cloneNode(true); div.children[0].children[0].innerText = `${ingredient.name} (${ingredient.unit.toUpperCase()})`; div.children[0].children[1].onclick = ()=>{this.removeIngredient(div, element)}; div.children[1].children[0].placeholder = "QUANTITY"; div.children[1].children[1].placeholder = "PRICE PER UNIT"; document.getElementById("selectedIngredientList").appendChild(div); }, removeIngredient: function(selectedElement, element){ selectedElement.parentElement.removeChild(selectedElement); element.style.display = "block"; }, submit: function(){ console.log("something"); } } module.exports = newOrder;