correccion bug en firma modal

This commit is contained in:
humano 2017-11-03 14:22:40 -05:00
parent 2c4cf5ddf7
commit 3235eea178
7 changed files with 274 additions and 71 deletions

View File

@ -602,6 +602,8 @@ $uri = $_SERVER['REQUEST_URI'];
<?php $xajax->printJavascript("milfs/xajax/"); <?php $xajax->printJavascript("milfs/xajax/");
//$xajax->debugOn(); //$xajax->debugOn();
$xajax->statusMessagesOn(); $xajax->statusMessagesOn();
;?> ;?>
<style> <style>
@ -735,6 +737,7 @@ legend.legend-area {
<script src="./librerias/charts/utils.js"></script> <script src="./librerias/charts/utils.js"></script>
<script src="./librerias/lazy/jquery.lazy.min.js"></script> <script src="./librerias/lazy/jquery.lazy.min.js"></script>
<!-- morris --> <!-- morris -->
<!-- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css"> --> <!-- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css"> -->
<!-- <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script> --> <!-- <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script> -->
@ -905,6 +908,8 @@ $menu_lateral = "
<script src='librerias/calendar/lib/moment.min.js'></script> <script src='librerias/calendar/lib/moment.min.js'></script>
<script src='librerias/calendar/fullcalendar.min.js'></script> <script src='librerias/calendar/fullcalendar.min.js'></script>
<script src='librerias/calendar/locale/es.js'></script> <script src='librerias/calendar/locale/es.js'></script>
<script src="librerias/firma/signature_pad.js"></script>
<?php echo $css_adicional; ?> <?php echo $css_adicional; ?>
<?php if(!isset($_SESSION['id']) ){ ?> <?php if(!isset($_SESSION['id']) ){ ?>
@ -1206,6 +1211,10 @@ $eventos= "
<?php echo $onload; ?> <?php echo $onload; ?>
<?php } ?> <?php } ?>
<script src="librerias/firma/app.js"></script>
<script type="text/javascript" >
</script>
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {

View File

@ -1,5 +1,5 @@
var wrapper = document.getElementById("signature-pad"), var wrapper = document.getElementById("signature-pad"),
clearButton = wrapper.querySelector("[data-action=clear]"), // clearButton = wrapper.querySelector("[data-action=clear]"),
saveDataButton = wrapper.querySelector("[data-action=save-data]"), saveDataButton = wrapper.querySelector("[data-action=save-data]"),
canvas = wrapper.querySelector("canvas"), canvas = wrapper.querySelector("canvas"),
@ -23,7 +23,7 @@ resizeCanvas();
signaturePad = new SignaturePad(canvas); signaturePad = new SignaturePad(canvas);
clearButton.addEventListener("click", function (event) { document.getElementById('clear').addEventListener('click', function() {
signaturePad.clear(); signaturePad.clear();
}); });

51
librerias/firma/modal.php Normal file
View File

@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="signature-pad.css">
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css?'.time().'" >
<script src="../jquery/jquery-2.1.4.min.js" ></script>
<script src="../bootstrap/js/bootstrap.min.js" ></script>
</head>
<body >
<div id='signature-pad' class='m-signature-pad'>
<div class='m-signature-pad--body'>
<canvas onmouseout=" if (signaturePad.isEmpty()) { alert('Por favor firme primero.'); } else { saveViaAJAX(); }" id='canvas_firma' ></canvas>
</div>
<div class='m-signature-pad--footer'>
<div class='description'>Firme arriba</div>
<div class='left'>
<button type='button' id='clear' class='button clear btn-warning' data-action="clear" onclick="document.getElementById('<?php echo $_REQUEST[campo]?>[<?php echo $_REQUEST[item]?>]').value=''; ">Limpiar</button>
</div>
<!-- <div class='right'>
<button type='button' class='button save btn-success' data-action='save-data'>Confirmar firma</button>
</div> -->
</div>
</div>
<script type="text/javascript">
function saveViaAJAX()
{
var testCanvas = document.getElementById('canvas_firma');
var canvasData = testCanvas.toDataURL('image/svg+xml');
var postData = 'canvasData='+canvasData;
//mapa = window.parent.document.getElementById('<?php echo $_REQUEST[id]?>');
var debugConsole= window.parent.document.getElementById('<?php echo $_REQUEST[campo]?>[<?php echo $_REQUEST[item]?>]' );
debugConsole.value=canvasData;
}
</script>
<script src="signature_pad.js"></script>
<script src="app.js"></script>
</body>
</html>

View File

@ -1,3 +1,21 @@
.wrapper {
position: relative;
width: 400px;
height: 200px;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.signature-pad {
position: absolute;
left: 0;
top: 0;
width: 400px;
height: 200px;
background-color: white;
}
.m-signature-pad { .m-signature-pad {
position: inherit; position: inherit;
right: 0; right: 0;

149
librerias/firma/signature_pad.js Normal file → Executable file
View File

@ -1,5 +1,5 @@
/*! /*!
* Signature Pad v1.6.0-beta.5 * Signature Pad v2.3.2
* https://github.com/szimek/signature_pad * https://github.com/szimek/signature_pad
* *
* Copyright 2017 Szymon Nowak * Copyright 2017 Szymon Nowak
@ -36,6 +36,10 @@ Point.prototype.distanceTo = function (start) {
return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2)); return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
}; };
Point.prototype.equals = function (other) {
return this.x === other.x && this.y === other.y && this.time === other.time;
};
function Bezier(startPoint, control1, control2, endPoint) { function Bezier(startPoint, control1, control2, endPoint) {
this.startPoint = startPoint; this.startPoint = startPoint;
this.control1 = control1; this.control1 = control1;
@ -71,6 +75,41 @@ Bezier.prototype._point = function (t, start, c1, c2, end) {
return start * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * c1 * (1.0 - t) * (1.0 - t) * t + 3.0 * c2 * (1.0 - t) * t * t + end * t * t * t; return start * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * c1 * (1.0 - t) * (1.0 - t) * t + 3.0 * c2 * (1.0 - t) * t * t + end * t * t * t;
}; };
/* eslint-disable */
// http://stackoverflow.com/a/27078401/815507
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function later() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
}
function SignaturePad(canvas, options) { function SignaturePad(canvas, options) {
var self = this; var self = this;
var opts = options || {}; var opts = options || {};
@ -78,6 +117,15 @@ function SignaturePad(canvas, options) {
this.velocityFilterWeight = opts.velocityFilterWeight || 0.7; this.velocityFilterWeight = opts.velocityFilterWeight || 0.7;
this.minWidth = opts.minWidth || 0.5; this.minWidth = opts.minWidth || 0.5;
this.maxWidth = opts.maxWidth || 2.5; this.maxWidth = opts.maxWidth || 2.5;
this.throttle = 'throttle' in opts ? opts.throttle : 16; // in miliseconds
this.minDistance = 'minDistance' in opts ? opts.minDistance : 5;
if (this.throttle) {
this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
} else {
this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
}
this.dotSize = opts.dotSize || function () { this.dotSize = opts.dotSize || function () {
return (this.minWidth + this.maxWidth) / 2; return (this.minWidth + this.maxWidth) / 2;
}; };
@ -101,7 +149,7 @@ function SignaturePad(canvas, options) {
this._handleMouseMove = function (event) { this._handleMouseMove = function (event) {
if (self._mouseButtonDown) { if (self._mouseButtonDown) {
self._strokeUpdate(event); self._strokeMoveUpdate(event);
} }
}; };
@ -113,6 +161,9 @@ function SignaturePad(canvas, options) {
}; };
this._handleTouchStart = function (event) { this._handleTouchStart = function (event) {
// Prevent scrolling.
event.preventDefault();
if (event.targetTouches.length === 1) { if (event.targetTouches.length === 1) {
var touch = event.changedTouches[0]; var touch = event.changedTouches[0];
self._strokeBegin(touch); self._strokeBegin(touch);
@ -124,7 +175,7 @@ function SignaturePad(canvas, options) {
event.preventDefault(); event.preventDefault();
var touch = event.targetTouches[0]; var touch = event.targetTouches[0];
self._strokeUpdate(touch); self._strokeMoveUpdate(touch);
}; };
this._handleTouchEnd = function (event) { this._handleTouchEnd = function (event) {
@ -156,10 +207,12 @@ SignaturePad.prototype.clear = function () {
SignaturePad.prototype.fromDataURL = function (dataUrl) { SignaturePad.prototype.fromDataURL = function (dataUrl) {
var _this = this; var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var image = new Image(); var image = new Image();
var ratio = window.devicePixelRatio || 1; var ratio = options.ratio || window.devicePixelRatio || 1;
var width = this._canvas.width / ratio; var width = options.width || this._canvas.width / ratio;
var height = this._canvas.height / ratio; var height = options.height || this._canvas.height / ratio;
this._reset(); this._reset();
image.src = dataUrl; image.src = dataUrl;
@ -190,6 +243,10 @@ SignaturePad.prototype.on = function () {
}; };
SignaturePad.prototype.off = function () { SignaturePad.prototype.off = function () {
// Pass touch events to canvas element on mobile IE11 and Edge.
this._canvas.style.msTouchAction = 'auto';
this._canvas.style.touchAction = 'auto';
this._canvas.removeEventListener('mousedown', this._handleMouseDown); this._canvas.removeEventListener('mousedown', this._handleMouseDown);
this._canvas.removeEventListener('mousemove', this._handleMouseMove); this._canvas.removeEventListener('mousemove', this._handleMouseMove);
document.removeEventListener('mouseup', this._handleMouseUp); document.removeEventListener('mouseup', this._handleMouseUp);
@ -219,7 +276,12 @@ SignaturePad.prototype._strokeUpdate = function (event) {
var y = event.clientY; var y = event.clientY;
var point = this._createPoint(x, y); var point = this._createPoint(x, y);
var lastPointGroup = this._data[this._data.length - 1];
var lastPoint = lastPointGroup && lastPointGroup[lastPointGroup.length - 1];
var isLastPointTooClose = lastPoint && point.distanceTo(lastPoint) < this.minDistance;
// Skip this point if it's too close to the previous one
if (!(lastPoint && isLastPointTooClose)) {
var _addPoint = this._addPoint(point), var _addPoint = this._addPoint(point),
curve = _addPoint.curve, curve = _addPoint.curve,
widths = _addPoint.widths; widths = _addPoint.widths;
@ -231,18 +293,36 @@ SignaturePad.prototype._strokeUpdate = function (event) {
this._data[this._data.length - 1].push({ this._data[this._data.length - 1].push({
x: point.x, x: point.x,
y: point.y, y: point.y,
time: point.time time: point.time,
color: this.penColor
}); });
}
}; };
SignaturePad.prototype._strokeEnd = function (event) { SignaturePad.prototype._strokeEnd = function (event) {
var canDrawCurve = this.points.length > 2; var canDrawCurve = this.points.length > 2;
var point = this.points[0]; var point = this.points[0]; // Point instance
if (!canDrawCurve && point) { if (!canDrawCurve && point) {
this._drawDot(point); this._drawDot(point);
} }
if (point) {
var lastPointGroup = this._data[this._data.length - 1];
var lastPoint = lastPointGroup[lastPointGroup.length - 1]; // plain object
// When drawing a dot, there's only one point in a group, so without this check
// such group would end up with exactly the same 2 points.
if (!point.equals(lastPoint)) {
lastPointGroup.push({
x: point.x,
y: point.y,
time: point.time,
color: this.penColor
});
}
}
if (typeof this.onEnd === 'function') { if (typeof this.onEnd === 'function') {
this.onEnd(event); this.onEnd(event);
} }
@ -416,10 +496,16 @@ SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) {
for (var j = 0; j < group.length; j += 1) { for (var j = 0; j < group.length; j += 1) {
var rawPoint = group[j]; var rawPoint = group[j];
var point = new Point(rawPoint.x, rawPoint.y, rawPoint.time); var point = new Point(rawPoint.x, rawPoint.y, rawPoint.time);
var color = rawPoint.color;
if (j === 0) { if (j === 0) {
// First point in a group. Nothing to draw yet. // First point in a group. Nothing to draw yet.
// All points in the group have the same color, so it's enough to set
// penColor just at the beginning.
this.penColor = color;
this._reset(); this._reset();
this._addPoint(point); this._addPoint(point);
} else if (j !== group.length - 1) { } else if (j !== group.length - 1) {
// Middle point in a group. // Middle point in a group.
@ -428,7 +514,7 @@ SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) {
widths = _addPoint2.widths; widths = _addPoint2.widths;
if (curve && widths) { if (curve && widths) {
drawCurve(curve, widths); drawCurve(curve, widths, color);
} }
} else { } else {
// Last point in a group. Do nothing. // Last point in a group. Do nothing.
@ -447,17 +533,18 @@ SignaturePad.prototype._toSVG = function () {
var pointGroups = this._data; var pointGroups = this._data;
var canvas = this._canvas; var canvas = this._canvas;
var ratio = Math.max(window.devicePixelRatio || 1, 1);
var minX = 0; var minX = 0;
var minY = 0; var minY = 0;
var maxX = canvas.width; var maxX = canvas.width / ratio;
var maxY = canvas.height; var maxY = canvas.height / ratio;
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttributeNS(null, 'width', canvas.width); svg.setAttributeNS(null, 'width', canvas.width);
svg.setAttributeNS(null, 'height', canvas.height); svg.setAttributeNS(null, 'height', canvas.height);
this._fromData(pointGroups, function (curve, widths) { this._fromData(pointGroups, function (curve, widths, color) {
var path = document.createElementNS('http;//www.w3.org/2000/svg', 'path'); var path = document.createElement('path');
// Need to check curve for NaN values, these pop up when drawing // Need to check curve for NaN values, these pop up when drawing
// lines on the canvas that are not continuous. E.g. Sharp corners // lines on the canvas that are not continuous. E.g. Sharp corners
@ -466,27 +553,41 @@ SignaturePad.prototype._toSVG = function () {
var attr = 'M ' + curve.startPoint.x.toFixed(3) + ',' + curve.startPoint.y.toFixed(3) + ' ' + ('C ' + curve.control1.x.toFixed(3) + ',' + curve.control1.y.toFixed(3) + ' ') + (curve.control2.x.toFixed(3) + ',' + curve.control2.y.toFixed(3) + ' ') + (curve.endPoint.x.toFixed(3) + ',' + curve.endPoint.y.toFixed(3)); var attr = 'M ' + curve.startPoint.x.toFixed(3) + ',' + curve.startPoint.y.toFixed(3) + ' ' + ('C ' + curve.control1.x.toFixed(3) + ',' + curve.control1.y.toFixed(3) + ' ') + (curve.control2.x.toFixed(3) + ',' + curve.control2.y.toFixed(3) + ' ') + (curve.endPoint.x.toFixed(3) + ',' + curve.endPoint.y.toFixed(3));
path.setAttribute('d', attr); path.setAttribute('d', attr);
path.setAttributeNS(null, 'stroke-width', (widths.end * 2.25).toFixed(3)); path.setAttribute('stroke-width', (widths.end * 2.25).toFixed(3));
path.setAttributeNS(null, 'stroke', _this2.penColor); path.setAttribute('stroke', color);
path.setAttributeNS(null, 'fill', 'none'); path.setAttribute('fill', 'none');
path.setAttributeNS(null, 'stroke-linecap', 'round'); path.setAttribute('stroke-linecap', 'round');
svg.appendChild(path); svg.appendChild(path);
} }
}, function (rawPoint) { }, function (rawPoint) {
var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); var circle = document.createElement('circle');
var dotSize = typeof _this2.dotSize === 'function' ? _this2.dotSize() : _this2.dotSize; var dotSize = typeof _this2.dotSize === 'function' ? _this2.dotSize() : _this2.dotSize;
circle.setAttributeNS(null, 'r', dotSize); circle.setAttribute('r', dotSize);
circle.setAttributeNS(null, 'cx', rawPoint.x); circle.setAttribute('cx', rawPoint.x);
circle.setAttributeNS(null, 'cy', rawPoint.y); circle.setAttribute('cy', rawPoint.y);
circle.setAttributeNS(null, 'fill', _this2.penColor); circle.setAttribute('fill', rawPoint.color);
svg.appendChild(circle); svg.appendChild(circle);
}); });
var prefix = 'data:image/svg+xml;base64,'; var prefix = 'data:image/svg+xml;base64,';
var header = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="' + minX + ' ' + minY + ' ' + maxX + ' ' + maxY + '">'; var header = '<svg' + ' xmlns="http://www.w3.org/2000/svg"' + ' xmlns:xlink="http://www.w3.org/1999/xlink"' + (' viewBox="' + minX + ' ' + minY + ' ' + maxX + ' ' + maxY + '"') + (' width="' + maxX + '"') + (' height="' + maxY + '"') + '>';
var body = svg.innerHTML; var body = svg.innerHTML;
// IE hack for missing innerHTML property on SVGElement
if (body === undefined) {
var dummy = document.createElement('dummy');
var nodes = svg.childNodes;
dummy.innerHTML = '';
for (var i = 0; i < nodes.length; i += 1) {
dummy.appendChild(nodes[i].cloneNode(true));
}
body = dummy.innerHTML;
}
var footer = '</svg>'; var footer = '</svg>';
var data = header + body + footer; var data = header + body + footer;
@ -503,6 +604,8 @@ SignaturePad.prototype.fromData = function (pointGroups) {
}, function (rawPoint) { }, function (rawPoint) {
return _this3._drawDot(rawPoint); return _this3._drawDot(rawPoint);
}); });
this._data = pointGroups;
}; };
SignaturePad.prototype.toData = function () { SignaturePad.prototype.toData = function () {

51
librerias/modal.php Normal file
View File

@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="firma/signature-pad.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css?'.time().'" >
<script src="jquery/jquery-2.1.4.min.js" ></script>
<script src="bootstrap/js/bootstrap.min.js" ></script>
</head>
<body >
<div id='signature-pad' class='m-signature-pad'>
<div class='m-signature-pad--body'>
<canvas onmouseout=" if (signaturePad.isEmpty()) { alert('Por favor firme primero.'); } else { saveViaAJAX(); }" id='canvas_firma' ></canvas>
</div>
<div class='m-signature-pad--footer'>
<div class='description'>Firme arriba</div>
<div class='left'>
<button type='button' id='clear' class='button clear btn-warning' data-action="clear" onclick="document.getElementById('<?php echo $_REQUEST[campo]?>[<?php echo $_REQUEST[item]?>]').value=''; ">Limpiar</button>
</div>
<div class='right'>
<button type='button' class='button save btn-success' data-action='save-data'>Confirmar firma</button>
</div>
</div>
</div>
<script type="text/javascript">
function saveViaAJAX()
{
var testCanvas = document.getElementById('canvas_firma');
var canvasData = testCanvas.toDataURL('image/svg+xml');
var postData = 'canvasData='+canvasData;
//mapa = window.parent.document.getElementById('<?php echo $_REQUEST[id]?>');
var debugConsole= window.parent.document.getElementById('<?php echo $_REQUEST[campo]?>[<?php echo $_REQUEST[item]?>]' );
debugConsole.value=canvasData;
}
</script>
<script src="firma/signature_pad.js"></script>
<script src="firma/app.js"></script>
</body>
</html>

View File

@ -13431,37 +13431,8 @@ elseif($campo_tipo_accion == 'email'){$render = "
elseif($campo_tipo_accion == 'firma'){ elseif($campo_tipo_accion == 'firma'){
$render = " $render = "
<link href='librerias/firma/signature-pad.css' rel='stylesheet'>
<div id='signature-pad' class='m-signature-pad'>
<div class='m-signature-pad--body'>
<canvas id='canvas_firma' onmouseout=\" if (signaturePad.isEmpty()) { alert('Por favor firme primero.'); } else { saveViaAJAX(); }\" ></canvas>
</div>
<div class='m-signature-pad--footer'>
<div class='description'>Firme arriba</div>
<div class='left'>
<button type='button' class='button clear btn-warning' data-action=\"clear\" onclick=\"document.getElementById('$id_campo').value=''\">Limpiar</button>
</div>
<input type='hidden' id='".$id_campo."[".$item."]' name='".$id_campo."[".$item."]' > <input type='hidden' id='".$id_campo."[".$item."]' name='".$id_campo."[".$item."]' >
<div class='right'> <iframe width='100%' height='400px' src='librerias/firma/modal.php?campo=$id_campo&item=$item' frameborder='0' allowFullScreen ></iframe>
<button type='button' class='button save btn-success' data-action='save-data'>Confirmar firma</button>
</div>
</div>
</div>
<script type=\"text/javascript\">
function saveViaAJAX()
{
var testCanvas = document.getElementById('canvas_firma');
var canvasData = testCanvas.toDataURL('image/svg+xml');
var postData = 'canvasData='+canvasData;
var debugConsole= document.getElementById('".$id_campo."[".$item."]' );
debugConsole.value=canvasData;
}
</script>
<script src=\"librerias/firma/signature_pad.js\"></script>
<script src=\"librerias/firma/app.js\"></script>
"; ";
$cols='12'; $cols='12';
} }
@ -13992,7 +13963,7 @@ $mensaje_agradecimiento = remplacetas('form_parametrizacion','campo',"$formulari
$envio $envio
</div> </div>
</div> </div>
</div> $mostrar_json"; </div> <!-- $mostrar_json -->";
// $mail ='1'; // $mail ='1';
} }