diff --git a/localization/en/strings.php b/localization/en/strings.php
index 022c5238..e6c91823 100644
--- a/localization/en/strings.php
+++ b/localization/en/strings.php
@@ -302,5 +302,8 @@ return array(
'Booking successfully undone' => 'Booking successfully undone',
'Charge cycle successfully undone' => 'Charge cycle successfully undone',
'This cannot be negative and must be an integral number' => 'This cannot be negative and must be an integral number',
- 'Disable stock fulfillment checking for this ingredient' => 'Disable stock fulfillment checking for this ingredient'
+ 'Disable stock fulfillment checking for this ingredient' => 'Disable stock fulfillment checking for this ingredient',
+ 'Add all list items to stock' => 'Add all list items to stock',
+ 'Add #3 #1 of #2 to stock' => 'Add #3 #1 of #2 to stock',
+ 'Adding shopping list item #1 of #2' => 'Adding shopping list item #1 of #2'
);
diff --git a/public/css/grocy.css b/public/css/grocy.css
index f43fc046..83e73bd5 100644
--- a/public/css/grocy.css
+++ b/public/css/grocy.css
@@ -82,6 +82,10 @@ body.embedded.fixed-nav {
margin-left: 0;
}
+iframe {
+ border: 0;
+}
+
/* Hide the default up/down arrow buttons for number inputs because we use our own buttons in numberpicker */
input[type='number'] {
-moz-appearance: textfield;
diff --git a/public/js/grocy.js b/public/js/grocy.js
index 31f894ce..af778959 100644
--- a/public/js/grocy.js
+++ b/public/js/grocy.js
@@ -345,3 +345,15 @@ $(window).on('resize', function()
{
ResizeResponsiveEmbeds($("body").hasClass("fullscreen-card"));
});
+$("iframe").on("load", function()
+{
+ ResizeResponsiveEmbeds($("body").hasClass("fullscreen-card"));
+});
+
+function WindowMessageBag(message, payload = null)
+{
+ var obj = { };
+ obj.Message = message;
+ obj.Payload = payload;
+ return obj;
+}
diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js
index 07d85685..331dfe05 100644
--- a/public/viewjs/purchase.js
+++ b/public/viewjs/purchase.js
@@ -40,18 +40,21 @@
);
}
- toastr.success(L('Added #1 #2 of #3 to stock', amount, Pluralize(amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + L("Undo") + '');
+ var successMessage = L('Added #1 #2 of #3 to stock', amount, Pluralize(amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + L("Undo") + '';
if (addBarcode !== undefined)
{
window.location.href = U('/purchase');
}
- else if (GetUriParam("flow") === "shoppinglistitemtostock")
+ else if (GetUriParam("flow") === "shoppinglistitemtostock" && typeof GetUriParam("embedded") !== undefined)
{
- window.location.href = U('/shoppinglist?flow=shoppinglistitemtostock&listitemid=' + GetUriParam("listitemid"));
+ window.parent.postMessage(WindowMessageBag("AfterItemAdded", GetUriParam("listitemid")), Grocy.BaseUrl);
+ window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", successMessage), Grocy.BaseUrl);
+ window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
}
else
{
+ toastr.success(successMessage);
$('#amount').val(0);
$('#price').val('');
Grocy.Components.DateTimePicker.Clear();
@@ -179,7 +182,6 @@ $('#amount').on('change', function (e)
if (GetUriParam("flow") === "shoppinglistitemtostock")
{
$('#amount').val(GetUriParam("amount"));
- $('#save-purchase-button').html(L("OK") + " & " + L("Back to shopping list"));
}
function UndoStockBooking(bookingId)
diff --git a/public/viewjs/shoppinglist.js b/public/viewjs/shoppinglist.js
index ecf8c6e9..406fb115 100644
--- a/public/viewjs/shoppinglist.js
+++ b/public/viewjs/shoppinglist.js
@@ -68,6 +68,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
$('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function()
{
$(this).remove();
+ OnListItemRemoved();
});
},
function(xhr)
@@ -115,6 +116,7 @@ $(document).on('click', '#clear-shopping-list', function(e)
$('#shoppinglist-table tbody tr').fadeOut(500, function()
{
$(this).remove();
+ OnListItemRemoved();
});
},
function(xhr)
@@ -127,8 +129,71 @@ $(document).on('click', '#clear-shopping-list', function(e)
});
});
-if (GetUriParam("flow") === "shoppinglistitemtostock")
+$(document).on('click', '.shopping-list-stock-add-workflow-list-item-button', function(e)
{
- var listItem = GetUriParam("listitemid");
- $(".shoppinglist-delete-button[data-shoppinglist-id='" + listItem + "']").click();
+ e.preventDefault();
+
+ var href = $(e.currentTarget).attr('href');
+
+ $("#shopping-list-stock-add-workflow-purchase-form-frame").attr("src", href);
+ $("#shopping-list-stock-add-workflow-modal").modal("show");
+
+ if (Grocy.ShoppingListToStockWorkflowAll)
+ {
+ $("#shopping-list-stock-add-workflow-modal .modal-footer").removeClass("d-none");
+ $("#shopping-list-stock-add-workflow-purchase-item-count").text(L("Adding shopping list item #1 of #2", Grocy.ShoppingListToStockWorkflowCurrent, Grocy.ShoppingListToStockWorkflowCount));
+ }
+});
+
+Grocy.ShoppingListToStockWorkflowAll = false;
+Grocy.ShoppingListToStockWorkflowCount = 0;
+Grocy.ShoppingListToStockWorkflowCurrent = 0;
+$(document).on('click', '#add-all-items-to-stock-button', function(e)
+{
+ Grocy.ShoppingListToStockWorkflowAll = true;
+ Grocy.ShoppingListToStockWorkflowCount = $(".shopping-list-stock-add-workflow-list-item-button").length;
+ Grocy.ShoppingListToStockWorkflowCurrent++;
+ $(".shopping-list-stock-add-workflow-list-item-button").first().click();
+});
+
+$(window).on("message", function(e)
+{
+ var data = e.originalEvent.data;
+
+ if (data.Message === "AfterItemAdded")
+ {
+ $(".shoppinglist-delete-button[data-shoppinglist-id='" + data.Payload + "']").click();
+ }
+ else if (data.Message === "Ready")
+ {
+ if (!Grocy.ShoppingListToStockWorkflowAll)
+ {
+ $("#shopping-list-stock-add-workflow-modal").modal("hide");
+ }
+ else
+ {
+ Grocy.ShoppingListToStockWorkflowCurrent++;
+ if (Grocy.ShoppingListToStockWorkflowCurrent <= Grocy.ShoppingListToStockWorkflowCount)
+ {
+ $(".shopping-list-stock-add-workflow-list-item-button")[1].click();
+ }
+ else
+ {
+ $("#shopping-list-stock-add-workflow-modal").modal("hide");
+ }
+ }
+ }
+ else if (data.Message === "ShowSuccessMessage")
+ {
+ toastr.success(data.Payload);
+ }
+});
+
+function OnListItemRemoved()
+{
+ if ($(".shopping-list-stock-add-workflow-list-item-button").length === 0)
+ {
+ $("#add-all-items-to-stock-button").addClass("disabled");
+ }
}
+OnListItemRemoved();
diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php
index c2b59e72..e96b1141 100644
--- a/views/shoppinglist.blade.php
+++ b/views/shoppinglist.blade.php
@@ -8,6 +8,7 @@
+
@endpush
@push('pageStyles')
@@ -28,6 +29,9 @@
{{ $L('Add products that are below defined min. stock amount') }}
+
+ {{ $L('Add all list items to stock') }}
+