diff options
Diffstat (limited to 'view/static')
-rw-r--r-- | view/static/ceres.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/view/static/ceres.js b/view/static/ceres.js index 43b8290..2405a59 100644 --- a/view/static/ceres.js +++ b/view/static/ceres.js @@ -59,12 +59,23 @@ function updateRecipe(event) { let obj = Object.fromEntries(data.entries()); obj.steps = []; - const steps = document.querySelectorAll('form section textarea'); - steps.forEach(step => { + var steps_container = document.getElementById('steps'); + var steps = steps_container.children; + for (var i = 0; i < steps.length; i++) { let s = {}; - s.text = step.value; + s.text = steps[i].querySelector('textarea').value; + s.ingredients = []; + var ingredients_container = steps[i].querySelector('.ingredients') + var ingredients = ingredients_container.children; + for (var j = 0; j < ingredients.length; j++) { + let ingr = {}; + ingr.amount = ingredients[j].querySelector('.amount').value; + ingr.unit = ingredients[j].querySelector('.unit').value; + ingr.type = ingredients[j].querySelector('.type').value; + s.ingredients.push(ingr) + } obj.steps.push(s); - }); + } fetch(url, { method: 'POST', @@ -93,3 +104,12 @@ function addNewStep() { let step = template.content.cloneNode(true); steps.appendChild(step); } + +function addNewIngredient(button) { + let step = button.parentNode; + let template = document.getElementById("recipe-ingredient-template"); + let ingredients = step.querySelector('.ingredients'); + + let ingredient = template.content.cloneNode(true); + ingredients.appendChild(ingredient); +} |