diff --git a/public/js/extensions.js b/public/js/extensions.js index df3e80d6..eb6654da 100644 --- a/public/js/extensions.js +++ b/public/js/extensions.js @@ -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) diff --git a/public/viewjs/components/productpicker.js b/public/viewjs/components/productpicker.js index f57fb56b..87bf8c52 100644 --- a/public/viewjs/components/productpicker.js +++ b/public/viewjs/components/productpicker.js @@ -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)); } } } diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index e9155605..f4020faf 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -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"); diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index a7c5ae87..58077d9d 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -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) diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index d3f9d156..44ceaa1d 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -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,28 +124,34 @@ $('.save-product-button').on('click', function(e) ); }); -Grocy.Api.Get('stock/products/' + Grocy.EditObjectId, - function(productDetails) - { - if (productDetails.last_purchased == null) - { - $('#qu_id_stock').removeAttr("disabled"); - } - }, - function(xhr) - { - console.error(xhr); - } -); - -var prefillName = GetUriParam('prefillname'); -if (prefillName !== undefined) +if (Grocy.EditMode == "edit") { - $('#name').val(prefillName); + Grocy.Api.Get('stock/products/' + Grocy.EditObjectId, + function(productDetails) + { + if (productDetails.last_purchased == null) + { + $('#qu_id_stock').removeAttr("disabled"); + } + }, + function(xhr) + { + console.error(xhr); + } + ); +} + +if (GetUriParam("flow") == "InplaceNewProductWithName") +{ + $('#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) diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 53d99a30..92714cf7 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -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(); + } } } diff --git a/public/viewjs/transfer.js b/public/viewjs/transfer.js index 7b78f1b4..13d45016 100644 --- a/public/viewjs/transfer.js +++ b/public/viewjs/transfer.js @@ -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 { diff --git a/views/components/productpicker.blade.php b/views/components/productpicker.blade.php index 01764262..d634a8be 100644 --- a/views/components/productpicker.blade.php +++ b/views/components/productpicker.blade.php @@ -60,8 +60,8 @@
{{ $__t('You have to select a product') }}
-
{{ $__t('will be added to the list of barcodes for the selected product on submit') }}
+
{{ $__t('will be added to the list of barcodes for the selected product on submit') }}
@include('components.barcodescanner') diff --git a/views/productform.blade.php b/views/productform.blade.php index ae397b1c..dd70ed41 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -356,7 +356,8 @@ 'entity' => 'products' )) - {{ $__t('Save & continue to add quantity unit conversions & barcodes') }} + {{ $__t('Save & continue to add quantity unit conversions & barcodes') }}