Completed
Push — master ( 017cb5...80e027 )
by Jean-Christophe
03:31
created

HtmlMessage::setCloseTransition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
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
	protected $_timeout;
22
	protected $_closeTransition="{animation : 'scale',duration : '2s'}";
23
24
	public function __construct($identifier, $content="") {
25
		parent::__construct($identifier, "div");
26
		$this->_template="<%tagName% id='%identifier%' %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>";
27
		$this->setClass("ui message");
28
		$this->setContent($content);
29
	}
30
31
	/**
32
	 * Adds an header to the message
33
	 * @param string|HtmlSemDoubleElement $header
34
	 * @return \Ajax\semantic\html\collections\HtmlMessage
35
	 */
36
	public function addHeader($header){
37
		$headerO=$header;
38
		if(\is_string($header)){
39
			$headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div");
40
			$headerO->setClass("header");
41
			$headerO->setContent($header);
42
		}
43
		return $this->addContent($headerO,true);
44
	}
45
46
	public function setHeader($header){
47
		return $this->addHeader($header);
48
	}
49
50
	public function addList($elements,$ordered=false){
51
		$list=new HtmlList("list-".$this->identifier,$elements);
52
		$list->setOrdered($ordered);
53
		$list->setClass("ui list");
54
		$this->addContent($list);
55
	}
56
57
	public function setIcon($icon){
58
		$this->addToProperty("class", "icon");
59
		$this->wrapContent("<div class='content'>","</div>");
60
		$this->icon=new HtmlIcon("icon-".$this->identifier, $icon);
61
		return $this;
62
	}
63
64
	public function addLoader($loaderIcon="notched circle"){
65
		$this->setIcon($loaderIcon);
66
		$this->icon->addToIcon("loading");
67
		return $this;
68
	}
69
70
	public function setDismissable($dismiss=true){
71
		if($dismiss===true)
72
			$this->close=new HtmlIcon("close-".$this->identifier, "close");
73
		else
74
			$this->close=NULL;
75
		return $this;
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
81
	 */
82
	public function run(JsUtils $js){
83
		parent::run($js);
84
		if(isset($this->close)){
85
			$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition({$this->_closeTransition})");
86
		}
87
		if(isset($this->_timeout)){
88
			$js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});",true);
89
		}
90
	}
91
92
	public function setState($visible=true){
93
		$visible=($visible===true)?"visible":"hidden";
94
		return $this->addToPropertyCtrl("class", $visible, array("visible","hidden"));
95
	}
96
97
	public function setVariation($value="floating"){
98
		return $this->addToPropertyCtrl("class", $value, array("floating","compact"));
99
	}
100
101
	public function setStyle($style){
102
		return $this->addToPropertyCtrl("class", $style, Style::getConstants());
103
	}
104
105
	public function setError(){
106
		return $this->setStyle("error");
107
	}
108
109
	public function setWarning(){
110
		return $this->setStyle("warning");
111
	}
112
113
	public function setMessage($message){
114
		if(\is_array($this->content)){
115
			$this->content[\sizeof($this->content)-1]=$message;
116
		}else
117
			$this->setContent($message);
118
	}
119
120
	public function setTimeout($_timeout) {
121
		$this->_timeout=$_timeout;
122
		return $this;
123
	}
124
125
	public function setCloseTransition($_closeTransition) {
126
		$this->_closeTransition=$_closeTransition;
127
		return $this;
128
	}
129
130
}