|
1 | 1 | <?php
|
2 |
| - |
3 | 2 | namespace Ajax\semantic\html\collections;
|
4 | 3 |
|
5 | 4 | use Ajax\semantic\html\base\HtmlSemDoubleElement;
|
|
8 | 7 | use Ajax\semantic\html\base\constants\Style;
|
9 | 8 | use Ajax\semantic\html\base\traits\AttachedTrait;
|
10 | 9 | use Ajax\semantic\html\base\traits\HasTimeoutTrait;
|
| 10 | + |
11 | 11 | /**
|
12 | 12 | * Semantic Message component
|
| 13 | + * |
13 | 14 | * @see http://semantic-ui.com/collections/message.html
|
14 | 15 | * @author jc
|
15 | 16 | * @version 1.001
|
16 | 17 | */
|
17 | 18 | class HtmlMessage extends HtmlSemDoubleElement {
|
18 | 19 | use AttachedTrait,HasTimeoutTrait;
|
| 20 | + |
19 | 21 | protected $icon;
|
20 |
| - protected $close; |
21 | 22 |
|
| 23 | + protected $close; |
22 | 24 |
|
23 |
| - public function __construct($identifier, $content="") { |
| 25 | + public function __construct($identifier, $content = "") { |
24 | 26 | 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%>'; |
26 | 28 | $this->setClass("ui message");
|
27 | 29 | $this->setContent($content);
|
28 | 30 | }
|
29 | 31 |
|
30 | 32 | /**
|
31 | 33 | * Adds an header to the message
|
| 34 | + * |
32 | 35 | * @param string|HtmlSemDoubleElement $header
|
33 | 36 | * @return \Ajax\semantic\html\collections\HtmlMessage
|
34 | 37 | */
|
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"); |
39 | 42 | $headerO->setClass("header");
|
40 | 43 | $headerO->setContent($header);
|
41 | 44 | }
|
42 |
| - return $this->addContent($headerO,true); |
| 45 | + return $this->addContent($headerO, true); |
43 | 46 | }
|
44 | 47 |
|
45 |
| - public function setHeader($header){ |
| 48 | + public function setHeader($header) { |
46 | 49 | return $this->addHeader($header);
|
47 | 50 | }
|
48 | 51 |
|
49 |
| - public function setIcon($icon){ |
| 52 | + public function setIcon($icon) { |
50 | 53 | $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; |
56 | 59 | }
|
57 | 60 | return $this;
|
58 | 61 | }
|
59 | 62 |
|
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") { |
61 | 82 | $this->setIcon($loaderIcon);
|
62 | 83 | $this->icon->addToIcon("loading");
|
63 | 84 | return $this;
|
64 | 85 | }
|
65 | 86 |
|
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"); |
69 | 90 | else
|
70 |
| - $this->close=NULL; |
| 91 | + $this->close = NULL; |
71 | 92 | return $this;
|
72 | 93 | }
|
73 | 94 |
|
74 | 95 | /**
|
75 |
| - * {@inheritDoc} |
| 96 | + * |
| 97 | + * {@inheritdoc} |
76 | 98 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
|
77 | 99 | */
|
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})"); |
82 | 104 | }
|
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); |
85 | 107 | }
|
86 | 108 | }
|
87 | 109 | return parent::run($js);
|
88 | 110 | }
|
89 | 111 |
|
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 | + )); |
93 | 118 | }
|
94 | 119 |
|
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 | + )); |
97 | 125 | }
|
98 | 126 |
|
99 |
| - public function setStyle($style){ |
| 127 | + public function setStyle($style) { |
100 | 128 | return $this->addToPropertyCtrl("class", $style, Style::getConstants());
|
101 | 129 | }
|
102 | 130 |
|
103 |
| - public function setError(){ |
| 131 | + public function setError() { |
104 | 132 | return $this->setStyle("error");
|
105 | 133 | }
|
106 | 134 |
|
107 |
| - public function setWarning(){ |
| 135 | + public function setWarning() { |
108 | 136 | return $this->setStyle("warning");
|
109 | 137 | }
|
110 | 138 |
|
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 |
115 | 143 | $this->setContent($message);
|
116 | 144 | }
|
117 |
| - |
118 | 145 | }
|
0 commit comments