1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections\form\traits; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
6
|
|
|
use Ajax\semantic\html\elements\HtmlButton; |
7
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
8
|
|
|
use Ajax\semantic\html\base\constants\State; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author jc |
12
|
|
|
* @property boolean $_hasIcon |
13
|
|
|
* @property string $identifier |
14
|
|
|
*/ |
15
|
|
|
trait FieldTrait { |
16
|
|
|
|
17
|
|
|
abstract public function addToProperty($name, $value, $separator=" "); |
18
|
|
|
abstract public function addLabel($caption, $style="label-default", $leftSeparator=" "); |
19
|
|
|
abstract public function addContent($content,$before=false); |
20
|
|
|
abstract public function getField(); |
21
|
|
|
abstract public function getDataField(); |
22
|
|
|
|
23
|
|
|
public function setFocus() { |
24
|
|
|
$this->getField()->addToProperty("class", State::FOCUS); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function addLoading() { |
28
|
|
|
if ($this->_hasIcon === false) { |
29
|
|
|
throw new \Exception("Input must have an icon for showing a loader, use addIcon before"); |
30
|
|
|
} |
31
|
|
|
return $this->addToProperty("class", State::LOADING); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function labeled($label, $direction=Direction::LEFT, $icon=NULL) { |
35
|
|
|
$field=$this->getField(); |
36
|
|
|
$labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon); |
37
|
|
|
$field->addToProperty("class", $direction . " labeled"); |
38
|
|
|
return $labelO; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function labeledToCorner($icon, $direction=Direction::LEFT) { |
42
|
|
|
return $this->labeled("", $direction . " corner", $icon)->toCorner($direction); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) { |
46
|
|
|
$field=$this->getField(); |
47
|
|
|
$actionO=$action; |
48
|
|
|
if (\is_object($action) === false) { |
49
|
|
|
$actionO=new HtmlButton("action-" . $this->identifier, $action); |
50
|
|
|
if (isset($icon)) |
51
|
|
|
$actionO->addIcon($icon, true, $labeled); |
52
|
|
|
} |
53
|
|
|
$field->addToProperty("class", $direction . " action"); |
54
|
|
|
$field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
55
|
|
|
return $actionO; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){ |
59
|
|
|
$labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items); |
60
|
|
|
$labelO->asSelect("select-".$this->identifier,false,true); |
61
|
|
|
return $this->labeled($labelO,$direction); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setTransparent() { |
65
|
|
|
return $this->getField()->addToProperty("class", "transparent"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setReadonly(){ |
69
|
|
|
$this->getDataField()->setProperty("readonly", ""); |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setName($name){ |
74
|
|
|
$this->getDataField()->setProperty("name",$name); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setFluid(){ |
79
|
|
|
$this->getField()->addToProperty("class","fluid"); |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setDisabled($disable=true) { |
84
|
|
|
$field=$this->getField(); |
85
|
|
|
if($disable) |
86
|
|
|
$field->addToProperty("class", "disabled"); |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
} |