shopping-list/js/edit-recipe.js

25 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2019-05-19 18:37:00 +02:00
$(document).ready(function () {
var recipeID = window.location.href.split("/")[(window.location.href.split("/").length - 1)];
$.post({
2018-11-20 09:59:59 +01:00
url: "/api/recipes/edit",
2018-10-24 15:00:27 +02:00
data: {
id: recipeID
},
2019-05-19 18:37:00 +02:00
success: function (data) {
2018-10-24 15:00:27 +02:00
var recipe = JSON.parse(data);
2019-05-19 18:37:00 +02:00
$("[name=id]").val(recipe.ID);
$("#recipeName").val(recipe.Name);
$("#recipeDuration").val(recipe.Dauer);
2019-06-04 09:15:06 +02:00
$("#recipeDescription").summernote('code', recipe.Beschreibung);
2019-05-19 18:37:00 +02:00
for (var i = 1; i <= recipe.Zutaten.length; i++) {
$((".ingredientRow input[name='ingredient[" + i + "][Amount]']")).val(recipe.Zutaten[(i - 1)].Menge);
$((".ingredientRow input[name='ingredient[" + i + "][Name]']")).val(recipe.Zutaten[(i - 1)].Name);
$((".ingredientRow select[name='ingredient[" + i + "][Unit]'] option")).filter(function () {
return $(this).text() === recipe.Zutaten[(i - 1)].Einheit;
2018-10-24 15:00:27 +02:00
}).prop("selected", true);
2019-05-19 18:37:00 +02:00
if (i + 1 <= recipe.Zutaten.length) { $("#addItem").click(); }
2018-10-24 15:00:27 +02:00
}
}
});
});