shopping-list/public_html/js/recipe.js

42 lines
920 B
JavaScript
Raw Normal View History

2018-10-24 15:00:27 +02:00
$(document).ready(function(){
2019-05-19 18:37:00 +02:00
$("#delRecipe").click(removeRecipe);
$("#addToList").click(addToList);
});
function addToList() {
var list = [];
var ingredientsList = $("#ingredients").children();
ingredientsList.each(function () {
if ($(this).data("unit") != null) {
var amount = $(this).data("amount");
var unit = $(this).data("unit");
var name = $(this).data("name");
list.push({ amount: amount, unit: unit, name: name });
2018-10-24 15:00:27 +02:00
}
});
2019-05-19 18:37:00 +02:00
$.post({
url: "/api/list/multiple",
data: {
list: list,
function: "multiple"
},
success: function () {
window.location = "/";
}
2018-10-24 15:00:27 +02:00
});
2019-05-19 18:37:00 +02:00
}
function removeRecipe() {
if (!(confirm("Wirklich löschen?"))) { return; }
$.post({
url: "/api/recipes/del",
data: {
id: $("[data-recipeid]").data("recipeid")
},
success: function () {
window.location.href = "/recipes";
}
2018-10-24 15:00:27 +02:00
});
2019-05-19 18:37:00 +02:00
}