Completed
Push — master ( 138cdf...e53430 )
by Jean-Christophe
03:16
created

HtmlMessage::setWarning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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 setHeader($header){
44
		return $this->addHeader($header);
45
	}
46
47
	public function addList($elements,$ordered=false){
48
		$list=new HtmlList("list-".$this->identifier,$elements);
49
		$list->setOrdered($ordered);
50
		$list->setClass("ui list");
51
		$this->addContent($list);
52
	}
53
54
	public function setIcon($icon){
55
		$this->addToProperty("class", "icon");
56
		$this->wrapContent("<div class='content'>","</div>");
57
		$this->icon=new HtmlIcon("icon-".$this->identifier, $icon);
58
		return $this;
59
	}
60
61
	public function addLoader($loaderIcon="notched circle"){
62
		$this->setIcon($loaderIcon);
63
		$this->icon->addToIcon("loading");
64
		return $this;
65
	}
66
67
	public function setDismissable($dismiss=true){
68
		if($dismiss===true)
69
			$this->close=new HtmlIcon("close-".$this->identifier, "close");
70
		else
71
			$this->close=NULL;
72
		return $this;
73
	}
74
75
	/**
76
	 * {@inheritDoc}
77
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
78
	 */
79
	public function run(JsUtils $js){
80
		parent::run($js);
81
		if(isset($this->close)){
82
			$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition('fade')");
83
		}
84
	}
85
86
	public function setState($visible=true){
87
		$visible=($visible===true)?"visible":"hidden";
88
		return $this->addToPropertyCtrl("class", $visible, array("visible","hidden"));
89
	}
90
91
	public function setVariation($value="floating"){
92
		return $this->addToPropertyCtrl("class", $value, array("floating","compact"));
93
	}
94
95
	public function setStyle($style){
96
		return $this->addToPropertyCtrl("class", $style, Style::getConstants());
97
	}
98
99
	public function setError(){
100
		return $this->setStyle("error");
101
	}
102
103
	public function setWarning(){
104
		return $this->setStyle("warning");
105
	}
106
107
	public function setMessage($message){
108
		if(\is_array($this->content)){
109
			$this->content[\sizeof($this->content)-1]=$message;
110
		}else
111
			$this->setContent($message);
112
	}
113
}