From 10f890ef89ed87d704eed02ff8e391fc6719943a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 13 Apr 2020 15:55:27 +0200 Subject: [PATCH] Added a camera-barcode-scanner-button to the barcodes field on the product edit page (closes #723) --- changelog/58_UNRELEASED_2020-xx-xx.md | 1 + public/viewjs/barcodescannertesting.js | 7 ++++++- public/viewjs/components/barcodescanner.js | 8 +++++--- public/viewjs/components/productpicker.js | 7 ++++++- public/viewjs/productform.js | 10 ++++++++++ views/barcodescannertesting.blade.php | 2 +- views/components/productpicker.blade.php | 2 +- views/productform.blade.php | 4 +++- 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/changelog/58_UNRELEASED_2020-xx-xx.md b/changelog/58_UNRELEASED_2020-xx-xx.md index 118ceca0..49e80743 100644 --- a/changelog/58_UNRELEASED_2020-xx-xx.md +++ b/changelog/58_UNRELEASED_2020-xx-xx.md @@ -8,6 +8,7 @@ ### Stock improvements/fixes - When creating a new product, the "QU id stock" is now preset by the "QU id purchase" (because most of the time that's most probably the same) (thanks @Mik-) - Clarified the row-button colors and toolips on the stock entries page +- Added a camera-barcode-scanning-button to the barcode(s) field on the product edit page to be able to also scan barcodes by the device camera there - Fixed that the aggregated parent product amount (displayed on the stock overview page and on the product card) did not respect quantity unit conversions when the parent/sub products had different stock quantity units (the unit conversion needs to be globally defined, or as an override on the sub product) - Fixed the conversion factor hint to display also decimal places on the purchase page (only displayed when the product has a different purchase/stock quantity unit) - Fixed that the stock entries page was broken when there were product userfields defined with enabled "Show as column in tables" diff --git a/public/viewjs/barcodescannertesting.js b/public/viewjs/barcodescannertesting.js index 2639ac91..15a86dc1 100644 --- a/public/viewjs/barcodescannertesting.js +++ b/public/viewjs/barcodescannertesting.js @@ -85,7 +85,12 @@ function OnBarcodeScanned(barcode) }, 200); } -$(document).on("Grocy.BarcodeScanned", function(e, barcode) +$(document).on("Grocy.BarcodeScanned", function(e, barcode, target) { + if (target !== "#scanned_barcod") + { + return; + } + OnBarcodeScanned(barcode); }); diff --git a/public/viewjs/components/barcodescanner.js b/public/viewjs/components/barcodescanner.js index dc21c717..440ae3b6 100644 --- a/public/viewjs/components/barcodescanner.js +++ b/public/viewjs/components/barcodescanner.js @@ -149,7 +149,7 @@ Quagga.onDetected(function(result) if (Grocy.Components.BarcodeScanner.DecodedCodesErrorCount / Grocy.Components.BarcodeScanner.DecodedCodesCount < 0.15) { Grocy.Components.BarcodeScanner.StopScanning(); - $(document).trigger("Grocy.BarcodeScanned", [result.codeResult.code]); + $(document).trigger("Grocy.BarcodeScanned", [result.codeResult.code, Grocy.Components.BarcodeScanner.CurrentTarget]); } }); @@ -195,6 +195,8 @@ $(document).on("click", "#barcodescanner-start-button", function(e) return; } + Grocy.Components.BarcodeScanner.CurrentTarget = inputElement.attr("data-target"); + bootbox.dialog({ message: '
', title: __t('Scan a barcode'), @@ -234,11 +236,11 @@ setTimeout(function() { if ($(this).hasAttr("disabled")) { - $(this).after(''); + $(this).after(''); } else { - $(this).after(''); + $(this).after(''); } }); }, 50); diff --git a/public/viewjs/components/productpicker.js b/public/viewjs/components/productpicker.js index 47280857..15649c85 100644 --- a/public/viewjs/components/productpicker.js +++ b/public/viewjs/components/productpicker.js @@ -227,8 +227,13 @@ $('#product_id_text_input').on('blur', function(e) } }); -$(document).on("Grocy.BarcodeScanned", function(e, barcode) +$(document).on("Grocy.BarcodeScanned", function(e, barcode, target) { + if (!(target == "@productpicker" || target == "undefined" || target == undefined)) // Default target + { + return; + } + // Don't know why the blur event does not fire immediately ... this works... Grocy.Components.ProductPicker.GetInputElement().focusout(); diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 488233a4..c2bbe6f2 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -434,3 +434,13 @@ $('#qu_id_purchase').blur(function(e) Grocy.FrontendHelpers.ValidateForm('product-form'); } }); + +$(document).on("Grocy.BarcodeScanned", function(e, barcode, target) +{ + if (target != "#barcode-taginput") + { + return; + } + + $("#barcode-taginput").tagsManager("pushTag", barcode); +}); diff --git a/views/barcodescannertesting.blade.php b/views/barcodescannertesting.blade.php index 5c1647df..c3d6725b 100644 --- a/views/barcodescannertesting.blade.php +++ b/views/barcodescannertesting.blade.php @@ -23,7 +23,7 @@
- +
diff --git a/views/components/productpicker.blade.php b/views/components/productpicker.blade.php index b6852d49..4cf715e0 100644 --- a/views/components/productpicker.blade.php +++ b/views/components/productpicker.blade.php @@ -14,7 +14,7 @@
- @foreach($products as $product) diff --git a/views/productform.blade.php b/views/productform.blade.php index 71f6867f..b30cf333 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -69,7 +69,9 @@
- +
+ +