Label template

This commit is contained in:
Eden Kirin
2023-07-31 14:45:16 +02:00
parent 6136d35dff
commit 13ddd7d2b4
2 changed files with 79 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View File

@ -33,27 +33,51 @@ const TEMPLATES = {
^XZ
`,
qrCodePos: {
agencyLogo: {
dimensions: {
width: 260,
height: 73,
},
pos: {
x: 20,
y: 85,
},
},
qrCode: {
dimensions: {
width: 250,
height: 250,
},
pos: {
x: 300,
y: 10,
},
companyNamePos: {
},
companyName: {
pos: {
x: 20,
y: 10,
},
machineModelPos: {
},
machineModel: {
pos: {
x: 20,
y: 180,
},
masterSystemIdPos: {
},
masterSystemId: {
pos: {
x: 20,
y: 210,
},
extMasterSystemIdIdPos: {
},
extMasterSystemIdId: {
pos: {
x: 20,
y: 55,
},
},
},
};
function replaceTemplateVars(template, vars) {
@ -69,25 +93,25 @@ function replaceTemplateVars(template, vars) {
return trimmed;
}
function createInternalStickerZPL(templateName, vars) {
function renderInternalStickerTemplate(templateName, vars) {
const template = TEMPLATES[templateName];
return replaceTemplateVars(template.content, {
qrCodeZPL: vars.qrCodeZPL,
qrCodeXpos: template.qrCodePos.x,
qrCodeYpos: template.qrCodePos.y,
qrCodeXpos: template.qrCode.pos.x,
qrCodeYpos: template.qrCode.pos.y,
companyName: vars.companyName,
companyNameXpos: template.companyNamePos.x,
companyNameYpos: template.companyNamePos.y,
companyNameXpos: template.companyName.pos.x,
companyNameYpos: template.companyName.pos.y,
machineModel: vars.machineModel,
machineModelXpos: template.machineModelPos.x,
machineModelYpos: template.machineModelPos.y,
machineModelXpos: template.machineModel.pos.x,
machineModelYpos: template.machineModel.pos.y,
masterSystemId: vars.masterSystemId,
masterSystemIdXpos: template.masterSystemIdPos.x,
masterSystemIdYpos: template.masterSystemIdPos.y,
masterSystemIdXpos: template.masterSystemId.pos.x,
masterSystemIdYpos: template.masterSystemId.pos.y,
extMasterSystemId: vars.extMasterSystemId,
extMasterSystemIdXpos: template.extMasterSystemIdIdPos.x,
extMasterSystemIdYpos: template.extMasterSystemIdIdPos.y,
extMasterSystemIdXpos: template.extMasterSystemIdId.pos.x,
extMasterSystemIdYpos: template.extMasterSystemIdId.pos.y,
});
}
@ -122,17 +146,34 @@ function imageToGRF(imgUrl, options) {
});
}
imageToGRF("/assets/qr-code-example.jpeg", {
width: 250,
height: 250,
}).then((qrCodeZPL) => {
const internalTicketZPL = createInternalStickerZPL("sticker-70x35", {
qrCodeZPL: qrCodeZPL,
function createInternalStickerZPL(options) {
const templateName = "sticker-70x35";
const template = TEMPLATES[templateName];
return new Promise((resolve, reject) => {
imageToGRF(options.qrCodeUrl, {
width: template.qrCode.dimensions.width,
height: template.qrCode.dimensions.height,
}).then((qrCodeZPL) => {
const zpl = renderInternalStickerTemplate(templateName, {
qrCodeZPL,
...options,
});
resolve(zpl);
});
});
}
const options = {
qrCodeUrl: "/assets/qr-code-example.jpeg",
agencyLogoUrl: "/assets/agenzia-entrate-logo-color.png",
companyName: "Vandelay Industries",
machineModel: "Model XL-123",
masterSystemId: "master-system-id",
extMasterSystemId: "ext-msid",
});
};
document.querySelector(`textarea[name="zpl"]`).value = internalTicketZPL;
createInternalStickerZPL(options).then((zpl) => {
document.querySelector(`textarea[name="zpl"]`).value = zpl;
});