Label template
This commit is contained in:
117
sticker-print.js
117
sticker-print.js
@ -33,25 +33,49 @@ const TEMPLATES = {
|
||||
|
||||
^XZ
|
||||
`,
|
||||
qrCodePos: {
|
||||
x: 300,
|
||||
y: 10,
|
||||
agencyLogo: {
|
||||
dimensions: {
|
||||
width: 260,
|
||||
height: 73,
|
||||
},
|
||||
pos: {
|
||||
x: 20,
|
||||
y: 85,
|
||||
},
|
||||
},
|
||||
companyNamePos: {
|
||||
x: 20,
|
||||
y: 10,
|
||||
qrCode: {
|
||||
dimensions: {
|
||||
width: 250,
|
||||
height: 250,
|
||||
},
|
||||
pos: {
|
||||
x: 300,
|
||||
y: 10,
|
||||
},
|
||||
},
|
||||
machineModelPos: {
|
||||
x: 20,
|
||||
y: 180,
|
||||
companyName: {
|
||||
pos: {
|
||||
x: 20,
|
||||
y: 10,
|
||||
},
|
||||
},
|
||||
masterSystemIdPos: {
|
||||
x: 20,
|
||||
y: 210,
|
||||
machineModel: {
|
||||
pos: {
|
||||
x: 20,
|
||||
y: 180,
|
||||
},
|
||||
},
|
||||
extMasterSystemIdIdPos: {
|
||||
x: 20,
|
||||
y: 55,
|
||||
masterSystemId: {
|
||||
pos: {
|
||||
x: 20,
|
||||
y: 210,
|
||||
},
|
||||
},
|
||||
extMasterSystemIdId: {
|
||||
pos: {
|
||||
x: 20,
|
||||
y: 55,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -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,
|
||||
companyName: "Vandelay Industries",
|
||||
machineModel: "Model XL-123",
|
||||
masterSystemId: "master-system-id",
|
||||
extMasterSystemId: "ext-msid",
|
||||
});
|
||||
function createInternalStickerZPL(options) {
|
||||
const templateName = "sticker-70x35";
|
||||
const template = TEMPLATES[templateName];
|
||||
|
||||
document.querySelector(`textarea[name="zpl"]`).value = internalTicketZPL;
|
||||
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",
|
||||
};
|
||||
|
||||
createInternalStickerZPL(options).then((zpl) => {
|
||||
document.querySelector(`textarea[name="zpl"]`).value = zpl;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user