... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
/** |
4 | 4 |
* Extension for Contao 4 |
5 | 5 |
* |
6 |
- * @copyright Softleister 2019 |
|
6 |
+ * @copyright Softleister 2019-2023 |
|
7 | 7 |
* @author Softleister <info@softleister.de> |
8 | 8 |
* @package contao-signature-formfield-bundle |
9 | 9 |
* based on jSignature (https://github.com/brinley/jSignature) |
... | ... |
@@ -12,6 +12,9 @@ |
12 | 12 |
|
13 | 13 |
namespace Softleister; |
14 | 14 |
|
15 |
+use Contao\Widget; |
|
16 |
+use Contao\StringUtil; |
|
17 |
+ |
|
15 | 18 |
/** |
16 | 19 |
* Class FormSignature |
17 | 20 |
* |
... | ... |
@@ -23,75 +26,67 @@ namespace Softleister; |
23 | 26 |
* @property integer $rows |
24 | 27 |
* @property integer $cols |
25 | 28 |
*/ |
26 |
-class FormSignature extends \Widget |
|
29 |
+class FormSignature extends Widget |
|
27 | 30 |
{ |
28 |
- protected $blnSubmitInput = true; // Submit user input @var boolean |
|
29 |
- protected $strTemplate = 'form_signature'; // Template @var string |
|
30 |
- protected $strPrefix = 'widget widget-signature'; // The CSS class prefix @var string |
|
31 |
- |
|
32 |
- /** |
|
33 |
- * Add specific attributes |
|
34 |
- * |
|
35 |
- * @param string $strKey The attribute name |
|
36 |
- * @param mixed $varValue The attribute value |
|
37 |
- */ |
|
38 |
- public function __set( $strKey, $varValue ) |
|
39 |
- { |
|
40 |
- switch( $strKey ) { |
|
41 |
- case 'sig_size': $arrSize = \StringUtil::deserialize($varValue); |
|
42 |
- $this->intWidth = is_numeric($arrSize[0]) ? $arrSize[0] : 500; |
|
43 |
- $this->intHeight = is_numeric($arrSize[1]) ? $arrSize[1] : 250; |
|
44 |
- break; |
|
45 |
- |
|
46 |
- case 'sig_bgcolor': $this->sig_bgcolor = empty($this->sig_bgcolor) ? 'transparent' : '#' . $this->sig_bgcolor; |
|
47 |
- break; |
|
48 |
- |
|
49 |
- case 'sig_width': $this->sig_width = is_numeric($this->sig_width) && ($this->sig_width > 0) ? $this->sig_width : 5; |
|
50 |
- break; |
|
51 |
- |
|
52 |
- case 'sig_color': $varValue = $varValue == '' ? '000' : $varValue; |
|
31 |
+ protected $blnSubmitInput = true; // Submit user input @var boolean |
|
32 |
+ protected $strTemplate = 'form_signature'; // Template @var string |
|
33 |
+ protected $strPrefix = 'widget widget-signature'; // The CSS class prefix @var string |
|
53 | 34 |
|
54 |
- default: parent::__set($strKey, $varValue); |
|
55 |
- } |
|
56 |
- } |
|
35 |
+ /** |
|
36 |
+ * Add specific attributes |
|
37 |
+ * |
|
38 |
+ * @param string $strKey The attribute name |
|
39 |
+ * @param mixed $varValue The attribute value |
|
40 |
+ */ |
|
41 |
+ public function __set( $strKey, $varValue ) |
|
42 |
+ { |
|
43 |
+ switch( $strKey ) { |
|
44 |
+ case 'sig_size': $arrSize = StringUtil::deserialize( $varValue ); |
|
45 |
+ $this->intWidth = is_numeric( $arrSize[0] ) ? $arrSize[0] : 500; |
|
46 |
+ $this->intHeight = is_numeric( $arrSize[1] ) ? $arrSize[1] : 250; |
|
47 |
+ break; |
|
57 | 48 |
|
58 |
- /** |
|
59 |
- * Return a parameter |
|
60 |
- * |
|
61 |
- * @param string $strKey The parameter key |
|
62 |
- * |
|
63 |
- * @return mixed The parameter value |
|
64 |
- */ |
|
65 |
- public function __get( $strKey ) |
|
66 |
- { |
|
67 |
- switch( $strKey ) { |
|
68 |
- case 'width': return $this->intWidth; |
|
69 |
- break; |
|
49 |
+ case 'sig_bgcolor': |
|
50 |
+ $this->sig_bgcolor = empty( $varValue ) ? 'transparent' : '#' . $varValue; |
|
51 |
+ break; |
|
70 | 52 |
|
71 |
- case 'height': return $this->intHeight; |
|
72 |
- break; |
|
53 |
+ case 'sig_width': |
|
54 |
+ $this->sig_width = is_numeric( $varValue ) && ($varValue > 0) ? $varValue : 5; |
|
55 |
+ break; |
|
73 | 56 |
|
74 |
- case 'pen': return $this->sig_width; |
|
75 |
- break; |
|
57 |
+ case 'sig_color': $varValue = $varValue == '' ? '#000' : '#' . $varValue; |
|
76 | 58 |
|
77 |
- case 'color': return $this->sig_color; |
|
78 |
- break; |
|
59 |
+ default: parent::__set( $strKey, $varValue ); |
|
60 |
+ } |
|
61 |
+ } |
|
79 | 62 |
|
80 |
- case 'bgcolor': return $this->sig_bgcolor; |
|
81 |
- break; |
|
63 |
+ /** |
|
64 |
+ * Return a parameter |
|
65 |
+ * |
|
66 |
+ * @param string $strKey The parameter key |
|
67 |
+ * |
|
68 |
+ * @return mixed The parameter value |
|
69 |
+ */ |
|
70 |
+ public function __get( $strKey ) |
|
71 |
+ { |
|
72 |
+ switch( $strKey ) { |
|
73 |
+ case 'width': return $this->intWidth; |
|
74 |
+ case 'height': return $this->intHeight; |
|
75 |
+ case 'pen': return $this->sig_width; |
|
76 |
+ case 'color': return $this->sig_color; |
|
77 |
+ case 'bgcolor': return $this->sig_bgcolor; |
|
82 | 78 |
|
83 |
- default: return parent::__get($strKey); |
|
84 |
- break; |
|
85 |
- } |
|
86 |
- } |
|
79 |
+ default: return parent::__get( $strKey ); |
|
80 |
+ } |
|
81 |
+ } |
|
87 | 82 |
|
88 |
- /** |
|
89 |
- * Generate the widget and return it as string |
|
90 |
- * |
|
91 |
- * @return string The widget markup |
|
92 |
- */ |
|
93 |
- public function generate( ) |
|
94 |
- { |
|
95 |
- return ''; |
|
96 |
- } |
|
83 |
+ /** |
|
84 |
+ * Generate the widget and return it as string |
|
85 |
+ * |
|
86 |
+ * @return string The widget markup |
|
87 |
+ */ |
|
88 |
+ public function generate( ) |
|
89 |
+ { |
|
90 |
+ return ''; |
|
91 |
+ } |
|
97 | 92 |
} |
... | ... |
@@ -31,11 +31,11 @@ |
31 | 31 |
$(function() { |
32 | 32 |
var $sigdiv = $("#signature_<?= $this->id ?>") |
33 | 33 |
$sigdiv.jSignature({ |
34 |
- 'color': "#<?= $this->color ?>", |
|
34 |
+ 'color': "<?= $this->color ?>", |
|
35 | 35 |
'lineWidth': <?= $this->pen ?>, |
36 | 36 |
'width': '<?= $this->width ?>', |
37 | 37 |
'height': '<?= $this->height ?>', |
38 |
- 'background-color': "transparent", |
|
38 |
+ 'background-color': '<?= $this->bgcolor ?>', |
|
39 | 39 |
'UndoButton': true |
40 | 40 |
}) |
41 | 41 |
$sigdiv.bind('change', function(e) { |