From 116a2d3210cd945f720f62046d6ecf65b547526c Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Mon, 24 Jun 2024 16:29:34 +0000 Subject: [PATCH] Bug 26777: (Follow-up) Allow ability to select diffferent barcode types --- .../bootstrap/en/modules/opac-virtual-card.tt | 2 +- .../bootstrap/js/barcode-generator.js | 29 ++++++++++++------- opac/opac-virtual-card.pl | 4 +++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt index 85a727d947..628a772adc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-virtual-card.tt @@ -42,7 +42,7 @@ [% END %]
- +

Library: [% Branches.GetName( patron.branchcode ) | html %]

diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/barcode-generator.js b/koha-tmpl/opac-tmpl/bootstrap/js/barcode-generator.js index afd32f8284..e1adb2fc9a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/barcode-generator.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/barcode-generator.js @@ -1,11 +1,20 @@ document.addEventListener("DOMContentLoaded", function() { - var barcodeNumber = document.getElementById("patron-barcode").dataset.barcode; - JsBarcode("#patron-barcode", barcodeNumber, { - format: "CODE39", - lineColor: "#000", - width: 2, - height: 100, - displayValue: false, - margin: 0 - }); -}); \ No newline at end of file + const svgElement = document.getElementById('patron-barcode'); + var barcodeNumber = svgElement.dataset.barcode; + var barcodeFormat = svgElement.dataset.barcodeFormat; + + try { + JsBarcode("#patron-barcode", barcodeNumber, { + format: barcodeFormat, + lineColor: "#000", + width: 2, + height: 100, + displayValue: false, + margin: 0 + }); + } catch (error) { + // Handle the error by displaying a message on the screen + console.error(error); + document.getElementById('barcode-container').innerHTML = `

Error: "${error}"

`; + } +}); diff --git a/opac/opac-virtual-card.pl b/opac/opac-virtual-card.pl index 57bab5f493..e8767929e0 100755 --- a/opac/opac-virtual-card.pl +++ b/opac/opac-virtual-card.pl @@ -48,9 +48,13 @@ if ( C4::Context->preference('OPACpatronimages') ) { $template->param( display_patron_image => 1 ) if $patron->image; } +# Get the desired barcode format +my $barcode_format = C4::Context->preference('OPACVirtualCardBarcode'); + $template->param( virtualcardview => 1, patron => $patron, + barcode_format => $barcode_format, ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.2