Passed
Push — master ( fa0f64...7ebbb8 )
by Jean-Christophe
01:58
created

HtmlInput   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 21
dl 0
loc 41
rs 10
c 3
b 0
f 1
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A outline() 0 5 1
A run() 0 4 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 7 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
14
class HtmlInput extends HtmlSemDoubleElement {
15
	use IconTrait,TextFieldsTrait,FieldTrait;
16
17
	public function __construct($identifier, $type="text", $value="", $placeholder="") {
18
		parent::__construct("div-" . $identifier, "div", "ui input");
19
		$this->_identifier=$identifier;
20
		$this->_libraryId=$identifier;
21
		$this->content=[ "field" => new HtmlInput5($identifier, $type, $value, $placeholder) ];
22
		$this->_states=[ State::DISABLED,State::FOCUS,State::ERROR ];
23
		$this->_variations=[ Variation::TRANSPARENT ];
24
	}
25
26
	public function getField() {
27
		return $this;
28
	}
29
30
	public function getDataField() {
31
		return $this->content["field"];
32
	}
33
34
	public static function outline($identifier, $icon, $value="", $placeholder="") {
35
		$result=new HtmlInput($identifier, "text", $value, $placeholder);
36
		$result->addToProperty("class", "transparent");
37
		$result->addIcon($icon)->setOutline();
38
		return $result;
39
	}
40
41
	public function run(JsUtils $js) {
42
		$result=parent::run($js);
43
		$result->attach("#" . $this->getDataField()->getIdentifier());
44
		return $result;
45
	}
46
47
	public function setTransparent(){
48
		return $this->addToProperty("class", "transparent");
49
	}
50
	
51
	public function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL){
52
		parent::compile_once($js,$view);
53
		if(isset($this->content['file'])){
54
			$this->onCreate(Javascript::fileUploadBehavior($this->identifier));
55
		}
56
	}
57
}
58