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
3
11
18
19 protected $_params = [];
20
21 protected $_paramParts = [];
22
23 public function __construct($identifier, $header = '', $content = '', $actions = null) {
24 parent::__construct($identifier, 'div', 'ui modal');
25 if (isset($header)) {
26 $this->setHeader($header);
27 }
28 if (isset($content)) {
29 $this->setContent($content);
30 }
31 if (isset($actions)) {
32 $this->setActions($actions);
33 }
34 }
35
36 public function setHeader($value) {
37 $this->content['header'] = new HtmlSemDoubleElement('header-' . $this->identifier, 'a', 'header', $value);
38 return $this;
39 }
40
41 public function setContent($value) {
42 $this->content['content'] = new HtmlSemDoubleElement('content-' . $this->identifier, 'div', 'content', $value);
43 return $this;
44 }
45
52 public function setActions($actions): array {
53 $this->content['actions'] = new HtmlSemDoubleElement('content-' . $this->identifier, 'div', 'actions');
54 $r = [];
55 if (\is_array($actions)) {
56 foreach ($actions as $action) {
57 $r[] = $this->addAction($action);
58 }
59 } else {
60 $r[] = $this->addAction($actions);
61 }
62 return $r;
63 }
64
70 public function addAction($action) {
71 if (! $action instanceof BaseHtml) {
72 $class = '';
73 if (\array_search($action, [
74 'Okay',
75 'Yes',
76 'Validate'
77 ]) !== false) {
78 $class = 'approve';
79 }
80 if (\array_search($action, [
81 'Close',
82 'Cancel',
83 'No'
84 ]) !== false) {
85 $class = 'cancel';
86 }
87 $action = new HtmlButton('action-' . $this->identifier . '-' . JArray::count($this->content['actions']->getContent()), $action);
88 if ($class !== '')
89 $action->addToProperty('class', $class);
90 }
91 return $this->addElementInPart($action, 'actions');
92 }
93
99 public function getAction($index) {
100 return $this->content['actions']->getContent()[$index];
101 }
102
103 public function addContent($content, $before = false) {
104 $this->content['content']->addContent($content, $before);
105 return $this;
106 }
107
108 public function addImageContent($image, $description = NULL) {
109 $content = $this->content['content'];
110 if (isset($description)) {
111 $description = new HtmlSemDoubleElement('description-' . $this->identifier, 'div', 'description', $description);
112 $content->addContent($description, true);
113 }
114 if ($image !== '') {
115 $img = new HtmlImage('image-' . $this->identifier, $image, '', 'medium');
116 $content->addContent($img, true);
117 $content->addToProperty('class', 'image');
118 }
119 return $this;
120 }
121
122 public function addIconContent($icon, $description = NULL) {
123 $content = $this->content['content'];
124 if (isset($description)) {
125 $description = new HtmlSemDoubleElement('description-' . $this->identifier, 'div', 'description', $description);
126 $content->addContent($description, true);
127 }
128 if ($icon !== '') {
129 $img = new HtmlIcon('image-' . $this->identifier, $icon);
130 $content->addContent($img, true);
131 $content->addToProperty('class', 'image');
132 }
133 return $this;
134 }
135
136 private function addElementInPart($element, $part) {
137 $this->content[$part]->addContent($element);
138 return $element;
139 }
140
141 public function showDimmer($value) {
142 $value = $value ? 'show' : 'hide';
143 $this->_paramParts[] = [
144 "'" . $value . " dimmer'"
145 ];
146 return $this;
147 }
148
149 public function setInverted($recursive = true) {
150 $this->_params['inverted'] = true;
151 return $this;
152 }
153
154 public function setBasic() {
155 return $this->addToProperty('class', 'basic');
156 }
157
158 public function setTransition($value) {
159 $this->_paramParts[] = [
160 "'setting'",
161 "'transition'",
162 "'" . $value . "'"
163 ];
164 }
165
175 public function renderView(JsUtils $js, $initialController, $viewName, $params = array()) {
176 return $this->setContent($js->renderContent($initialController, $viewName, $params));
177 }
178
190 public function forward(JsUtils $js, $initialControllerInstance, $controllerName, $actionName, $params = NULL) {
191 return $this->setContent($js->forward($initialControllerInstance, $controllerName, $actionName, $params));
192 }
193
200 public function compile(JsUtils $js = NULL, &$view = NULL) {
201 $this->content = JArray::sortAssociative($this->content, [
202 'header',
203 'content',
204 'actions'
205 ]);
206 if (isset($this->_params['inverted']) && $this->_params['inverted']) {
207 parent::setInverted(true);
208 }
209 return parent::compile($js, $view);
210 }
211
212 /*
213 * (non-PHPdoc)
214 * @see BaseHtml::run()
215 */
216 public function run(JsUtils $js) {
217 if (isset($this->_bsComponent) === false)
218 $this->_bsComponent = $js->semantic()->modal('#' . $this->identifier, $this->_params, $this->_paramParts);
219 $this->addEventsOnRun($js);
220 return $this->_bsComponent;
221 }
222
223 public function jsDo($behavior) {
224 return "$('#" . $this->identifier . "').modal('" . $behavior . "');";
225 }
226
227 public function jsHide() {
228 return $this->jsDo('hide');
229 }
230
231 public function onHidden($js) {
232 $this->_params['onHidden'] = $js;
233 }
234}
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...
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
Definition JsUtils.php:158
BaseHtml for HTML components.
Definition BaseHtml.php:17
Base class for Semantic double elements.
Semantic Button component.
Semantic Icon component.
Definition HtmlIcon.php:14
Semantic Image component.
Definition HtmlImage.php:16
run(JsUtils $js)
{{SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()}HtmlDoubleElement:...
renderView(JsUtils $js, $initialController, $viewName, $params=array())
render the content of an existing view : $controller/$action and set the response to the modal conten...
__construct($identifier, $header='', $content='', $actions=null)
Definition HtmlModal.php:23
setInverted($recursive=true)
can be formatted to appear on dark backgrounds
setActions($actions)
Adds the modal actions (buttons).
Definition HtmlModal.php:52
compile(JsUtils $js=NULL, &$view=NULL)
{{}BaseHtml::compile()}
addImageContent($image, $description=NULL)
forward(JsUtils $js, $initialControllerInstance, $controllerName, $actionName, $params=NULL)
render the content of
addContent($content, $before=false)
addIconContent($icon, $description=NULL)