Passed
Push — master ( 2672cd...e7f8f8 )
by Jean-Christophe
03:27
created

HtmlInput   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 31
c 4
b 0
f 1
dl 0
loc 58
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A outline() 0 5 1
A addDataList() 0 5 1
A run() 0 5 1
A getField() 0 2 1
A compile_once() 0 4 2
A getDataField() 0 2 1
A setTransparent() 0 2 1
A __construct() 0 14 1
1
<?php
2
namespace Ajax\semantic\html\elements;
3
4
use Ajax\semantic\html\base\HtmlSemDoubleElement;
5
use Ajax\semantic\html\base\constants\State;
6
use Ajax\semantic\html\base\constants\Variation;
7
use Ajax\semantic\html\base\traits\IconTrait;
8
use Ajax\semantic\html\collections\form\traits\TextFieldsTrait;
9
use Ajax\semantic\html\collections\form\traits\FieldTrait;
10
use Ajax\JsUtils;
11
use Ajax\common\html\html5\HtmlInput as HtmlInput5;
12
use Ajax\service\Javascript;
13
use Ajax\semantic\html\elements\html5\HtmlDatalist;
14
15
class HtmlInput extends HtmlSemDoubleElement {
16
	use IconTrait,TextFieldsTrait,FieldTrait;
17
18
	public function __construct($identifier, $type = "text", $value = "", $placeholder = "") {
19
		parent::__construct("div-" . $identifier, "div", "ui input");
20
		$this->_identifier = $identifier;
21
		$this->_libraryId = $identifier;
22
		$this->content = [
23
			"field" => new HtmlInput5($identifier, $type, $value, $placeholder)
24
		];
25
		$this->_states = [
26
			State::DISABLED,
27
			State::FOCUS,
28
			State::ERROR
29
		];
30
		$this->_variations = [
31
			Variation::TRANSPARENT
32
		];
33
	}
34
35
	public function getField() {
36
		return $this;
37
	}
38
39
	public function getDataField() {
40
		return $this->content["field"];
41
	}
42
43
	public static function outline($identifier, $icon, $value = "", $placeholder = "") {
44
		$result = new HtmlInput($identifier, "text", $value, $placeholder);
45
		$result->addToProperty("class", "transparent");
46
		$result->addIcon($icon)->setOutline();
47
		return $result;
48
	}
49
50
	public function run(JsUtils $js) {
51
		$result = parent::run($js);
52
		$result->attach("#" . $this->getDataField()
53
			->getIdentifier());
54
		return $result;
55
	}
56
57
	public function setTransparent() {
58
		return $this->addToProperty("class", "transparent");
59
	}
60
61
	public function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL) {
62
		parent::compile_once($js, $view);
63
		if (isset($this->content['file'])) {
64
			$this->onCreate(Javascript::fileUploadBehavior($this->identifier));
65
		}
66
	}
67
68
	public function addDataList($items) {
69
		$dl = new HtmlDatalist('list-' . $this->identifier);
70
		$dl->addItems($items);
71
		$this->getDataField()->setProperty('list', $dl->getIdentifier());
72
		$this->getDataField()->wrap($dl);
73
	}
74
}
75