Просмотр исходного кода

Add price to recipe creation for non-pos users

Lee Morgan 6 лет назад
Родитель
Сommit
311c0f55b8
3 измененных файлов с 17 добавлено и 6 удалено
  1. 1 0
      controllers/recipeData.js
  2. 7 1
      views/inventoryPage/inventory.ejs
  3. 9 5
      views/inventoryPage/recipes.js

+ 1 - 0
controllers/recipeData.js

@@ -15,6 +15,7 @@ module.exports = {
         let recipe = new Recipe({
         let recipe = new Recipe({
             merchant: req.session.user,
             merchant: req.session.user,
             name: req.body.name,
             name: req.body.name,
+            price: Math.round(req.body.price * 100),
             ingredients: []
             ingredients: []
         });
         });
 
 

+ 7 - 1
views/inventoryPage/inventory.ejs

@@ -55,7 +55,13 @@
             </div>
             </div>
 
 
             <div id="newRecipe">
             <div id="newRecipe">
-                <input type="text">
+                <label>Name:
+                    <input id="newName" type="text">
+                </label>
+
+                <label>Price:
+                    <input id="newPrice" type="number" step="0.01">
+                </label>
 
 
                 <button class="button-small" onclick="window.recipesObj.submitNew()">Create</button>
                 <button class="button-small" onclick="window.recipesObj.submitNew()">Create</button>
 
 

+ 9 - 5
views/inventoryPage/recipes.js

@@ -73,20 +73,24 @@ window.recipesObj = {
         document.querySelector("#newRecipe").style.display = "block";
         document.querySelector("#newRecipe").style.display = "block";
     },
     },
 
 
-    cancel: function(){
-        document.querySelector("#newRecipe input").value = "";
+    cancelAdd: function(){
+        document.querySelector("#newName").value = "";
+        document.querySelector("#newPrice").value = 0;
         document.querySelector("#newRecipe").style.display = "none";
         document.querySelector("#newRecipe").style.display = "none";
     },
     },
 
 
     submitNew: function(){
     submitNew: function(){
         let inputDiv = document.querySelector("#newRecipe");
         let inputDiv = document.querySelector("#newRecipe");
-        let input = document.querySelector("#newRecipe input");
+        let nameInput = document.querySelector("#newName");
+        let priceInput = document.querySelector("#newPrice");
 
 
         let data = {
         let data = {
-            name: input.value
+            name: nameInput.value,
+            price: priceInput.value
         };
         };
 
 
-        input.value = "";
+        nameInput.value = "";
+        priceInput.value = 0;
         inputDiv.style.display = "none";
         inputDiv.style.display = "none";
 
 
         axios.post("/recipe/create", data)
         axios.post("/recipe/create", data)