This repository has been archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSignatureWidgetInput.php
76 lines (68 loc) · 2.06 KB
/
SignatureWidgetInput.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Created by PhpStorm.
* User: macbook
* Date: 10/29/17
* Time: 11:26 PM
*/
namespace inquid\signature;
use yii\base\Model;
use yii\widgets\InputWidget;
class SignatureWidgetInput extends InputWidget
{
public $model;
public $attribute;
public $width;
public $height;
public $clear = true;
public $change_color = false;
public $undo = true;
public $description;
private $action_buttons;
public function init()
{
if ($this->width === null)
$this->width = '500px';
if ($this->height === null)
$this->height = '300px';
if ($this->clear == true) {
$this->action_buttons .= '<button type="button" class="button clear" data-action="clear">Clear</button>';
}
if ($this->change_color == true) {
$this->action_buttons .= '<button type="button" class="button" data-action="change-color">Change color</button>';
}
if ($this->undo == true) {
$this->action_buttons .= '<button type="button" class="button" data-action="undo">Undo</button>';
}
SignatureAsset::register($this->view);
}
protected function hasModel()
{
return $this->model instanceof Model && $this->attribute !== null;
}
public function run()
{
$signature = '
<style>
canvas{
width: ' . $this->width . ';
height: ' . $this->height . ';
}
</style>
<div id="signature-pad" class="signature-pad">
<div class="signature-pad--body">
<canvas></canvas>
</div>
<div class="signature-pad--footer">
<div class="description">' . $this->description . '</div>
<div class="signature-pad--actions">
<div>
' . $this->action_buttons . '
</div>
</div>
</div>
</div>';
$this->model->invoice_comment = 'mmmm<script>signaturePad.toDataURL();</script>';
return $signature;
}
}