Skip to content

Commit 0da08b7

Browse files
committed
Add Message->getOnClose method
1 parent 18a30ff commit 0da08b7

File tree

1 file changed

+68
-41
lines changed

1 file changed

+68
-41
lines changed
Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Ajax\semantic\html\collections;
43

54
use Ajax\semantic\html\base\HtmlSemDoubleElement;
@@ -8,111 +7,139 @@
87
use Ajax\semantic\html\base\constants\Style;
98
use Ajax\semantic\html\base\traits\AttachedTrait;
109
use Ajax\semantic\html\base\traits\HasTimeoutTrait;
10+
1111
/**
1212
* Semantic Message component
13+
*
1314
* @see http://semantic-ui.com/collections/message.html
1415
* @author jc
1516
* @version 1.001
1617
*/
1718
class HtmlMessage extends HtmlSemDoubleElement {
1819
use AttachedTrait,HasTimeoutTrait;
20+
1921
protected $icon;
20-
protected $close;
2122

23+
protected $close;
2224

23-
public function __construct($identifier, $content="") {
25+
public function __construct($identifier, $content = "") {
2426
parent::__construct($identifier, "div");
25-
$this->_template='<%tagName% id="%identifier%" %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>';
27+
$this->_template = '<%tagName% id="%identifier%" %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>';
2628
$this->setClass("ui message");
2729
$this->setContent($content);
2830
}
2931

3032
/**
3133
* Adds an header to the message
34+
*
3235
* @param string|HtmlSemDoubleElement $header
3336
* @return \Ajax\semantic\html\collections\HtmlMessage
3437
*/
35-
public function addHeader($header){
36-
$headerO=$header;
37-
if(\is_string($header)){
38-
$headerO=new HtmlSemDoubleElement("header-".$this->identifier,"div");
38+
public function addHeader($header) {
39+
$headerO = $header;
40+
if (\is_string($header)) {
41+
$headerO = new HtmlSemDoubleElement("header-" . $this->identifier, "div");
3942
$headerO->setClass("header");
4043
$headerO->setContent($header);
4144
}
42-
return $this->addContent($headerO,true);
45+
return $this->addContent($headerO, true);
4346
}
4447

45-
public function setHeader($header){
48+
public function setHeader($header) {
4649
return $this->addHeader($header);
4750
}
4851

49-
public function setIcon($icon){
52+
public function setIcon($icon) {
5053
$this->addToProperty("class", "icon");
51-
$this->wrapContent("<div class='content'>","</div>");
52-
if(\is_string($icon)){
53-
$this->icon=new HtmlIcon("icon-".$this->identifier, $icon);
54-
}else{
55-
$this->icon=$icon;
54+
$this->wrapContent("<div class='content'>", "</div>");
55+
if (\is_string($icon)) {
56+
$this->icon = new HtmlIcon("icon-" . $this->identifier, $icon);
57+
} else {
58+
$this->icon = $icon;
5659
}
5760
return $this;
5861
}
5962

60-
public function addLoader($loaderIcon="notched circle"){
63+
/**
64+
* Performs a get to $url on the click event on close button
65+
* and display it in $responseElement
66+
*
67+
* @param string $url
68+
* The url of the request
69+
* @param string $responseElement
70+
* The selector of the HTML element displaying the answer
71+
* @param array $parameters
72+
* default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false)
73+
* @return $this
74+
*/
75+
public function getOnClose($url, $responseElement = "", $parameters = array()) {
76+
if (isset($this->close)) {
77+
$this->close->getOnClick($url, $responseElement, $parameters);
78+
}
79+
}
80+
81+
public function addLoader($loaderIcon = "notched circle") {
6182
$this->setIcon($loaderIcon);
6283
$this->icon->addToIcon("loading");
6384
return $this;
6485
}
6586

66-
public function setDismissable($dismiss=true){
67-
if($dismiss===true)
68-
$this->close=new HtmlIcon("close-".$this->identifier, "close");
87+
public function setDismissable($dismiss = true) {
88+
if ($dismiss === true)
89+
$this->close = new HtmlIcon("close-" . $this->identifier, "close");
6990
else
70-
$this->close=NULL;
91+
$this->close = NULL;
7192
return $this;
7293
}
7394

7495
/**
75-
* {@inheritDoc}
96+
*
97+
* {@inheritdoc}
7698
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
7799
*/
78-
public function run(JsUtils $js){
79-
if(!isset($this->_bsComponent)){
80-
if(isset($this->close)){
81-
$js->execOn("click", "#".$this->identifier." .close", "$(this).closest('.message').transition({$this->_closeTransition})");
100+
public function run(JsUtils $js) {
101+
if (! isset($this->_bsComponent)) {
102+
if (isset($this->close)) {
103+
$js->execOn("click", "#" . $this->identifier . " .close", "$(this).closest('.message').transition({$this->_closeTransition})");
82104
}
83-
if(isset($this->_timeout)){
84-
$js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});",true);
105+
if (isset($this->_timeout)) {
106+
$js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}); }, {$this->_timeout});", true);
85107
}
86108
}
87109
return parent::run($js);
88110
}
89111

90-
public function setState($visible=true){
91-
$visible=($visible===true)?"visible":"hidden";
92-
return $this->addToPropertyCtrl("class", $visible, array("visible","hidden"));
112+
public function setState($visible = true) {
113+
$visible = ($visible === true) ? "visible" : "hidden";
114+
return $this->addToPropertyCtrl("class", $visible, array(
115+
"visible",
116+
"hidden"
117+
));
93118
}
94119

95-
public function setVariation($value="floating"){
96-
return $this->addToPropertyCtrl("class", $value, array("floating","compact"));
120+
public function setVariation($value = "floating") {
121+
return $this->addToPropertyCtrl("class", $value, array(
122+
"floating",
123+
"compact"
124+
));
97125
}
98126

99-
public function setStyle($style){
127+
public function setStyle($style) {
100128
return $this->addToPropertyCtrl("class", $style, Style::getConstants());
101129
}
102130

103-
public function setError(){
131+
public function setError() {
104132
return $this->setStyle("error");
105133
}
106134

107-
public function setWarning(){
135+
public function setWarning() {
108136
return $this->setStyle("warning");
109137
}
110138

111-
public function setMessage($message){
112-
if(\is_array($this->content)){
113-
$this->content[\sizeof($this->content)-1]=$message;
114-
}else
139+
public function setMessage($message) {
140+
if (\is_array($this->content)) {
141+
$this->content[\sizeof($this->content) - 1] = $message;
142+
} else
115143
$this->setContent($message);
116144
}
117-
118145
}

0 commit comments

Comments
 (0)