Lager-v3/resources/views/Partials/Form/Signature/loaner.blade.php

121 lines
4.9 KiB
PHP

<script type="text/javascript">
// Initialize the image variables
var imgWidth;
var imgHeight;
// The Signature Pad Functions
function LoanerStartSign()
{
// Check if the Browser Extension is Installed
var isInstalled = document.documentElement.getAttribute('SigPlusExtLiteExtension-installed');
if (!isInstalled) {
alert("SigPlusExtLite extension is either not installed or disabled. Please install or enable extension.");
return;
}
// Get the Signature Canvas Object
var canvasObj = document.getElementById('loanerCanvas');
// Clear the Signature Canvas Object
canvasObj.getContext('2d').clearRect(0, 0, canvasObj.width, canvasObj.height);
// Reset the Data Containers
document.getElementById("loanerSigStringData").value = "";
document.getElementById("loanerSigRawData").value = "";
// Set the Signature Image dimensions
imgWidth = canvasObj.width;
imgHeight = canvasObj.height;
// Set the Data to be sent to the Signature Pad
var message = { "firstName": "", "lastName": "", "eMail": "", "location": "", "imageFormat": 1, "imageX": imgWidth, "imageY": imgHeight, "imageTransparency": false, "imageScaling": false, "maxUpScalePercent": 0.0, "rawDataFormat": "ENC", "minSigPoints": 25 };
// Add Event Listener
top.document.addEventListener('SignResponse', LoanerSignResponse, false);
// Prepare Data to be Sent
var messageData = JSON.stringify(message);
var element = document.createElement("MyLoanerExtensionDataElement");
element.setAttribute("messageAttribute", messageData);
document.documentElement.appendChild(element);
var evt = document.createEvent("Events");
//Send the Data to the Signature Pad
evt.initEvent("SignStartEvent", true, false);
element.dispatchEvent(evt);
}
// Get Response from the Signature Pad
function LoanerSignResponse(event)
{
var str = event.target.getAttribute("msgAttribute");
var obj = JSON.parse(str);
LoanerSetValues(obj, imgWidth, imgHeight);
}
// Set the Input from the Signature Pad into the Data Containers and the Canvas
function LoanerSetValues(objResponse, imageWidth, imageHeight)
{
var obj = null;
if(typeof(objResponse) === 'string'){
obj = JSON.parse(objResponse);
} else{
obj = JSON.parse(JSON.stringify(objResponse));
}
// Get the Canvas
var ctx = document.getElementById('loanerCanvas').getContext('2d');
// Check for Errors from the Signature Pad
if (obj.errorMsg != null && obj.errorMsg!="" && obj.errorMsg!="undefined")
{
// Display the Error Message
alert(obj.errorMsg);
}
// If No Errors
else
{
if (obj.isSigned)
{
// Put the Data into the Data Containers
document.getElementById("loanerSigRawData").value += obj.imageData;
document.getElementById("loanerSigStringData").value += obj.sigString;
// Draw the Image on the Canvas
var img = new Image();
img.onload = function ()
{
ctx.drawImage(img, 0, 0, imageWidth, imageHeight);
}
img.src = "data:image/png;base64," + obj.imageData;
// Disable the 'Sign' Button
var sign_button = document.getElementById('loanerSignButton');
sign_button.style.display = "none";
var loaner_confirm_field = document.getElementById('loaner_confirm');
loaner_confirm_field.innerHTML = '<i class="fas fa-check"></i> Underskrift modtaget';
}
}
}
</script>
<!-- Hide Data Containers -->
<style>
#loanerSigStringData, #loanerSigRawData,#loanerCanvas{
display:none;
}
</style>
<!-- The Loaner Signature Form -->
<div class="mb-3 row">
<div class="col-2 fw-bold">
@lang('loaner') :
</div>
<div class="col">
<canvas id="loanerCanvas" name="loanerCanvas" width="300" height="80"></canvas>
<button id="loanerSignButton" class="btn btn-secondary" onclick="LoanerStartSign()" @if(old('loanerSigRawData')) style="display:none;" @endif type="button">@lang('sign')</button>
<span id="loaner_confirm">@if(old('loanerSigRawData'))<i class="fas fa-check"></i> Underskrift modtaget @endif</span>
<!-- Data Containers -->
<textarea id="loanerSigStringData" name="loanerSigStringData" rows="20" cols="50">@if(old('loanerSigStringData')){{old('loanerSigStringData')}}@endif</textarea>
<textarea id="loanerSigRawData" name="loanerSigRawData" rows="20" cols="50" required>@if(old('loanerSigRawData')){{old('loanerSigRawData')}}@endif</textarea>
</div>
</div>