| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 |
|
| 5 |
use BitCode\BitForm\Core\Util\FrontendHelpers; |
| 6 |
|
| 7 |
class SignatureField |
| 8 |
{ |
| 9 |
public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) |
| 10 |
{ |
| 11 |
$inputWrapper = new InputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 12 |
$input = self::field($field, $rowID, $form_atomic_Cls_map, $value); |
| 13 |
return $inputWrapper->wrapper($input); |
| 14 |
} |
| 15 |
|
| 16 |
private static function field($field, $rowID, $form_atomic_Cls_map, $value) |
| 17 |
{ |
| 18 |
$fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); |
| 19 |
|
| 20 |
$name = $fieldHelpers->name(); |
| 21 |
$req = $fieldHelpers->required(); |
| 22 |
|
| 23 |
$clrBtnContent = ''; |
| 24 |
$undoBtnContent = ''; |
| 25 |
$redoBtnContent = ''; |
| 26 |
|
| 27 |
$bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 28 |
$contentCount = count($bfFrontendFormIds); |
| 29 |
|
| 30 |
$clrBtnPreIcn = $fieldHelpers->icon('clrPreIcn', 'clr-btn-pre-i'); |
| 31 |
$clrBtnSufIcn = $fieldHelpers->icon('clrSufIcn', 'clr-btn-suf-i'); |
| 32 |
$undoBtnPreIcn = $fieldHelpers->icon('undoPreIcn', 'undo-btn-pre-i'); |
| 33 |
$undoBtnSufIcn = $fieldHelpers->icon('undoSufIcn', 'undo-btn-suf-i'); |
| 34 |
$redoBtnPreIcn = $fieldHelpers->icon('redoPreIcn', 'redo-btn-pre-i'); |
| 35 |
$redoBtnSufIcn = $fieldHelpers->icon('redoSufIcn', 'redo-btn-suf-i'); |
| 36 |
|
| 37 |
if (property_exists($field, 'clrBtnHide') && !$field->clrBtnHide) { |
| 38 |
$clrBtnContent = <<<CLRBTN |
| 39 |
<button |
| 40 |
aria-label="Signature pad clear button" |
| 41 |
class="{$fieldHelpers->getAtomicCls('clr-btn')} {$fieldHelpers->getCustomClasses('clr-btn')}" |
| 42 |
type="button" |
| 43 |
{$fieldHelpers->getCustomAttributes('clr-btn')} |
| 44 |
> |
| 45 |
{$clrBtnPreIcn} |
| 46 |
{$field->clrBtn} |
| 47 |
{$clrBtnSufIcn} |
| 48 |
</button> |
| 49 |
|
| 50 |
CLRBTN; |
| 51 |
} |
| 52 |
|
| 53 |
if (property_exists($field, 'undoBtnHide') && !$field->undoBtnHide) { |
| 54 |
$undoBtnContent = <<<UNDOBTN |
| 55 |
<button |
| 56 |
aria-label="Signature pad undo button" |
| 57 |
class="{$fieldHelpers->getAtomicCls('undo-btn')} {$fieldHelpers->getCustomClasses('undo-btn')}" |
| 58 |
type="button" |
| 59 |
{$fieldHelpers->getCustomAttributes('undo-btn')} |
| 60 |
> |
| 61 |
{$undoBtnPreIcn} |
| 62 |
{$field->undoBtn} |
| 63 |
{$undoBtnSufIcn} |
| 64 |
</button> |
| 65 |
UNDOBTN; |
| 66 |
} |
| 67 |
|
| 68 |
if (property_exists($field, 'redoBtnHide') && !$field->redoBtnHide) { |
| 69 |
$redoBtnContent = <<<REDOBTN |
| 70 |
<button |
| 71 |
aria-label="Signature pad redo button" |
| 72 |
class="{$fieldHelpers->getAtomicCls('redo-btn')} {$fieldHelpers->getCustomClasses('redo-btn')}" |
| 73 |
type="button" |
| 74 |
{$fieldHelpers->getCustomAttributes('redo-btn')} |
| 75 |
> |
| 76 |
{$redoBtnPreIcn} |
| 77 |
{$field->redoBtn} |
| 78 |
{$redoBtnSufIcn} |
| 79 |
</button> |
| 80 |
REDOBTN; |
| 81 |
} |
| 82 |
|
| 83 |
return <<<SIGNATUREFIELD |
| 84 |
<div |
| 85 |
{$fieldHelpers->getCustomAttributes('inp-fld-wrp')} |
| 86 |
class="{$fieldHelpers->getAtomicCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}" |
| 87 |
> |
| 88 |
<input |
| 89 |
type="text" |
| 90 |
{$name} |
| 91 |
class="d-none {$rowID}-signature-fld" |
| 92 |
{$req} |
| 93 |
value="" |
| 94 |
/> |
| 95 |
<canvas |
| 96 |
tabindex="0" |
| 97 |
aria-label="Signature pad" |
| 98 |
id="{$rowID}-{$contentCount}" |
| 99 |
class="{$fieldHelpers->getAtomicCls('signature-pad')} {$fieldHelpers->getCustomClasses('signature-pad')}" |
| 100 |
{$fieldHelpers->getCustomAttributes('signature-pad')} |
| 101 |
> |
| 102 |
</canvas> |
| 103 |
|
| 104 |
<div aria-label="Signature pad control buttons" class="{$fieldHelpers->getAtomicCls('ctrl')} {$fieldHelpers->getCustomClasses('ctrl')}"> |
| 105 |
{$clrBtnContent} |
| 106 |
{$undoBtnContent} |
| 107 |
{$redoBtnContent} |
| 108 |
</div> |
| 109 |
|
| 110 |
<iframe class="{$fieldHelpers->getAtomicCls('signature-iframe')}"></iframe> |
| 111 |
</div> |
| 112 |
SIGNATUREFIELD; |
| 113 |
} |
| 114 |
} |
| 115 |
|