summaryrefslogtreecommitdiff
path: root/view/static
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-14 20:14:42 +0200
committerxengineering <me@xengineering.eu>2024-05-14 20:43:41 +0200
commita87128138bdb301ede64049ec5068e47abb5c839 (patch)
tree72495022f7237458f4a24122ffd13dd872263698 /view/static
parentb5b72880a0b6e9f188b532c9b2ad360ff1dab2ea (diff)
downloadceres-a87128138bdb301ede64049ec5068e47abb5c839.tar
ceres-a87128138bdb301ede64049ec5068e47abb5c839.tar.zst
ceres-a87128138bdb301ede64049ec5068e47abb5c839.zip
view: Complete ingredient editing
Diffstat (limited to 'view/static')
-rw-r--r--view/static/ceres.js28
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);
+}