recipeDetails.ejs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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="recipeIngredientList"></div>
  26. <div class="lineBorder"></div>
  27. <div id="recipePrice">
  28. <h3>Price</h3>
  29. <p></p>
  30. </div>
  31. <template id="recipeIngredient">
  32. <div class="recipeIngredient">
  33. <p></p>
  34. <p></p>
  35. </div>
  36. </template>
  37. <script>
  38. let recipeDetailsComp = {
  39. recipe: {},
  40. display: function(recipe){
  41. this.recipe = recipe;
  42. console.log(recipe);
  43. openSidebar(document.querySelector("#recipeDetails"));
  44. document.querySelector("#recipeDetails h1").innerText = recipe.name;
  45. let ingredientList = document.querySelector("#recipeIngredientList");
  46. while(ingredientList.children.length > 0){
  47. ingredientList.removeChild(ingredientList.firstChild);
  48. }
  49. let template = document.querySelector("#recipeIngredient").content.children[0];
  50. for(let i = 0; i < recipe.ingredients.length; i++){
  51. ingredientDiv = template.cloneNode(true);
  52. ingredientDiv.children[0].innerText = recipe.ingredients[i].ingredient.name;
  53. ingredientDiv.children[1].innerText = `${recipe.ingredients[i].quantity} ${recipe.ingredients[i].ingredient.unit}`;
  54. ingredientList.appendChild(ingredientDiv);
  55. }
  56. document.querySelector("#recipePrice p").innerText = `$${(recipe.price / 100).toFixed(2)}`;
  57. },
  58. edit: function(){
  59. console.log("edit recipe");
  60. },
  61. remove: function(){
  62. fetch(`/merchant/recipes/remove/${this.recipe._id}`, {
  63. method: "DELETE"
  64. })
  65. .then((response) => response.json())
  66. .then((response)=>{
  67. if(typeof(response) === "string"){
  68. banner.createError(response);
  69. }else{
  70. updateRecipes(this.recipe, true);
  71. banner.createNotification("Recipe removed");
  72. }
  73. })
  74. .catch((err)=>{
  75. banner.createError("Something went wrong. Try refreshing the page");
  76. });
  77. }
  78. }
  79. </script>
  80. </div>