phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlAlert.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ajax\bootstrap\html;
4 
6 use Ajax\JsUtils;
8 
9 
21  protected $button="";
22  protected $closeable;
23 
24  public function __construct($identifier, $message=NULL, $cssStyle="alert-warning") {
25  parent::__construct($identifier, "div");
26  $this->_template='<div id="%identifier%" %properties%>%button%%content%</div>';
27  $this->setClass("alert");
28  $this->setRole("alert");
29  $this->setStyle($cssStyle);
30  if ($message!=NULL) {
31  $this->content=$message;
32  }
33  }
34 
41  public function setStyle($cssStyle) {
42  return $this->addToPropertyCtrl("class", CssRef::getStyle($cssStyle, "alert"), CssRef::Styles("alert"));
43  }
44 
45  public function addCloseButton() {
46  $button=new HtmlButton("close-".$this->identifier);
47  $button->setProperties(array (
48  "class" => "close",
49  "data-dismiss" => "alert",
50  "aria-label" => "close"
51  ));
52  $button->setValue('<span aria-hidden="true">&times;</span>');
53  $this->addToPropertyCtrl("class", "alert-dismissible", array (
54  "alert-dismissible"
55  ));
56  $this->button=$button;
57  }
58 
59  public function onClose($jsCode) {
60  return $this->addEvent("close.bs.alert", $jsCode);
61  }
62 
63  /*
64  * (non-PHPdoc)
65  * @see \Ajax\bootstrap\html\base\HtmlDoubleElement::run()
66  */
67  public function run(JsUtils $js) {
68  $this->_bsComponent=$js->bootstrap()->generic("#".$this->identifier);
69  $this->addEventsOnRun($js);
70  return $this->_bsComponent;
71  }
72 
73  public function close() {
74  return "$('#".$this->identifier."').alert('close');";
75  }
76 
77  /*
78  * (non-PHPdoc)
79  * @see \Ajax\bootstrap\html\base\BaseHtml::compile()
80  */
81  public function compile(JsUtils $js=NULL, &$view=NULL) {
82  if ($this->closeable&&$this->button==="") {
83  $this->addCloseButton();
84  }
85  return parent::compile($js, $view);
86  }
87 
88  public function setCloseable($closeable) {
89  $this->closeable=$closeable;
90  return $this;
91  }
92 
93  public function setMessage($message) {
94  $this->content=$message;
95  }
96 }
Twitter Bootstrap Alert component.
Definition: HtmlAlert.php:16
addEventsOnRun(JsUtils $js=NULL)
__construct($identifier, $message=NULL, $cssStyle="alert-warning")
Definition: HtmlAlert.php:24
setStyle($cssStyle)
define the alert style avaible values : "alert-success","alert-info","alert-warning","alert-danger"
Definition: HtmlAlert.php:41
Twitter Bootstrap Button component.
Definition: HtmlButton.php:15
bootstrap(Bootstrap $bootstrap=NULL)
getter or setter of the Twitter Bootstrap variable
Definition: JsUtils.php:141
static Styles($prefix="btn")
Definition: CssRef.php:27
JQuery PHP library.
Definition: JsUtils.php:23
addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false)
static getStyle($cssStyle, $prefix)
return a valid style avaible values : "default","primary","success","info","warning","danger"
Definition: CssRef.php:346
compile(JsUtils $js=NULL, &$view=NULL)
Definition: HtmlAlert.php:81
addToPropertyCtrl($name, $value, $typeCtrl)