This commit is contained in:
@@ -102,22 +102,33 @@ try {
|
||||
}
|
||||
*/
|
||||
Handlebars.registerHelper("ayBC", function (text, options) {
|
||||
// options.text=text;
|
||||
let canvas = document.getElementById("aybarcode");
|
||||
if (canvas == null) {
|
||||
canvas = document.createElement("canvas");
|
||||
canvas.id = "aybarcode";
|
||||
}
|
||||
//let canvas = document.createElement("canvas");
|
||||
let opt = JSON.parse(options);
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
text = text.toString();
|
||||
}
|
||||
opt.text = text;
|
||||
opt.textxalign = "center";
|
||||
|
||||
let opt = {
|
||||
bcid: "code128", // Barcode type
|
||||
text: "0123456789", // Text to encode
|
||||
scale: 3, // 3x scaling factor
|
||||
height: 10, // Bar height, in millimeters
|
||||
includetext: true, // Show human-readable text
|
||||
textxalign: "center" // Always good to set this
|
||||
};
|
||||
if (opt.pad && opt.text) {
|
||||
//pad out the code by inserting leading zeros to the specified length
|
||||
opt.text = ayPad(opt.text, opt.pad, 0);
|
||||
}
|
||||
|
||||
// let opt = {
|
||||
// bcid: "code128", // Barcode type
|
||||
// text: "0123456789", // Text to encode
|
||||
// scale: 3, // 3x scaling factor
|
||||
// height: 10, // Bar height, in millimeters
|
||||
// includetext: true, // Show human-readable text
|
||||
// textxalign: "center" // Always good to set this
|
||||
// };
|
||||
|
||||
bwipjs.toCanvas(canvas, opt);
|
||||
var url = canvas.toDataURL("image/png");
|
||||
@@ -313,3 +324,10 @@ async function ayPostToAPI(route, data, token) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//Utils
|
||||
function ayPad(n, width, z) {
|
||||
z = z || "0";
|
||||
n = n + "";
|
||||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"Name":"EXAMPLE Bar code helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"<html>\n\n<body>\n\t<h2>Example: Bar code helper </h2>\n\t<p>See Report editor help documentation for details</p>\n\n\t{{#each ayReportData}}\n\t<h2>{{ Name }}</h2>\n\t<div>\n\t\tSerial as \"CODE-128\" BarCode:<br/>\n\t\t{{ ayBC Serial '{ \"bcid\": \"code128\",\"includetext\":true, \"scale\":1}' }}\n\t</div>\n\t<br/>\n\t<div>\n\t\tSerial as \"QR\" Code:<br/>\n\t\t{{ ayBC Serial '{ \"bcid\": \"qrcode\",\"includetext\":true, \"scale\":3}' }}\n\t</div>\n\t<br/>\n\t<div>\n\t\tSample \"UPC-A\" Code (Serial wouldn't be a valid UPC code so hard coded here):<br/>\n\t\t{{ ayBC \"712345678904\" '{ \"bcid\": \"upca\",\"includetext\":true, \"scale\":1}' }}\n\t</div>\n\t<br/>\n\t<br/>\n\t<hr/>\n\t{{/each}}\n</body>\n\n</html>","Style":".example {\n color: blue;\n}","JsPrerender":"async function ayPrepareData(reportData){ \n //this function (if present) is called with the report data \n //before the report is rendered\n //modify data as required here and return it to change the data before the report renders\n //see the help documentation for details\n return reportData;\n}","JsHelpers":"//Register custom Handlebars helpers here to use in your report script\n//https://handlebarsjs.com/guide/#custom-helpers\nHandlebars.registerHelper('loud', function (aString) {\n return aString.toUpperCase()\n})","RenderType":0}
|
||||
Reference in New Issue
Block a user