shopping-list/bin/recipe.js
2018-11-20 09:59:59 +01:00

56 lines
1.7 KiB
JavaScript

$(document).ready(function(){
$("#editingMenu").click(function(){
$(this).css("display", "none");
$("#editingMenuOpen").css("transform", "translate(0, 0)");
});
$("#closeMenue").click(function(){
$("#editingMenu").css("display", "block");
$(this).parent().css("transform", "translate(0, -12em)");
});
$("#edit-recipe").click(function(){
window.location.href = "/edit-recipe/"+$("#recipeHeader").data("recipeid");
});
$("#delRecipe").click(function(){
if(!(confirm("Wirklich löschen?"))){return;}
$.ajax({
type: "POST",
url: "/api/recipes/del",
data: {
id: $("#recipeHeader").data("recipeid")
},
success: function(data){
window.location.href = "/recipes";
}
});
});
$(".removeIngredient").click(function(){
if($(".removeIngredient").length>1){
$(this).parent().remove();
}
});
$(".ingredientName").focus(function(x){
autocomplete(this, values);
});
$(".ingredientName").on("focus", function(){$(this).select();});
$(".ingredientAmount").on("focus", function(){$(this).select();});
$("#addToListButton").click(function(){
var list = [];
var ingredientsList = $("#ingredients").children();
ingredientsList.each(function(){
var amount = $(this).find(".ingredients_row_amount").html();
var unit = $(this).find(".ingredients_row_unit").html();
var name = $(this).find(".ingredients_row_name").html();
list.push({amount: amount, unit: unit, name: name});
});
$.ajax({
type: "POST",
url: "/api/list/multiple",
data: {
list: list
},
success: function(data){
window.location = "/";
}
});
});
});