1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace fieldwork\components; |
4
|
|
|
|
5
|
|
|
use fieldwork\methods\Method; |
6
|
|
|
|
7
|
|
|
class Button extends Field |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
const TYPE_SUBMIT = "submit"; |
11
|
|
|
const TYPE_BUTTON = "button"; |
12
|
|
|
|
13
|
|
|
private $type, $icon, $glyphIcon, $isClicked = false; |
14
|
|
|
|
15
|
|
|
public function __construct ($name, $label, $value = "", $type = Button::TYPE_BUTTON) |
16
|
|
|
{ |
17
|
|
|
parent::__construct($name, $label, $value); |
18
|
|
|
$this->type = $type; |
19
|
|
|
$this->collectData = false; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function isClicked () |
23
|
|
|
{ |
24
|
|
|
return $this->isClicked; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function setIcon ($file) |
28
|
|
|
{ |
29
|
|
|
$this->icon = $file; |
30
|
|
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function setGlyphIcon ($code) |
34
|
|
|
{ |
35
|
|
|
$this->glyphIcon = $code; |
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function restoreValue (Method $method, $sanitize = true) |
40
|
|
|
{ |
41
|
|
|
$this->isClicked = $method->hasValue($this->getName()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getAttributes () |
45
|
|
|
{ |
46
|
|
|
return array_merge(parent::getAttributes(), array( |
47
|
|
|
'type' => $this->type |
48
|
|
|
)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getClasses () |
52
|
|
|
{ |
53
|
|
|
return array_merge( |
54
|
|
|
parent::getClasses(), array( |
55
|
|
|
'button', |
56
|
|
|
$this->type === self::TYPE_SUBMIT ? 'btn btn-primary' : 'btn-default' |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getHTML ($showLabel = true) |
62
|
|
|
{ |
63
|
|
|
$icon = ($this->icon == '' ? '' : '<img class="button-icon" src="' . $this->icon . '"> '); |
64
|
|
|
$glyphIcon = !empty($this->glyphIcon) ? '<i class="button-icon icon-' . $this->glyphIcon . '"></i> ' : ''; |
65
|
|
|
return |
66
|
|
|
"<button " . $this->getAttributesString() . ">" . $icon . $glyphIcon . $this->label . "</button>"; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getJsonData () |
70
|
|
|
{ |
71
|
|
|
return array_merge(parent::getJsonData(), array( |
72
|
|
|
'isButton' => true |
73
|
|
|
)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |