From 886d0449e93dc332d0ee9386442dc78a3b9258f0 Mon Sep 17 00:00:00 2001 From: xgaia Date: Wed, 15 Apr 2020 16:54:38 +0200 Subject: [PATCH] optional qr code --- package.json | 7 +++++-- src/certificate.js | 47 ++++++++++++++++++++++++++-------------------- src/index.html | 8 ++++++-- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index caae57e..f6c2694 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,9 @@ "strategy": "default", "clearDist": false, "templatedURLs": { - "./": ["index.html"] - } } + "./": [ + "index.html" + ] + } + } } diff --git a/src/certificate.js b/src/certificate.js index 46f0778..817fa48 100644 --- a/src/certificate.js +++ b/src/certificate.js @@ -62,7 +62,11 @@ function saveProfile () { var dateSortie = field.value.split('-') localStorage.setItem(field.id.substring('field-'.length), `${dateSortie[2]}/${dateSortie[1]}/${dateSortie[0]}`) } else { - localStorage.setItem(field.id.substring('field-'.length), field.value) + if (field.id === "checkbox-qr") { + localStorage.setItem("generateQR", field.checked) + } else { + localStorage.setItem(field.id.substring('field-'.length), field.value) + } } } } @@ -158,29 +162,32 @@ async function generatePdf (profile, reasons) { drawText(releaseMinutes, 220, 201) } - // Date création - drawText('Date de création:', 464, 150, 7) - drawText(`${creationDate} à ${creationHour}`, 455, 144, 7) + // Générer un QR code si la case est cochée + if (profile.generateQR == "true") { // localStorage don't store boolean but string + // Date création + drawText('Date de création:', 464, 150, 7) + drawText(`${creationDate} à ${creationHour}`, 455, 144, 7) - const generatedQR = await generateQR(data) + const generatedQR = await generateQR(data) - const qrImage = await pdfDoc.embedPng(generatedQR) + const qrImage = await pdfDoc.embedPng(generatedQR) - page1.drawImage(qrImage, { - x: page1.getWidth() - 170, - y: 155, - width: 100, - height: 100, - }) + page1.drawImage(qrImage, { + x: page1.getWidth() - 170, + y: 155, + width: 100, + height: 100, + }) - pdfDoc.addPage() - const page2 = pdfDoc.getPages()[1] - page2.drawImage(qrImage, { - x: 50, - y: page2.getHeight() - 350, - width: 300, - height: 300, - }) + pdfDoc.addPage() + const page2 = pdfDoc.getPages()[1] + page2.drawImage(qrImage, { + x: 50, + y: page2.getHeight() - 350, + width: 300, + height: 300, + }) + } const pdfBytes = await pdfDoc.save() diff --git a/src/index.html b/src/index.html index 64408ed..fcc3e42 100644 --- a/src/index.html +++ b/src/index.html @@ -243,8 +243,12 @@

Remplissez en ligne votre attestation numérique :

- - + +
+ + +
+