mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Finish "shopping list to stock workflow" (closes #98)
This commit is contained in:
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBooking(' + result.booking_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
|
||||
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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBooking(' + result.booking_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>';
|
||||
|
||||
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)
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user