Finish "shopping list to stock workflow" (closes #98)

This commit is contained in:
Bernd Bestel
2018-11-17 14:50:52 +01:00
parent db0b48e7ae
commit 6f67619784
6 changed files with 112 additions and 9 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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();