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

Creating new recipe only allows types for that specific ingredient.

Lee Morgan 5 лет назад
Родитель
Сommit
c0382955e9

+ 4 - 4
views/dashboardPage/ejs/sidebars/newRecipe.ejs

@@ -47,14 +47,14 @@
                 <input type="number" step="0.01" min="0">
 
                 <select>
-                    <optgroup label="MASS/WEIGHT">
+                    <optgroup label="MASS/WEIGHT" style="display:none">
                         <option type="mass" value="g">G</option>
                         <option type="mass" value="kg">KG</option>
                         <option type="mass" value="oz">OZ</option>
                         <option type="mass" value="lb">LB</option>
                     </optgroup>
         
-                    <optgroup label="VOLUME">
+                    <optgroup label="VOLUME" style="display:none">
                         <option type="volume" value="ml">ML</option>
                         <option type="volume" value="l">L</option>
                         <option type="volume" value="tsp">TSP</option>
@@ -66,7 +66,7 @@
                         <option type="volume" value="gal">GAL</option>
                     </optgroup>
         
-                    <optgroup label="LENGTH">
+                    <optgroup label="LENGTH" style="display:none">
                         <option type="length" value="mm">MM</option>
                         <option type="length" value="cm">CM</option>
                         <option type="length" value="m">M</option>
@@ -74,7 +74,7 @@
                         <option type="length" value="ft">FT</option>
                     </optgroup>
         
-                    <optgroup label="OTHER">
+                    <optgroup label="OTHER" style="display:none">
                         <option type="other" value="each">EACH</option>
                     </optgroup>
                 </select>

+ 2 - 1
views/dashboardPage/js/sidebars/editRecipe.js

@@ -96,8 +96,9 @@ module.exports = {
             case "volume": select.value = "ml"; break;
             case "length": select.value = "mm"; break;
             case "other":
-                select.value = "other";
+                select.value = "each";
                 select.children[3].style.display = "block";
+                break;
         }
 
         used.appendChild(newItem);

+ 16 - 0
views/dashboardPage/js/sidebars/newRecipe.js

@@ -59,6 +59,22 @@ let newRecipe = {
             this.populateChoices();
         };
         element.ingredient = ingredient;
+
+        let select = element.children[1].children[1];
+        if(ingredient.convert.toMass !== undefined) select.children[0].style.display = "block";
+        if(ingredient.convert.toVolume !== undefined) select.children[1].style.display = "block";
+        if(ingredient.convert.toLength !== undefined) select.children[2].style.display = "block";
+
+        switch(ingredient.unitType){
+            case "mass": select.value = "g"; break;
+            case "volume": select.value = "ml"; break;
+            case "length": select.value = "mm"; break;
+            case "other":
+                select.children[3].style.display = "block";
+                select.value = "each";
+                break;
+        }
+
         document.getElementById("newRecipeChosenList").appendChild(element);
     },