fix: support options

fix: bundle files
This commit is contained in:
Safwan Samsudeen 2026-02-27 18:38:58 +05:30
parent 97c3ce6408
commit 6e344db222
5 changed files with 36 additions and 46 deletions

View file

@ -500,15 +500,14 @@ frappe.ui.form.PrintView = class {
.find("body")
.html(`<div class="print-format print-format-preview">${out.html}</div>`);
const iframeDoc = this.$print_format_body[0];
const script = iframeDoc.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/jsbarcode@3/dist/JsBarcode.all.min.js";
script.onload = () => {
iframeDoc.querySelectorAll("svg[data-barcode-value]").forEach((el) => {
JsBarcode(el, el.dataset.barcodeValue, { width: 3, height: 50, fontSize: 16 });
el.setAttribute("width", "100%");
iframeDoc.querySelectorAll("svg[data-barcode-value]").forEach((el) => {
const get_options = frappe.ui.form.ControlBarcode.prototype.get_options.bind({
df: { options: el.dataset.options },
});
};
iframeDoc.head.appendChild(script);
console.log(get_options(el.dataset.barcodeValue));
JsBarcode(el, el.dataset.barcodeValue, get_options(el.dataset.barcodeValue));
el.setAttribute("width", "100%");
});
this.show_footer();
this.$print_format_body.find(".print-format").css({

View file

@ -64,7 +64,7 @@ frappe.ui.form.ControlBarcode = class ControlBarcode extends frappe.ui.form.Cont
options.height = "50";
if (frappe.utils.is_json(this.df.options)) {
options = JSON.parse(this.df.options);
Object.assign(options, JSON.parse(this.df.options));
if (options.format && options.format === "EAN") {
options.format = value.length == 8 ? "EAN8" : "EAN13";
}

View file

@ -0,0 +1,25 @@
import JsBarcode from "jsbarcode";
function get_options(value, df_options = null) {
let options = {};
options.fontSize = "16";
options.width = "3";
options.height = "50";
if (df_options) {
Object.assign(options, JSON.parse(df_options));
if (options.format && options.format === "EAN") {
options.format = value.length == 8 ? "EAN8" : "EAN13";
}
}
return options;
}
window.render_barcode = (el) => {
const value = el.dataset.barcodeValue;
try {
JsBarcode(el, value, get_options(value, el.dataset.options));
el.setAttribute("width", "100%");
} catch (e) {
console.log(e);
}
};

View file

@ -158,8 +158,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}"
<img src="{{ doc[df.fieldname] }}" class="signature-img img-responsive"
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}>
{% elif df.fieldtype=="Barcode" %}
<svg data-barcode-value="{{ doc[df.fieldname] }}" height="80"></svg>
<script>get_barcode_html("{{ doc[df.fieldname] }}");</script>
<svg data-barcode-value="{{ doc[df.fieldname] }}" height="80" data-options='{{ df.options }}'></svg>
{% elif df.fieldtype in ("Attach", "Attach Image") and frappe.utils.is_image(doc[df.fieldname]) %}
<img src="{{ doc[df.fieldname] }}" class="img-responsive"
{%- if df.print_width %} style="width: {{ get_width(df) }};"{% endif %}>

View file

@ -6,41 +6,7 @@
<title>{{ title }}</title>
<meta name="generator" content="frappe">
{{ include_style('print.bundle.css') }}
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3/dist/JsBarcode.all.min.js"></script>
<script>
function get_options(value) {
// get JsBarcode options
let options = {};
options.fontSize = "16";
options.width = "3";
options.height = "50";
// options.format = value.length == 8 ? "EAN8" : "EAN13";
// if (frappe.utils.is_json(this.df.options)) {
// options = JSON.parse(this.df.options);
// if (options.format && options.format === "EAN") {
// options.format = value.length == 8 ? "EAN8" : "EAN13";
// }
// }
return options;
}
function get_barcode_html(value) {
if (value) {
// Get svg
const svg = document.querySelector(`[data-barcode-value="${value}"]`);
try {
JsBarcode(svg, value, get_options(value));
$(svg).attr("width", "100%");
return 'hey';
} catch (e) {
console.log(e)
}
}
}
</script>
{{ include_script('print.bundle.js') }}
{% if print_style %}
<style>
{{ print_style }}
@ -78,6 +44,7 @@
footer_html.style.order = 1;
footer_html.style.marginTop = '20px';
}
document.querySelectorAll("svg[data-barcode-value]").forEach(render_barcode)
});
</script>
</body>