|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
|
6
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
|
7
|
|
|
use Ajax\JsUtils; |
|
8
|
|
|
use Ajax\semantic\html\base\constants\Style; |
|
9
|
|
|
use Ajax\semantic\html\base\traits\AttachedTrait; |
|
10
|
|
|
use Ajax\semantic\html\base\traits\HasTimeoutTrait; |
|
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,HasTimeoutTrait; |
|
19
|
|
|
protected $icon; |
|
20
|
|
|
protected $close; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
public function __construct($identifier, $content="") { |
|
24
|
|
|
parent::__construct($identifier, "div"); |
|
25
|
|
|
$this->_template="<%tagName% id='%identifier%' %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>"; |
|
26
|
|
|
$this->setClass("ui message"); |
|
27
|
|
|
$this->setContent($content); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Adds an header to the message |
|
32
|
|
|
* @param string|HtmlSemDoubleElement $header |
|
33
|
|
|
* @return \Ajax\semantic\html\collections\HtmlMessage |
|
34
|
|
|
*/ |
|
35
|
|
|
public function addHeader($header){ |
|
36
|
|
|
$headerO=$header; |
|
37
|
|
|
if(\is_string($header)){ |
|
38
|
|
|
$headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div"); |
|
39
|
|
|
$headerO->setClass("header"); |
|
40
|
|
|
$headerO->setContent($header); |
|
41
|
|
|
} |
|
42
|
|
|
return $this->addContent($headerO,true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function setHeader($header){ |
|
46
|
|
|
return $this->addHeader($header); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setIcon($icon){ |
|
50
|
|
|
$this->addToProperty("class", "icon"); |
|
51
|
|
|
$this->wrapContent("<div class='content'>","</div>"); |
|
52
|
|
|
$this->icon=new HtmlIcon("icon-".$this->identifier, $icon); |
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function addLoader($loaderIcon="notched circle"){ |
|
57
|
|
|
$this->setIcon($loaderIcon); |
|
58
|
|
|
$this->icon->addToIcon("loading"); |
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setDismissable($dismiss=true){ |
|
63
|
|
|
if($dismiss===true) |
|
64
|
|
|
$this->close=new HtmlIcon("close-".$this->identifier, "close"); |
|
65
|
|
|
else |
|
66
|
|
|
$this->close=NULL; |
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritDoc} |
|
72
|
|
|
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run() |
|
73
|
|
|
*/ |
|
74
|
|
|
public function run(JsUtils $js){ |
|
75
|
|
|
if(!isset($this->_bsComponent)){ |
|
76
|
|
|
if(isset($this->close)){ |
|
77
|
|
|
$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition({$this->_closeTransition})"); |
|
78
|
|
|
} |
|
79
|
|
|
if(isset($this->_timeout)){ |
|
80
|
|
|
$js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});",true); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
return parent::run($js); |
|
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
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|