Completed
Push — master ( 2ffc14...238349 )
by Jean-Christophe
02:59
created

FieldTrait::setFluid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox;
10
use Ajax\common\html\BaseHtml;
11
use Ajax\semantic\html\elements\HtmlLabel;
12
13
/**
14
 * @author jc
15
 * @property boolean $_hasIcon
16
 * @property string $identifier
17
 */
18
trait FieldTrait {
19
20
	abstract public function addToProperty($name, $value, $separator=" ");
21
	abstract public function addLabel($caption, $style="label-default", $leftSeparator="&nbsp;");
22
	abstract public function addContent($content,$before=false);
23
	abstract public function getField();
24
	abstract public function getDataField();
25
26
	public function setFocus() {
27
		$this->getField()->addToProperty("class", State::FOCUS);
28
	}
29
30
	public function addLoading() {
31
		if ($this->_hasIcon === false) {
32
			throw new \Exception("Input must have an icon for showing a loader, use addIcon before");
33
		}
34
		return $this->addToProperty("class", State::LOADING);
35
	}
36
37
	/**
38
	 * @param string|BaseHtml $label
39
	 * @param string $direction
40
	 * @param string $icon
41
	 * @return HtmlLabel
42
	 */
43
	public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
44
		$field=$this->getField();
45
		$labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon);
46
		$field->addToProperty("class", $direction . " labeled");
47
		return $labelO;
48
	}
49
50
	/**
51
	 * @param string $direction
52
	 * @param string $caption
53
	 * @param string $value
54
	 * @param string $checkboxType
55
	 * @return HtmlLabel
56
	 */
57
	public function labeledCheckbox($direction=Direction::LEFT,$caption="",$value=NULL,$checkboxType=NULL){
58
		return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(),$caption,$value,$checkboxType),$direction);
59
	}
60
61
	/**
62
	 * @param string $icon
63
	 * @param string $direction
64
	 * @return HtmlLabel
65
	 */
66
	public function labeledToCorner($icon, $direction=Direction::LEFT) {
67
		return $this->labeled("", $direction . " corner", $icon)->toCorner($direction);
68
	}
69
70
	/**
71
	 * @param string $action
72
	 * @param string $direction
73
	 * @param string $icon
74
	 * @param string $labeled
75
	 * @return unknown|HtmlButton
76
	 */
77
	public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) {
78
		$field=$this->getField();
79
		$actionO=$action;
80
		if (\is_object($action) === false) {
81
			$actionO=new HtmlButton("action-" . $this->identifier, $action);
82
			if (isset($icon))
83
				$actionO->addIcon($icon, true, $labeled);
0 ignored issues
show
Bug introduced by
It seems like $labeled defined by parameter $labeled on line 77 can also be of type string; however, Ajax\semantic\html\base\...ledIconTrait::addIcon() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
84
		}
85
		$field->addToProperty("class", $direction . " action");
86
		$field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
87
		return $actionO;
88
	}
89
90
	/**
91
	 * @param string $label
92
	 * @param array $items
93
	 * @param string $direction
94
	 * @return HtmlLabel
95
	 */
96
	public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){
97
		$labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items);
98
		$labelO->asSelect("select-".$this->identifier,false,true);
99
		return $this->labeled($labelO,$direction);
100
	}
101
102
	public function setTransparent() {
103
		return $this->getField()->addToProperty("class", "transparent");
104
	}
105
106
	public function setReadonly(){
107
		$this->getDataField()->setProperty("readonly", "");
108
		return $this;
109
	}
110
111
	public function setName($name){
112
		$this->getDataField()->setProperty("name",$name);
113
		return $this;
114
	}
115
116
	public function setFluid(){
117
		$this->getField()->addToProperty("class","fluid");
118
		return $this;
119
	}
120
121
	public function setDisabled($disable=true) {
122
		$field=$this->getField();
123
		if($disable)
124
			$field->addToProperty("class", "disabled");
125
		return $this;
126
	}
127
}
128