From c6310d636da74bb2f30757a6018801bbbfc806ba Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 22 Jul 2018 10:14:06 +0200 Subject: [PATCH] Always save the recipe edit form when adding, editing or deleting ingredients (fixes #17) --- public/viewjs/recipeform.js | 32 ++++++++++++++++++++++++++++++++ views/recipeform.blade.php | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/public/viewjs/recipeform.js b/public/viewjs/recipeform.js index 8a8e8cfb..1da5f122 100644 --- a/public/viewjs/recipeform.js +++ b/public/viewjs/recipeform.js @@ -82,6 +82,7 @@ $(document).on('click', '.recipe-pos-delete-button', function(e) { if (result === true) { + Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { }); Grocy.Api.Get('delete-object/recipes_pos/' + objectId, function(result) { @@ -112,6 +113,7 @@ $(document).on('click', '.recipe-pos-order-missing-button', function(e) Grocy.Api.Post('add-object/shopping_list', jsonData, function(result) { + Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { }); window.location.href = U('/recipe/' + Grocy.EditObjectId); }, function(xhr) @@ -127,3 +129,33 @@ $(document).on('click', '.recipe-pos-show-note-button', function(e) bootbox.alert(note); }); + +$(document).on('click', '.recipe-pos-edit-button', function (e) +{ + var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id'); + + Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), + function(result) + { + window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId); + }, + function(xhr) + { + console.error(xhr); + } + ); +}); + +$("#recipe-pos-add-button").on("click", function(e) +{ + Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), + function(result) + { + window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new'); + }, + function(xhr) + { + console.error(xhr); + } + ); +}); diff --git a/views/recipeform.blade.php b/views/recipeform.blade.php index 665f68e5..9c88132a 100644 --- a/views/recipeform.blade.php +++ b/views/recipeform.blade.php @@ -44,7 +44,7 @@

{{ $L('Ingredients list') }} - + {{ $L('Add') }}

@@ -62,7 +62,7 @@ @foreach($recipePositions as $recipePosition) - +