From 4b974407b3ffe0c55e2d7a359346d2963b0d0fd1 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 7 Aug 2022 14:38:20 +0200 Subject: bar code scanner inside direct approve page --- server/templates/server/approve_doc_direct.html | 67 ++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'server/templates') diff --git a/server/templates/server/approve_doc_direct.html b/server/templates/server/approve_doc_direct.html index 2a6710b..a435b5f 100644 --- a/server/templates/server/approve_doc_direct.html +++ b/server/templates/server/approve_doc_direct.html @@ -36,6 +36,10 @@ +
+
+ Scansiona un nuovo documento +
{% elif not error%}
@@ -51,7 +55,7 @@ - @@ -63,7 +67,7 @@
{% else %}
- {{error}} +
{% endif %} @@ -72,7 +76,17 @@ {% endblock %} +{% block script_import %} + +{% endblock %} + {% block script %} +document.addEventListener('DOMContentLoaded', function() { + {% if error and error != -1 %} + M.toast({html: '{{ error }}', classes: 'orange'}) + {% endif %} +}); + function confirm() { var button = document.getElementById('send_button') var button_small = document.getElementById('send_button_small') @@ -90,4 +104,53 @@ function send() { action.setAttribute('value', {{doc.code}}); form.submit() } + +{% if error %} +function loadCode(code) { + if (code.substring(0, 4) == 'http') { + window.location.replace(code); + return; + } + + var currentUrl = window.location.href; + var currentUrl = currentUrl.split('?')[0]; + if (currentUrl[currentUrl.length - 1] == '/') { + currentUrl = currentUrl.substring(0, currentUrl.length - 1); + } + var newUrl = currentUrl + "?code=" + code; + window.location.replace(newUrl); + return; +} + +let qrboxFunction = function(viewfinderWidth, viewfinderHeight) { + let minEdgePercentage = 0.7; // 70% + let minEdgeSize = Math.min(viewfinderWidth, viewfinderHeight); + let qrboxSize = Math.floor(minEdgeSize * minEdgePercentage); + let size = viewfinderWidth * minEdgePercentage; + return { + width: size, + height: size*0.25, + }; +} + +const html5QrCode = new Html5Qrcode("reader"); +html5QrCode.start( + { facingMode: "environment" }, + { + fps: 10, + qrbox: qrboxFunction, + }, + (decodedText, decodedResult) => { + loadCode(decodedText); + html5QrCode.stop(); + }, + (errorMessage) => {} + ) +.catch((err) => { + // start failed + console.log(`Error starting. Reason: ${err}`) + M.toast({html: 'Collegamento alla telecamera non riuscito. Riprovare.', classes: 'orange'}) +}); +{% endif %} + {% endblock %} \ No newline at end of file -- cgit v1.2.1