From 36e8484046253da841d97bfbea4ee47d8e574a70 Mon Sep 17 00:00:00 2001 From: kriddles <54413450+kriddles@users.noreply.github.com> Date: Sat, 21 Dec 2019 05:36:02 -0600 Subject: [PATCH] Recipe form updates (#476) * recipePosForm - hide when embeded productcard * recipeposform: remove prefillByName for productPicker * recipeform add data-product-id * recipeposform cleanup extra clicks * recipeform: bootbox the recipe pos edit button * recipeform: bootbox the recipe pos add button * recipeposform postMessage back * recipeform reload if IngredientsChanged * Fix page reload for new recipes (URL = /recipe/new) Co-authored-by: Bernd Bestel --- public/viewjs/recipeform.js | 68 ++++++++++++++++++++++++---------- public/viewjs/recipeposform.js | 10 +++-- views/recipeform.blade.php | 4 +- views/recipeposform.blade.php | 6 +-- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/public/viewjs/recipeform.js b/public/viewjs/recipeform.js index 334f0418..c146fb11 100644 --- a/public/viewjs/recipeform.js +++ b/public/viewjs/recipeform.js @@ -192,20 +192,29 @@ $(document).on('click', '.recipe-pos-show-note-button', function(e) bootbox.alert(note); }); -$(document).on('click', '.recipe-pos-edit-button', function (e) +$(document).on('click', '.recipe-pos-edit-button', function(e) { - var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id'); + e.preventDefault(); - Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), - function(result) - { - window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId); - }, - function(xhr) - { - console.error(xhr); + var productId = $(e.currentTarget).attr("data-product-id"); + var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id'); + + bootbox.dialog({ + message: '', + size: 'large', + backdrop: true, + closeButton: false, + buttons: { + cancel: { + label: __t('Cancel'), + className: 'btn-secondary responsive-button', + callback: function() + { + bootbox.hideAll(); + } + } } - ); + }); }); $(document).on('click', '.recipe-include-edit-button', function (e) @@ -234,16 +243,24 @@ $(document).on('click', '.recipe-include-edit-button', function (e) $("#recipe-pos-add-button").on("click", function(e) { - Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), - function(result) - { - window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new'); - }, - function(xhr) - { - console.error(xhr); + e.preventDefault(); + + bootbox.dialog({ + message: '', + size: 'large', + backdrop: true, + closeButton: false, + buttons: { + cancel: { + label: __t('Cancel'), + className: 'btn-secondary responsive-button', + callback: function() + { + bootbox.hideAll(); + } + } } - ); + }); }); $("#recipe-include-add-button").on("click", function(e) @@ -319,3 +336,14 @@ $('#delete-current-recipe-picture-button').on('click', function (e) }); Grocy.Components.UserfieldsForm.Load(); + +$(window).on("message", function(e) +{ + var data = e.originalEvent.data; + + if (data.Message === "IngredientsChanged") + { + window.location.href = U('/recipe/' + Grocy.EditObjectId); + } + +}); diff --git a/public/viewjs/recipeposform.js b/public/viewjs/recipeposform.js index 7b559a34..21432c52 100644 --- a/public/viewjs/recipeposform.js +++ b/public/viewjs/recipeposform.js @@ -15,7 +15,8 @@ $('#save-recipe-pos-button').on('click', function (e) Grocy.Api.Post('objects/recipes_pos', jsonData, function(result) { - window.location.href = U('/recipe/' + Grocy.EditObjectParentId); + window.parent.postMessage(WindowMessageBag("IngredientsChanged"), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, function(xhr) { @@ -29,7 +30,8 @@ $('#save-recipe-pos-button').on('click', function (e) Grocy.Api.Put('objects/recipes_pos/' + Grocy.EditObjectId, jsonData, function(result) { - window.location.href = U('/recipe/' + Grocy.EditObjectParentId); + window.parent.postMessage(WindowMessageBag("IngredientsChanged"), Grocy.BaseUrl); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); }, function(xhr) { @@ -152,5 +154,5 @@ $("#only_check_single_unit_in_stock").on("click", function() }); // Click twice to trigger on-click but not change the actual checked state -$("#only_check_single_unit_in_stock").click(); -$("#only_check_single_unit_in_stock").click(); +//$("#only_check_single_unit_in_stock").click(); +//$("#only_check_single_unit_in_stock").click(); diff --git a/views/recipeform.blade.php b/views/recipeform.blade.php index a1246f18..4e68b275 100644 --- a/views/recipeform.blade.php +++ b/views/recipeform.blade.php @@ -98,7 +98,7 @@

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

@@ -118,7 +118,7 @@ @foreach($recipePositions as $recipePosition) - + diff --git a/views/recipeposform.blade.php b/views/recipeposform.blade.php index 7534b577..676c959c 100644 --- a/views/recipeposform.blade.php +++ b/views/recipeposform.blade.php @@ -28,11 +28,9 @@
- @php $prefillByName = ''; if($mode=='edit') { $prefillByName = FindObjectInArrayByPropertyValue($products, 'id', $recipePos->product_id)->name; } @endphp @include('components.productpicker', array( 'products' => $products, - 'nextInputSelector' => '#amount', - 'prefillByName' => $prefillByName + 'nextInputSelector' => '#amount' )) @php if($mode == 'edit') { $value = $recipePos->amount; } else { $value = 1; } @endphp @@ -96,7 +94,7 @@
-
+
@include('components.productcard')