Skip to content
Snippets Groups Projects
Commit 3ef42e24 authored by Tomáš Hozman's avatar Tomáš Hozman
Browse files

no online signature, 2 pdf versions

parent 7454e5bb
Branches
No related tags found
No related merge requests found
...@@ -43,9 +43,6 @@ ...@@ -43,9 +43,6 @@
<script <script
src="static/js/jquery.min.js" src="static/js/jquery.min.js"
></script> ></script>
<script
src="static/js/jSignature.min.js"
></script>
<script <script
src="static/js/jspdf.umd.min.js" src="static/js/jspdf.umd.min.js"
></script> ></script>
...@@ -152,13 +149,14 @@ ...@@ -152,13 +149,14 @@
<select <select
id="card-type" id="card-type"
> >
<option>1. a 2. kolo</option>
<option>1. kolo</option> <option>1. kolo</option>
<option>2. kolo</option> <option>2. kolo</option>
</select> </select>
<input <input
type="submit" type="submit"
id="create-filled-form" id="finish"
value="Podepsat" value="Podepsat"
> >
...@@ -169,41 +167,6 @@ ...@@ -169,41 +167,6 @@
</div> </div>
<div id="step2"> <div id="step2">
<h2>Podpis</h2>
<a
href="#"
id="show-document"
>
Zobrazit dokument
</a>
<div id="signature-info-wrapper">
V
<input
type="text"
id="signature-location"
placeholder="Místo"
>
dne <input
type="text"
id="current-date"
placeholder="Datum"
>
</div>
<div id="signature-wrapper">
<div id="signature"></div>
<div id="signature-bottom">
<button class="button-small" id="signature-undo">Smazat</button>
<i>Myší nebo prstem nakresli podpis</i>
</div>
</div>
<button id="finish">Předat úřadu</button>
</div>
<div id="step3">
<div id="found-office"> <div id="found-office">
<h2>Úřad jsme našli automaticky.</h2> <h2>Úřad jsme našli automaticky.</h2>
...@@ -231,15 +194,11 @@ ...@@ -231,15 +194,11 @@
demokracie! demokracie!
</p> </p>
<button id="download-pdf">Stáhnout PDF</button> <button id="download-paper-pdf">Stáhnout PDF (osobní předání)</button>
<button id="download-electronic-pdf">Stáhnout PDF (datová schránka)</button>
</div> </div>
<div id="canvas-wrapper"> <div id="canvas-wrapper">
<a
href="#"
id="back-to-step2"
>Zpět</a>
<canvas id="page-1-canvas" width="2480" height="3507"></canvas> <canvas id="page-1-canvas" width="2480" height="3507"></canvas>
<canvas id="page-2-canvas" width="2480" height="3507"></canvas> <canvas id="page-2-canvas" width="2480" height="3507"></canvas>
</div> </div>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
padding-bottom:20px padding-bottom:20px
} }
#found-office,#not-found-office,#step3 { #found-office,#not-found-office,#step2 {
display:none display:none
} }
...@@ -79,18 +79,13 @@ ...@@ -79,18 +79,13 @@
max-width:600px max-width:600px
} }
#step1,#step2,#step3,#canvas-wrapper { #step1,#step2,#canvas-wrapper {
margin-left:auto; margin-left:auto;
margin-right:auto; margin-right:auto;
max-width:1000px; max-width:1000px;
padding-top:40px padding-top:40px
} }
#step2 {
display:none;
text-align:center
}
.button-small { .button-small {
font-size:small; font-size:small;
padding:4px 7px padding:4px 7px
...@@ -186,7 +181,7 @@ textarea { ...@@ -186,7 +181,7 @@ textarea {
} }
@media screen and (max-width:1200px) { @media screen and (max-width:1200px) {
#step1,#step2,#step3,#canvas-wrapper { #step1,#step2,#canvas-wrapper {
padding-top:0 padding-top:0
} }
......
This diff is collapsed.
...@@ -108,27 +108,40 @@ const fillCanvas = async () => { ...@@ -108,27 +108,40 @@ const fillCanvas = async () => {
const roundCheckSharedY = firstPageCanvas.width * 0.185; const roundCheckSharedY = firstPageCanvas.width * 0.185;
let electionDate = ""; let electionDate = "";
const createCheckRound1 = () => {
createCheck(
firstPageContext,
firstPageCanvas,
roundCheckSharedY,
firstPageCanvas.height * 0.3853
);
electionDate = "13. ledna 2023 - 14. ledna 2023";
}
const createCheckRound2 = () => {
createCheck(
firstPageContext,
firstPageCanvas,
roundCheckSharedY,
firstPageCanvas.height * 0.404
);
electionDate = "27. ledna 2023 - 28. ledna 2023";
}
switch ($("#card-type").val()) { switch ($("#card-type").val()) {
case "1. kolo": case "1. a 2. kolo":
createCheck( createCheckRound1();
firstPageContext, createCheckRound2();
firstPageCanvas,
roundCheckSharedY,
firstPageCanvas.height * 0.3853
);
electionDate = "13. ledna 2023 - 14. ledna 2023"; break;
case "1. kolo":
createCheckRound1();
break; break;
case "2. kolo": case "2. kolo":
createCheck( createCheckRound2();
firstPageContext,
firstPageCanvas,
roundCheckSharedY,
firstPageCanvas.height * 0.404
);
electionDate = "27. ledna 2023 - 28. ledna 2023";
break; break;
} }
...@@ -345,7 +358,7 @@ $(window).ready( ...@@ -345,7 +358,7 @@ $(window).ready(
} }
); );
$("#create-filled-form").on( $("#finish").on(
"click", "click",
async (event) => { async (event) => {
if ($("#form-wrapper")[0].checkValidity()) { if ($("#form-wrapper")[0].checkValidity()) {
...@@ -361,121 +374,8 @@ $(window).ready( ...@@ -361,121 +374,8 @@ $(window).ready(
await fillCanvas(); await fillCanvas();
await new Promise(
resolve => { $("#step1").fadeOut(200, resolve); }
);
$("#step1").css("display", "none");
await new Promise(
resolve => { $("#step2").fadeIn(200, resolve); }
);
$("#signature").jSignature();
}
);
$("#signature-undo").on(
"click",
(event) => {
$("#signature").jSignature("reset");
}
);
$("#show-document").on(
"click",
async (event) => {
await new Promise(
resolve => { $("#step2").fadeOut(200, resolve); }
);
$("#step2").css("display", "none");
await new Promise(
resolve => { $("#canvas-wrapper").fadeIn(200, resolve); }
);
}
);
$("#back-to-step2").on(
"click",
async (event) => {
await new Promise(
resolve => { $("#canvas-wrapper").fadeOut(200, resolve); }
);
$("#canvas-wrapper").css("display", "none");
await new Promise(
resolve => { $("#step2").fadeIn(200, resolve); }
);
}
);
$("#finish").on(
"click",
async (event) => {
// Canvas
const secondPageCanvas = document.getElementById("page-2-canvas");
const secondPageContext = secondPageCanvas.getContext("2d");
// Date
const desiredCurrentDate = $("#current-date").val()
setHighestPossibleFontSize(
secondPageContext,
desiredCurrentDate,
"Open Sans",
secondPageCanvas.height * 0.013,
secondPageCanvas.width * 0.32
);
secondPageContext.fillText(
desiredCurrentDate,
secondPageCanvas.width * 0.56, secondPageCanvas.height * 0.232
);
// Location
const location = $("#signature-location").val();
setHighestPossibleFontSize(
secondPageContext,
location,
"Open Sans",
secondPageCanvas.height * 0.013,
secondPageCanvas.width * 0.31
);
secondPageContext.fillText(
location,
secondPageCanvas.width * 0.155, secondPageCanvas.height * 0.232
);
// Signature
const signature = await getImage($("#signature").jSignature("getData"));
const signatureWidth = secondPageCanvas.width * 0.315;
const signatureHeight = (
signature.height
* (signatureWidth / signature.width)
);
console.log(signatureHeight, signatureWidth, signature);
secondPageContext.drawImage(
signature,
secondPageCanvas.width * 0.57, secondPageCanvas.height * 0.31 - signatureHeight,
signatureWidth, signatureHeight
);
// UI // UI
await new Promise(
resolve => { $("#step2").fadeOut(200, resolve); }
);
$("#step2").css("display", "none");
const city = $("#city").val(); const city = $("#city").val();
if (city in OFFICES) { if (city in OFFICES) {
...@@ -497,37 +397,64 @@ $(window).ready( ...@@ -497,37 +397,64 @@ $(window).ready(
} }
await new Promise( await new Promise(
resolve => { $("#step3").fadeIn(200, resolve); } resolve => { $("#step1").fadeOut(200, resolve); }
);
$("#step1").css("display", "none");
await new Promise(
resolve => { $("#step2").fadeIn(200, resolve); }
); );
} }
); );
$("#download-pdf").on( const createPdf = () => {
const pdfDocument = new jsPDF({
orientation: "portrait",
unit: "pt",
format: "a4"
});
pdfDocument.addImage(
document.getElementById("page-1-canvas"),
"JPEG",
0, 0,
595.28, 841.89
);
pdfDocument.addPage();
pdfDocument.addImage(
document.getElementById("page-2-canvas"),
"JPEG",
0, 0,
595.28, 841.89
);
pdfDocument.save("Přihláška k volebnímu průkazu.pdf");
}
$("#download-paper-pdf").on(
"click", "click",
() => { () => {
const pdfDocument = new jsPDF({ createPdf();
orientation: "portrait", }
unit: "pt", );
format: "a4"
}); $("#download-electronic-pdf").on(
"click",
pdfDocument.addImage( () => {
document.getElementById("page-1-canvas"), const secondPageCanvas = document.getElementById("page-2-canvas");
"JPEG", const secondPageContext = secondPageCanvas.getContext("2d");
0, 0, const canvasHeight = secondPageCanvas.height * 0.8;
595.28, 841.89
);
pdfDocument.addPage(); secondPageContext.fillStyle = "#ffffff";
pdfDocument.addImage( secondPageContext.fillRect(
document.getElementById("page-2-canvas"), 0, secondPageCanvas.height - canvasHeight,
"JPEG", secondPageCanvas.width, canvasHeight
0, 0,
595.28, 841.89
); );
pdfDocument.save("Přihláška k volebnímu průkazu.pdf"); createPdf();
} }
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment