Fixed product picker workflows

This commit is contained in:
Bernd Bestel 2020-11-14 11:05:36 +01:00
parent 71f6b38cb2
commit b267295e86
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
9 changed files with 90 additions and 84 deletions

View File

@ -44,6 +44,13 @@ UpdateUriParam = function(key, value)
window.history.replaceState({}, "", decodeURIComponent(`${location.pathname}?${queryParameters}`));
};
RemoveUriParam = function(key)
{
var queryParameters = new URLSearchParams(location.search);
queryParameters.delete(key);
window.history.replaceState({}, "", decodeURIComponent(`${location.pathname}?${queryParameters}`));
};
IsTouchInputDevice = function()
{
if (("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch)

View File

@ -36,12 +36,24 @@ Grocy.Components.ProductPicker.Clear = function()
Grocy.Components.ProductPicker.InProductAddWorkflow = function()
{
return typeof GetUriParam('createdproduct') !== "undefined" || typeof GetUriParam('product') !== "undefined";
return GetUriParam('flow') == "InplaceNewProductWithName";
}
Grocy.Components.ProductPicker.InProductModifyWorkflow = function()
{
return typeof GetUriParam('addbarcodetoselection') !== "undefined";
return GetUriParam('flow') == "InplaceAddBarcodeToExistingProduct";
}
Grocy.Components.ProductPicker.InAnyFlow = function()
{
return Grocy.Components.ProductPicker.InProductAddWorkflow() || Grocy.Components.ProductPicker.InProductModifyWorkflow();
}
Grocy.Components.ProductPicker.FinishFlow = function()
{
RemoveUriParam("flow");
RemoveUriParam("barcode");
RemoveUriParam("product-name");
}
Grocy.Components.ProductPicker.ShowCustomError = function(text)
@ -76,7 +88,7 @@ $('.product-combobox').combobox({
clearIfNoMatch: false
});
var prefillProduct = GetUriParam('createdproduct');
var prefillProduct = GetUriParam('product-name');
var prefillProduct2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-name').toString();
if (!prefillProduct2.isEmpty())
{
@ -117,11 +129,10 @@ if (typeof prefillProductId !== "undefined")
nextInputElement.focus();
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")
{
$('#addbarcodetoselection').text(addBarcode);
$('#flow-info-addbarcodetoselection').removeClass('d-none');
$('#InplaceAddBarcodeToExistingProduct').text(GetUriParam("barcode"));
$('#flow-info-InplaceAddBarcodeToExistingProduct').removeClass('d-none');
$('#barcode-lookup-disabled-hint').removeClass('d-none');
$('#barcode-lookup-hint').addClass('d-none');
}
@ -138,7 +149,7 @@ $('#product_id_text_input').on('blur', function(e)
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*=\"" + input + ",\"]").first();
if (GetUriParam('addbarcodetoselection') === undefined && input.length > 0 && possibleOptionElement.length > 0)
if (GetUriParam('flow') === undefined && input.length > 0 && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').attr("barcode", input);
@ -153,7 +164,7 @@ $('#product_id_text_input').on('blur', function(e)
}
var optionElement = $("#product_id option:contains(\"" + input + "\")").first();
if (input.length > 0 && optionElement.length === 0 && typeof GetUriParam('addbarcodetoselection') === "undefined" && Grocy.Components.ProductPicker.GetPicker().parent().data('disallow-all-product-workflows').toString() === "false")
if (input.length > 0 && optionElement.length === 0 && GetUriParam('flow') === undefined && Grocy.Components.ProductPicker.GetPicker().parent().data('disallow-all-product-workflows').toString() === "false")
{
var addProductWorkflowsAdditionalCssClasses = "";
if (Grocy.Components.ProductPicker.GetPicker().parent().data('disallow-add-product-workflows').toString() === "true")
@ -189,7 +200,7 @@ $('#product_id_text_input').on('blur', function(e)
callback: function()
{
Grocy.Components.ProductPicker.PopupOpen = false;
window.location.href = U('/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative));
window.location.href = U('/product/new?flow=InplaceNewProductWithName&name=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceNewProductWithName"));
}
},
addbarcode: {
@ -198,7 +209,7 @@ $('#product_id_text_input').on('blur', function(e)
callback: function()
{
Grocy.Components.ProductPicker.PopupOpen = false;
window.location.href = U(Grocy.CurrentUrlRelative + '?addbarcodetoselection=' + encodeURIComponent(input));
window.location.href = U(Grocy.CurrentUrlRelative + '?flow=InplaceAddBarcodeToExistingProduct&barcode=' + encodeURIComponent(input));
}
},
addnewproductwithbarcode: {
@ -207,7 +218,7 @@ $('#product_id_text_input').on('blur', function(e)
callback: function()
{
Grocy.Components.ProductPicker.PopupOpen = false;
window.location.href = U('/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative));
window.location.href = U('/product/new?flow=InplaceNewProductWithBarcode&barcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative + "?flow=InplaceAddBarcodeToExistingProduct&barcode=" + input));
}
}
}

View File

@ -42,17 +42,16 @@
bookingResponse = result;
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = addBarcode;
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonForm.product_id;
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-addbarcodetoselection").addClass("d-none");
$("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
$('#barcode-lookup-disabled-hint').addClass('d-none');
$('#barcode-lookup-hint').removeClass('d-none');
window.history.replaceState({}, document.title, U("/consume"));
@ -90,6 +89,7 @@
{
Grocy.FrontendHelpers.EndUiBusy("consume-form");
toastr.success(successMessage);
Grocy.Components.ProductPicker.FinishFlow();
Grocy.Components.ProductAmountPicker.Reset();
$("#display_amount").attr("min", "1");

View File

@ -39,18 +39,17 @@
{
bookingResponse = result;
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = addBarcode;
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonForm.product_id;
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-addbarcodetoselection").addClass("d-none");
$("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
$('#barcode-lookup-disabled-hint').addClass('d-none');
$('#barcode-lookup-hint').removeClass('d-none');
window.history.replaceState({}, document.title, U("/inventory"));
@ -78,6 +77,7 @@
{
Grocy.FrontendHelpers.EndUiBusy("inventory-form");
toastr.success(successMessage);
Grocy.Components.ProductPicker.FinishFlow();
Grocy.Components.ProductAmountPicker.Reset();
$('#inventory-change-info').addClass('d-none');
@ -189,13 +189,18 @@ $('#display_amount').val('');
$(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('inventory-form');
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
if (Grocy.Components.ProductPicker.InAnyFlow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
if (Grocy.Components.ProductPicker.InProductModifyWorkflow())
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
}
$('#display_amount').on('focus', function(e)

View File

@ -1,6 +1,7 @@
function saveProductPicture(result, location, jsonData)
{
var productId = Grocy.EditObjectId || result.created_object_id;
Grocy.Components.UserfieldsForm.Save(() =>
{
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
@ -21,7 +22,7 @@
}
else if (returnTo !== undefined)
{
window.location.href = U(returnTo) + '?createdproduct=' + encodeURIComponent($('#name').val());
window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($('#name').val());
}
else
{
@ -51,7 +52,7 @@
}
else if (returnTo !== undefined)
{
window.location.href = U(returnTo) + '?createdproduct=' + encodeURIComponent($('#name').val());
window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($('#name').val());
}
else
{
@ -123,7 +124,9 @@ $('.save-product-button').on('click', function(e)
);
});
Grocy.Api.Get('stock/products/' + Grocy.EditObjectId,
if (Grocy.EditMode == "edit")
{
Grocy.Api.Get('stock/products/' + Grocy.EditObjectId,
function(productDetails)
{
if (productDetails.last_purchased == null)
@ -135,16 +138,20 @@ Grocy.Api.Get('stock/products/' + Grocy.EditObjectId,
{
console.error(xhr);
}
);
);
}
var prefillName = GetUriParam('prefillname');
if (prefillName !== undefined)
if (GetUriParam("flow") == "InplaceNewProductWithName")
{
$('#name').val(prefillName);
$('#name').val(GetUriParam("name"));
$('#name').focus();
}
var prefillBarcode = GetUriParam('prefillbarcode');
if (GetUriParam("flow") !== undefined)
{
$("#save-hint").addClass("d-none");
$(".save-product-button[data-location='return']").addClass("d-none");
}
$('.input-group-qu').on('change', function(e)
{
@ -171,6 +178,7 @@ $('#product-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
$(".input-group-qu").trigger("change");
$("#product-form select").trigger("select");
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
@ -180,42 +188,11 @@ $('#product-form input').keyup(function(event)
{
$("#qu-conversion-add-button").removeClass("disabled");
}
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
$("#barcode-add-button").addClass("disabled");
}
else
{
if (prefillBarcode === undefined)
{
$("#barcode-add-button").removeClass("disabled");
}
}
});
$('#product-form select').change(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
$("#barcode-add-button").addClass("disabled");
}
else
{
if (prefillBarcode === undefined)
{
$("#barcode-add-button").removeClass("disabled");
}
}
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
$("#qu-conversion-add-button").addClass("disabled");
}
else
{
$("#qu-conversion-add-button").removeClass("disabled");
}
});
$('#location_id').change(function(event)

View File

@ -58,18 +58,17 @@
Grocy.UISound.Success();
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
if (GetUriParam("flow") == "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = addBarcode;
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonForm.product_id;
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-addbarcodetoselection").addClass("d-none");
$("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
$('#barcode-lookup-disabled-hint').addClass('d-none');
$('#barcode-lookup-hint').removeClass('d-none');
window.history.replaceState({}, document.title, U("/purchase"));
@ -96,6 +95,7 @@
{
Grocy.FrontendHelpers.EndUiBusy("purchase-form");
toastr.success(successMessage);
Grocy.Components.ProductPicker.FinishFlow();
Grocy.Components.ProductAmountPicker.Reset();
$("#display_amount").attr("min", "1");
@ -325,13 +325,18 @@ Grocy.FrontendHelpers.ValidateForm('purchase-form');
if (Grocy.Components.ProductPicker)
{
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
if (Grocy.Components.ProductPicker.InAnyFlow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
if (Grocy.Components.ProductPicker.InProductModifyWorkflow())
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
}
}

View File

@ -25,19 +25,18 @@
Grocy.Api.Post(apiUrl, jsonData,
function(result)
{
var addBarcode = GetUriParam('addbarcodetoselection');
bookingResponse = result;
if (addBarcode !== undefined)
if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = addBarcode;
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonForm.product_id;
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-addbarcodetoselection").addClass("d-none");
$("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
$('#barcode-lookup-disabled-hint').addClass('d-none');
$('#barcode-lookup-hint').removeClass('d-none');
window.history.replaceState({}, document.title, U("/transfer"));
@ -69,6 +68,7 @@
{
Grocy.FrontendHelpers.EndUiBusy("transfer-form");
toastr.success(successMessage);
Grocy.Components.ProductPicker.FinishFlow();
if (parseInt($("#location_id_from option:selected").attr("data-is-freezer")) === 0 && parseInt($("#location_id_to option:selected").attr("data-is-freezer")) === 1) // Frozen
{

View File

@ -60,8 +60,8 @@
<div class="invalid-feedback">{{ $__t('You have to select a product') }}</div>
<div id="custom-productpicker-error"
class="form-text text-danger d-none"></div>
<div id="flow-info-addbarcodetoselection"
class="form-text text-info small d-none"><strong><span id="addbarcodetoselection"></span></strong> {{ $__t('will be added to the list of barcodes for the selected product on submit') }}</div>
<div id="flow-info-InplaceAddBarcodeToExistingProduct"
class="form-text text-info small d-none"><strong><span id="InplaceAddBarcodeToExistingProduct"></span></strong> {{ $__t('will be added to the list of barcodes for the selected product on submit') }}</div>
</div>
@include('components.barcodescanner')

View File

@ -356,7 +356,8 @@
'entity' => 'products'
))
<small class="my-2 form-text text-muted @if($mode == 'edit') d-none @endif">{{ $__t('Save & continue to add quantity unit conversions & barcodes') }}</small>
<small id="save-hint"
class="my-2 form-text text-muted @if($mode == 'edit') d-none @endif">{{ $__t('Save & continue to add quantity unit conversions & barcodes') }}</small>
<button id="save-product-button"
class="save-product-button btn btn-success mb-2"