Completed
Push — master ( 19ac8a...195df7 )
by Jean-Christophe
03:23
created

HtmlMessage::setAttached()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
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\Style;
10
use Ajax\common\html\HtmlDoubleElement;
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
	protected $icon;
19
	protected $close;
20
	public function __construct($identifier, $content="") {
21
		parent::__construct($identifier, "div");
22
		$this->_template="<%tagName% id='%identifier%' %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>";
23
		$this->setClass("ui message");
24
		$this->setContent($content);
25
	}
26
27
	public function addHeader($header){
28
		$headerO=$header;
29
		if(\is_string($header)){
30
			$headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div");
31
			$headerO->setClass("header");
32
			$headerO->setContent($header);
33
		}
34
		return $this->addContent($headerO,true);
35
	}
36
37
	public function addList($elements,$ordered=false){
38
		$list=new HtmlList("list-".$this->identifier,$elements);
39
		$list->setOrdered($ordered);
40
		$list->setClass("ui list");
41
		$this->addContent($list);
42
	}
43
44
	public function setIcon($icon){
45
		$this->addToProperty("class", "icon");
46
		$this->wrapContent("<div class='content'>","</div>");
47
		$this->icon=new HtmlIcon("icon-".$this->identifier, $icon);
48
		return $this;
49
	}
50
51
	public function addLoader($loaderIcon="notched circle"){
52
		$this->setIcon($loaderIcon);
53
		$this->icon->addToIcon("loading");
54
		return $this;
55
	}
56
57
	public function setDismissable($dismiss=true){
58
		if($dismiss===true)
59
			$this->close=new HtmlIcon("close-".$this->identifier, "close");
60
		else
61
			$this->close=NULL;
62
		return $this;
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
68
	 */
69
	public function run(JsUtils $js){
70
		parent::run($js);
71
		if(isset($this->close)){
72
			$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition('fade')");
73
		}
74
	}
75
76
	public function setState($visible=true){
77
		$visible=($visible===true)?"visible":"hidden";
78
		return $this->addToPropertyCtrl("class", $visible, array("visible","hidden"));
79
	}
80
81
	public function setVariation($value="floating"){
82
		return $this->addToPropertyCtrl("class", $value, array("floating","compact"));
83
	}
84
85
	public function setStyle($style){
86
		return $this->addToPropertyCtrl("class", $style, Style::getConstants());
87
	}
88
89
	public function setAttached(HtmlDoubleElement $toElement=NULL){
90
		if(isset($toElement)){
91
			$toElement->addToProperty("class", "attached");
92
		}
93
		return $this->addToProperty("class", "attached");
94
	}
95
}