mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-27 23:40:03 +01:00
24 lines
1 KiB
JavaScript
24 lines
1 KiB
JavaScript
$(document).ready(function () {
|
|
var recipeID = window.location.href.split("/")[(window.location.href.split("/").length - 1)];
|
|
$.post({
|
|
url: "/api/recipes/edit",
|
|
data: {
|
|
id: recipeID
|
|
},
|
|
success: function (data) {
|
|
var recipe = JSON.parse(data);
|
|
$("[name=id]").val(recipe.ID);
|
|
$("#recipeName").val(recipe.Name);
|
|
$("#recipeDuration").val(recipe.Dauer);
|
|
$("#recipeDescription").val(recipe.Beschreibung);
|
|
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;
|
|
}).prop("selected", true);
|
|
if (i + 1 <= recipe.Zutaten.length) { $("#addItem").click(); }
|
|
}
|
|
}
|
|
});
|
|
});
|