Add remote signature pad (close #11)
parent
068640c548
commit
34fd854a99
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2021 Netsyms Technologies.
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*
|
||||
Created on : Jul 17, 2021, 12:29:13 PM
|
||||
Author : Skylar Ittner
|
||||
*/
|
||||
|
||||
select option {
|
||||
color: var(--bs-dark);
|
||||
}
|
||||
|
||||
.alert {
|
||||
color: var(--bs-dark);
|
||||
}
|
||||
|
||||
.theme-purple {
|
||||
background-image: linear-gradient(90deg,#33b7e2,#5e62b0,#dc307c);
|
||||
}
|
||||
|
||||
.theme-green {
|
||||
background-image: linear-gradient(90deg, #9ebd13 0%, #008552 100%);
|
||||
}
|
||||
|
||||
.theme-red {
|
||||
background-image: linear-gradient(90deg, #d53369 0%, #daae51 100%);
|
||||
}
|
||||
|
||||
.theme-aqua {
|
||||
background-image: linear-gradient(90deg, #00d2ff 0%, #3a47d5 100%);
|
||||
}
|
||||
|
||||
.theme-ocean {
|
||||
background-image: linear-gradient(90deg, #1CB5E0 0%, #000851 100%);
|
||||
}
|
||||
|
||||
.theme-dusty {
|
||||
background-image: linear-gradient(90deg, #fcff9e 0%, #c67700 100%);
|
||||
}
|
||||
|
||||
.theme-lilac {
|
||||
background-image: linear-gradient(90deg, #efd5ff 0%, #515ada 100%);
|
||||
}
|
||||
|
||||
.theme-spring {
|
||||
background-image: linear-gradient(90deg, #00C9FF 0%, #92FE9D 100%);
|
||||
}
|
||||
|
||||
.theme-shadow {
|
||||
background-image: linear-gradient(90deg, #4b6cb7 0%, #182848 100%);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2021 Netsyms Technologies.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
const http_port = 36744; // dialed ENSIG on phone keypad (eNotary Signature)
|
||||
var http = require('http');
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
|
||||
if (req.method == "GET") {
|
||||
console.log("Serving " + req.url);
|
||||
switch (req.url) {
|
||||
case "/":
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
var index = getFileAsString("./sigserver/index.html");
|
||||
index = index.replace("theme-BLANK", "theme-" + getStorage("color_theme"));
|
||||
res.end(index);
|
||||
break;
|
||||
case "/bootstrap.min.css":
|
||||
res.writeHead(200, {'Content-Type': 'text/css'});
|
||||
res.end(getFileAsString("./css/bootstrap.min.css"));
|
||||
break;
|
||||
case "/theme.css":
|
||||
res.writeHead(200, {'Content-Type': 'text/css'});
|
||||
res.end(getFileAsString("./css/theme.css"));
|
||||
break;
|
||||
case "/fontawesome/all.min.js":
|
||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
||||
res.end(getFileAsString("./node_modules/@fortawesome/fontawesome-free/js/all.min.js"));
|
||||
break;
|
||||
case "/signature_pad.umd.min.js":
|
||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
||||
res.end(getFileAsString("./node_modules/signature_pad/dist/signature_pad.umd.min.js"));
|
||||
break;
|
||||
case "/img/signature-line.svg":
|
||||
res.writeHead(200, {'Content-Type': 'image/svg+xml'});
|
||||
res.end(getFileAsString("./img/signature-line.svg"));
|
||||
break;
|
||||
default:
|
||||
res.writeHead(404);
|
||||
res.end("404 not found.");
|
||||
}
|
||||
} else if (req.method == "POST") {
|
||||
var body = '';
|
||||
req.on('data', function (data) {
|
||||
body += data;
|
||||
});
|
||||
req.on('end', function () {
|
||||
handleRemoteSignatureData(JSON.parse(body));
|
||||
});
|
||||
res.writeHead(201);
|
||||
}
|
||||
});
|
||||
server.listen(http_port); //3 - listen for any incoming requests
|
||||
console.log('Signature collection pad service running on port ' + http_port + '.');
|
||||
|
||||
function getSignatureServerUrl() {
|
||||
const prepareUrls = require('local-ip-url/prepareUrls');
|
||||
var urls = prepareUrls({
|
||||
protocol: 'http',
|
||||
host: '0.0.0.0',
|
||||
port: http_port
|
||||
});
|
||||
return urls.lanUrl;
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright 2021 Netsyms Technologies.
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Signature Pad</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="theme.css" />
|
||||
<script src="fontawesome/all.min.js"></script>
|
||||
<script src="signature_pad.umd.min.js"></script>
|
||||
<style>
|
||||
.signature-wrapper {
|
||||
background-color: transparent;
|
||||
background-image: linear-gradient(125deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.2) 70%);
|
||||
box-shadow: inset 1px 1px rgba(255, 255, 255, 0.2), inset -1px -1px rgba(255, 255, 255, 0.1), 1px 3px 24px -1px rgba(0, 0, 0, 0.15);
|
||||
border-radius: 0 0 0.5rem 0.5rem;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0 auto;
|
||||
/* fix bug on iOS where image sticks out right side and makes entire page scroll horiz. */
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.signature-wrapper img {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.signature-wrapper canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="theme-BLANK">
|
||||
<div class="card" style="width: calc(100vw - 1rem); height: calc(100vh - 1rem); margin: 0.5rem;">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h6 class="card-title mb-0">Signature Pad</h6>
|
||||
<div class="btn btn-warning btn-sm" onclick="resizeSignaturePadCanvas();signaturePad.clear();"><i class="fas fa-eraser"></i> Erase</div>
|
||||
<div class="btn btn-primary btn-sm" onclick="signaturePadUndo();"><i class="fas fa-undo"></i> Undo</div>
|
||||
<div class="btn btn-success btn-sm" onclick="sendSignature();"><i class="fas fa-check"></i> Done</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="signature-wrapper">
|
||||
<img src="img/signature-line.svg" />
|
||||
<canvas id="signaturecanvas"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var signaturePad = null;
|
||||
|
||||
function initSignaturePad() {
|
||||
var canvas = document.getElementById("signaturecanvas");
|
||||
signaturePad = new SignaturePad(canvas, {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.5)'
|
||||
});
|
||||
resizeSignaturePadCanvas();
|
||||
}
|
||||
|
||||
function resizeSignaturePadCanvas() {
|
||||
var canvas = document.getElementById("signaturecanvas");
|
||||
var ratio = Math.max(window.devicePixelRatio || 1, 1);
|
||||
canvas.width = canvas.offsetWidth * ratio;
|
||||
canvas.height = canvas.offsetHeight * ratio;
|
||||
canvas.getContext("2d").scale(ratio, ratio);
|
||||
if (signaturePad != null) {
|
||||
signaturePad.clear(); // otherwise isEmpty() might return incorrect value
|
||||
}
|
||||
}
|
||||
|
||||
function signaturePadUndo() {
|
||||
var data = signaturePad.toData();
|
||||
|
||||
resizeSignaturePadCanvas();
|
||||
|
||||
if (data) {
|
||||
data.pop(); // remove the last dot or line
|
||||
signaturePad.fromData(data);
|
||||
}
|
||||
}
|
||||
|
||||
function sendSignature() {
|
||||
var signature = signaturePad.toData();
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.open("POST", "/", true);
|
||||
xhttp.send(JSON.stringify(signature));
|
||||
}
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
initSignaturePad();
|
||||
});
|
||||
window.addEventListener('resize', function () {
|
||||
resizeSignaturePadCanvas();
|
||||
});
|
||||
window.addEventListener('orientationchange', function () {
|
||||
resizeSignaturePadCanvas();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue