recipeDetails.ejs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <div id="recipeDetails">
  2. <div class="sidebarIconButtons">
  3. <button onclick="closeSidebar()">
  4. <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  5. <line x1="5" y1="12" x2="19" y2="12"></line>
  6. <polyline points="12 5 19 12 12 19"></polyline>
  7. </svg>
  8. </button>
  9. <% if(merchant.pos === "none"){ %>
  10. <button onclick="recipeDetailsComp.edit()">
  11. <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  12. <path d="M12 20h9"></path>
  13. <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path>
  14. </svg>
  15. </button>
  16. <button onclick="recipeDetailsComp.remove()">
  17. <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  18. <polyline points="3 6 5 6 21 6"></polyline>
  19. <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
  20. </svg>
  21. </button>
  22. <% } %>
  23. </div>
  24. <h1></h1>
  25. <div id="recipeIngredients"></div>
  26. <div class="lineBorder"></div>
  27. <div id="recipePrice">
  28. <h3>Price</h3>
  29. <p></p>
  30. </div>
  31. <script>
  32. let recipeDetailsComp = {
  33. recipe: {},
  34. display: function(recipe){
  35. this.recipe = recipe;
  36. openSidebar(document.querySelector("#recipeDetails"));
  37. document.querySelector("#recipeDetails h1").innerText = recipe.name;
  38. let ingredientList = document.querySelector("#recipeIngredients");
  39. while(ingredientList.children.length > 0){
  40. ingredientList.removeChild(ingredientList.firstChild);
  41. }
  42. for(let ingredient of recipe.ingredients){
  43. let ingredientDiv = document.createElement("div");
  44. ingredientDiv.classList = "recipeIngredient";
  45. ingredientList.appendChild(ingredientDiv);
  46. let ingredientName = document.createElement("p");
  47. ingredientName.innerText = ingredient.ingredient.name;
  48. ingredientDiv.appendChild(ingredientName);
  49. let ingredientQuantity = document.createElement("p");
  50. ingredientQuantity.innerText = `${ingredient.quantity} ${ingredient.ingredient.unit}`;
  51. ingredientDiv.appendChild(ingredientQuantity);
  52. }
  53. document.querySelector("#recipePrice p").innerText = `$${(recipe.price / 100).toFixed(2)}`;
  54. },
  55. remove: function(){
  56. fetch(`/merchant/recipes/remove/${this.recipe._id}`, {
  57. method: "DELETE"
  58. })
  59. .then((response) => response.json())
  60. .then((response)=>{
  61. if(typeof(response) === "string"){
  62. banner.createError(response);
  63. }else{
  64. updateRecipes(this.recipe, true);
  65. banner.createNotification("Recipe removed");
  66. }
  67. })
  68. .catch((err)=>{
  69. banner.createError("Something went wrong. Try refreshing the page");
  70. });
  71. }
  72. }
  73. </script>
  74. </div>