Completed
Push — master ( ec2f1c...349ff5 )
by Jean-Christophe
04:00
created

HtmlMessage::setVariation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\common\html\html5\HtmlList;
7
use Ajax\semantic\html\elements\HtmlIcon;
8
use Ajax\JsUtils;
9
use Ajax\semantic\html\base\constants\Style;
10
use Ajax\semantic\html\base\traits\AttachedTrait;
11
/**
12
 * Semantic Message component
13
 * @see http://semantic-ui.com/collections/message.html
14
 * @author jc
15
 * @version 1.001
16
 */
17
class HtmlMessage extends HtmlSemDoubleElement {
18
	use AttachedTrait;
19
	protected $icon;
20
	protected $close;
21
	public function __construct($identifier, $content="") {
22
		parent::__construct($identifier, "div");
23
		$this->_template="<%tagName% id='%identifier%' %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>";
24
		$this->setClass("ui message");
25
		$this->setContent($content);
26
	}
27
28
	/**
29
	 * Adds an header to the message
30
	 * @param string|HtmlSemDoubleElement $header
31
	 * @return \Ajax\semantic\html\collections\HtmlMessage
32
	 */
33
	public function addHeader($header){
34
		$headerO=$header;
35
		if(\is_string($header)){
36
			$headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div");
37
			$headerO->setClass("header");
38
			$headerO->setContent($header);
39
		}
40
		return $this->addContent($headerO,true);
41
	}
42
43
	public function addList($elements,$ordered=false){
44
		$list=new HtmlList("list-".$this->identifier,$elements);
45
		$list->setOrdered($ordered);
46
		$list->setClass("ui list");
47
		$this->addContent($list);
48
	}
49
50
	public function setIcon($icon){
51
		$this->addToProperty("class", "icon");
52
		$this->wrapContent("<div class='content'>","</div>");
53
		$this->icon=new HtmlIcon("icon-".$this->identifier, $icon);
54
		return $this;
55
	}
56
57
	public function addLoader($loaderIcon="notched circle"){
58
		$this->setIcon($loaderIcon);
59
		$this->icon->addToIcon("loading");
60
		return $this;
61
	}
62
63
	public function setDismissable($dismiss=true){
64
		if($dismiss===true)
65
			$this->close=new HtmlIcon("close-".$this->identifier, "close");
66
		else
67
			$this->close=NULL;
68
		return $this;
69
	}
70
71
	/**
72
	 * {@inheritDoc}
73
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
74
	 */
75
	public function run(JsUtils $js){
76
		parent::run($js);
77
		if(isset($this->close)){
78
			$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition('fade')");
79
		}
80
	}
81
82
	public function setState($visible=true){
83
		$visible=($visible===true)?"visible":"hidden";
84
		return $this->addToPropertyCtrl("class", $visible, array("visible","hidden"));
85
	}
86
87
	public function setVariation($value="floating"){
88
		return $this->addToPropertyCtrl("class", $value, array("floating","compact"));
89
	}
90
91
	public function setStyle($style){
92
		return $this->addToPropertyCtrl("class", $style, Style::getConstants());
93
	}
94
95
	public function setError(){
96
		return $this->setStyle("error");
97
	}
98
}