phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlMessage.php
Go to the documentation of this file.
1 <?php
3 
6 use Ajax\JsUtils;
10 
20 
21  protected $icon;
22 
23  protected $close;
24 
25  public function __construct($identifier, $content = "") {
26  parent::__construct($identifier, "div");
27  $this->_template = '<%tagName% id="%identifier%" %properties%>%close%%icon%%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>';
28  $this->setClass("ui message");
29  $this->setContent($content);
30  }
31 
38  public function addHeader($header) {
39  $headerO = $header;
40  if (\is_string($header)) {
41  $headerO = new HtmlSemDoubleElement("header-" . $this->identifier, "div");
42  $headerO->setClass("header");
43  $headerO->setContent($header);
44  }
45  return $this->addContent($headerO, true);
46  }
47 
48  public function setHeader($header) {
49  return $this->addHeader($header);
50  }
51 
52  public function setIcon($icon) {
53  $this->addToProperty("class", "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;
59  }
60  return $this;
61  }
62 
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") {
82  $this->setIcon($loaderIcon);
83  $this->icon->addToIcon("loading");
84  return $this;
85  }
86 
87  public function setDismissable($dismiss = true) {
88  if ($dismiss === true)
89  $this->close = new HtmlIcon("close-" . $this->identifier, "close");
90  else
91  $this->close = NULL;
92  return $this;
93  }
94 
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}).trigger('close-message');");
104  }
105  if (isset($this->_timeout)) {
106  $js->exec("setTimeout(function() { $('#{$this->identifier}').transition({$this->_closeTransition}).trigger('close-message'); }, {$this->_timeout});", true);
107  }
108  }
109  return parent::run($js);
110  }
111 
112  public function setState($visible = true) {
113  $visible = ($visible === true) ? "visible" : "hidden";
114  return $this->addToPropertyCtrl("class", $visible, array(
115  "visible",
116  "hidden"
117  ));
118  }
119 
120  public function setVariation($value = "floating") {
121  return $this->addToPropertyCtrl("class", $value, array(
122  "floating",
123  "compact"
124  ));
125  }
126 
127  public function setStyle($style) {
128  return $this->addToPropertyCtrl("class", $style, Style::getConstants());
129  }
130 
131  public function setError() {
132  return $this->setStyle("error");
133  }
134 
135  public function setWarning() {
136  return $this->setStyle("warning");
137  }
138 
139  public function setMessage($message) {
140  if (\is_array($this->content)) {
141  $this->content[\sizeof($this->content) - 1] = $message;
142  } else
143  $this->setContent($message);
144  }
145 }
Semantic Message component.
Definition: HtmlMessage.php:18
addToProperty($name, $value, $separator=" ")
static getConstants()
Definition: BaseEnum.php:17
addContent($content, $before=false)
Semantic Icon component.
Definition: HtmlIcon.php:14
addHeader($header)
Adds an header to the message.
Definition: HtmlMessage.php:38
Base class for Semantic double elements.
getOnClose($url, $responseElement="", $parameters=array())
Performs a get to $url on the click event on close button and display it in $responseElement.
Definition: HtmlMessage.php:75
JQuery PHP library.
Definition: JsUtils.php:23
addLoader($loaderIcon="notched circle")
Definition: HtmlMessage.php:81
addToPropertyCtrl($name, $value, $typeCtrl)
__construct($identifier, $content="")
Definition: HtmlMessage.php:25