phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlModal.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\bootstrap\html;
4
5
8
14class HtmlModal extends BaseHtml {
15 protected $title="HtmlModal Title";
16 protected $content="";
17 protected $buttons=array ();
18 protected $showOnStartup=false;
19 protected $draggable=false;
20 protected $validCondition=NULL;
21 protected $backdrop=true;
22
27 public function __construct($identifier, $title="", $content="", $buttonCaptions=array()) {
28 parent::__construct($identifier);
29 $this->_template=include 'templates/tplModal.php';
30 $this->buttons=array ();
31 $this->title=$title;
32 $this->content=$content;
33 foreach ( $buttonCaptions as $button ) {
34 $this->addButton($button);
35 }
36 }
37
44 public function addButton($value="Okay", $style="btn-primary") {
45 $btn=new HtmlButton($this->identifier."-".$value);
46 $btn->setStyle($style);
47 $btn->setValue($value);
48 $this->buttons []=$btn;
49 return $btn;
50 }
51
57 public function addCancelButton($value="Annuler") {
58 $btn=$this->addButton($value, "btn-default");
59 $btn->setProperty("data-dismiss", "modal");
60 return $btn;
61 }
62
68 public function addOkayButton($value="Okay",$jsCode="") {
69 $btn=$this->addButton($value, "btn-primary");
70 $btn->onClick("if(".$this->getValidCondition()."){ ".$jsCode."$('#".$this->identifier."').modal('hide');}");
71 return $btn;
72 }
73
74 protected function getDefaultValidCondition() {
75 return "$('#".$this->identifier."').prop('valid')";
76 }
77
78 public function setValidCondition($js) {
79 $this->validCondition=$js;
80 }
81
82 public function getValidCondition() {
83 if ($this->validCondition==NULL) {
84 return $this->getDefaultValidCondition();
85 } else {
87 }
88 }
89
90 public function setValid() {
91 $this->validCondition="1==1";
92 }
93
98 public function setContent($content) {
99 $this->content=$content;
100 }
101
106 public function setTitle($title) {
107 $this->title=$title;
108 }
109
117 public function renderView(JsUtils $js,$initialController,$viewName, $params=array()) {
118 $this->content=$js->renderContent($initialController, $viewName,$params);
119 }
120
129 public function forward(JsUtils $js,$initialControllerInstance,$controllerName,$actionName,$params=NULL){
130 $this->content=$js->forward($initialControllerInstance, $controllerName, $actionName,$params);
131 }
132
133 /*
134 * (non-PHPdoc)
135 * @see BaseHtml::run()
136 */
137 public function run(JsUtils $js) {
138 if($this->content instanceof BaseHtml){
139 $this->content->run($js);
140 }
141 $this->_bsComponent=$js->bootstrap()->modal("#".$this->identifier, array (
142 "show" => $this->showOnStartup
143 ));
144 if ($this->draggable)
145 $this->_bsComponent->setDraggable(true);
146 $this->_bsComponent->setBackdrop($this->backdrop);
147 $this->addEventsOnRun($js);
148 return $this->_bsComponent;
149 }
150
151 public function getButton($index) {
152 if (is_int($index))
153 return $this->buttons [$index];
154 else
155 return $this->getElementById($index, $this->buttons);
156 }
157
158 public function showOnCreate() {
159 $this->showOnStartup=true;
160 return $this;
161 }
162
163 public function jsShow() {
164 return "$('#{$this->identifier}').modal('show');";
165 }
166
167 public function jsHide() {
168 return "$('#{$this->identifier}').modal('hide');";
169 }
170
171 public function jsGetContent(JsUtils $js, $url) {
172 return $js->getDeferred($url, "#".$this->identifier." .modal-body");
173 }
174
175 public function jsSetTitle($title) {
176 return "$('#".$this->identifier." .modal-title').html('".$title."');";
177 }
178
179 public function jsHideButton($index) {
180 $btn=$this->getButton($index);
181 if ($btn)
182 return "$('#".$btn->getIdentifier()."').hide();";
183 }
184
190 public function draggable($value=true) {
191 $this->draggable=$value;
192 if ($value) {
193 $this->backdrop=false;
194 }
195 }
196
203 public function setBackdrop($value) {
204 $this->backdrop=$value;
205 return $this;
206 }
207}
JQuery PHP library.
Definition JsUtils.php:23
forward($initialController, $controller, $action, $params)
Forwards to.
renderContent($initialControllerInstance, $viewName, $params=NULL)
render the content of an existing view : $viewName and set the response to the modal content Used int...
bootstrap(Bootstrap $bootstrap=NULL)
getter or setter of the Twitter Bootstrap variable
Definition JsUtils.php:140
Twitter Bootstrap Button component.
Twitter Bootstrap HTML Modal component.
Definition HtmlModal.php:14
addCancelButton($value="Annuler")
Add a cancel button (dismiss)
Definition HtmlModal.php:57
setContent($content)
set the content of the modal
Definition HtmlModal.php:98
renderView(JsUtils $js, $initialController, $viewName, $params=array())
render the content of an existing view : $controller/$action and set the response to the modal conten...
draggable($value=true)
Allow modal to be moved using the mouse, on the dialog title.
setBackdrop($value)
Includes a modal-backdrop element.
setTitle($title)
set the title of the modal
addButton($value="Okay", $style="btn-primary")
Add a button.
Definition HtmlModal.php:44
__construct($identifier, $title="", $content="", $buttonCaptions=array())
Definition HtmlModal.php:27
addOkayButton($value="Okay", $jsCode="")
Add an Okay button (close the box only if .valid===true)
Definition HtmlModal.php:68
forward(JsUtils $js, $initialControllerInstance, $controllerName, $actionName, $params=NULL)
render the content of
jsGetContent(JsUtils $js, $url)
BaseHtml for HTML components.
Definition BaseHtml.php:17
getElementById($identifier, $elements)
Definition BaseHtml.php:178
getDeferred($url, $responseElement="", $parameters=[])
Prepares a Get ajax request for using on an event.