@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | use Ajax\common\html\traits\BaseHooksTrait; |
22 | 22 | |
23 | 23 | abstract class Widget extends HtmlDoubleElement { |
24 | - use FieldAsTrait,FormTrait,BaseHooksTrait; |
|
24 | + use FieldAsTrait, FormTrait, BaseHooksTrait; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @var string classname |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | protected $_hasRules; |
57 | 57 | |
58 | 58 | |
59 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
59 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
60 | 60 | parent::__construct($identifier); |
61 | 61 | $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
62 | 62 | $this->setModel($model); |
63 | - if(isset($modelInstance)){ |
|
63 | + if (isset($modelInstance)) { |
|
64 | 64 | $this->show($modelInstance); |
65 | 65 | } |
66 | 66 | $this->_generated=false; |
67 | 67 | } |
68 | 68 | |
69 | - protected function _init($instanceViewer,$contentKey,$content,$edition){ |
|
69 | + protected function _init($instanceViewer, $contentKey, $content, $edition) { |
|
70 | 70 | $this->_instanceViewer=$instanceViewer; |
71 | 71 | $this->content=[$contentKey=>$content]; |
72 | 72 | $this->_self=$content; |
@@ -78,31 +78,31 @@ discard block |
||
78 | 78 | * @param int|string $fieldName |
79 | 79 | * @return int|string|boolean |
80 | 80 | */ |
81 | - protected function _getIndex($fieldName){ |
|
81 | + protected function _getIndex($fieldName) { |
|
82 | 82 | $index=$fieldName; |
83 | - if(\is_string($fieldName)){ |
|
83 | + if (\is_string($fieldName)) { |
|
84 | 84 | $fields=$this->_instanceViewer->getVisibleProperties(); |
85 | 85 | $index=\array_search($fieldName, $fields); |
86 | 86 | } |
87 | 87 | return $index; |
88 | 88 | } |
89 | 89 | |
90 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
90 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
91 | 91 | return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
92 | 92 | } |
93 | 93 | |
94 | - protected function _getFieldName($index){ |
|
94 | + protected function _getFieldName($index) { |
|
95 | 95 | return $this->_instanceViewer->getFieldName($index); |
96 | 96 | } |
97 | 97 | |
98 | - protected function _getFieldCaption($index){ |
|
98 | + protected function _getFieldCaption($index) { |
|
99 | 99 | return $this->_instanceViewer->getCaption($index); |
100 | 100 | } |
101 | 101 | |
102 | - abstract protected function _setToolbarPosition($table,$captions=NULL); |
|
102 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
103 | 103 | |
104 | - public function show($modelInstance){ |
|
105 | - if(\is_array($modelInstance)){ |
|
104 | + public function show($modelInstance) { |
|
105 | + if (\is_array($modelInstance)) { |
|
106 | 106 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
107 | 107 | } |
108 | 108 | $this->_modelInstance=$modelInstance; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | abstract public function getHtmlComponent(); |
130 | 130 | |
131 | - public function setAttached($value=true){ |
|
131 | + public function setAttached($value=true) { |
|
132 | 132 | return $this->getHtmlComponent()->setAttached($value); |
133 | 133 | } |
134 | 134 | |
@@ -139,69 +139,69 @@ discard block |
||
139 | 139 | * @param callable $callback function called after the field compilation |
140 | 140 | * @return Widget |
141 | 141 | */ |
142 | - public function afterCompile($index,$callback){ |
|
142 | + public function afterCompile($index, $callback) { |
|
143 | 143 | $index=$this->_getIndex($index); |
144 | - if($index!==false){ |
|
144 | + if ($index!==false) { |
|
145 | 145 | $this->_instanceViewer->afterCompile($index, $callback); |
146 | 146 | } |
147 | 147 | return $this; |
148 | 148 | } |
149 | 149 | |
150 | - public function setColor($color){ |
|
150 | + public function setColor($color) { |
|
151 | 151 | return $this->getHtmlComponent()->setColor($color); |
152 | 152 | } |
153 | 153 | |
154 | 154 | |
155 | - public function setCaptions($captions){ |
|
155 | + public function setCaptions($captions) { |
|
156 | 156 | $this->_instanceViewer->setCaptions($captions); |
157 | 157 | return $this; |
158 | 158 | } |
159 | 159 | |
160 | - public function setCaption($index,$caption){ |
|
160 | + public function setCaption($index, $caption) { |
|
161 | 161 | $this->_instanceViewer->setCaption($this->_getIndex($index), $caption); |
162 | 162 | return $this; |
163 | 163 | } |
164 | 164 | |
165 | - public function setFields($fields){ |
|
165 | + public function setFields($fields) { |
|
166 | 166 | $this->_instanceViewer->setVisibleProperties($fields); |
167 | 167 | return $this; |
168 | 168 | } |
169 | 169 | |
170 | - public function addField($field,$key=null){ |
|
171 | - $this->_instanceViewer->addField($field,$key); |
|
170 | + public function addField($field, $key=null) { |
|
171 | + $this->_instanceViewer->addField($field, $key); |
|
172 | 172 | return $this; |
173 | 173 | } |
174 | 174 | |
175 | 175 | |
176 | - public function addFields($fields){ |
|
176 | + public function addFields($fields) { |
|
177 | 177 | $this->_instanceViewer->addFields($fields); |
178 | 178 | return $this; |
179 | 179 | } |
180 | 180 | |
181 | - public function countFields(){ |
|
181 | + public function countFields() { |
|
182 | 182 | return $this->_instanceViewer->visiblePropertiesCount(); |
183 | 183 | } |
184 | 184 | |
185 | - public function addMessage($attributes=NULL,$fieldName="message"){ |
|
185 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
186 | 186 | $this->_instanceViewer->addField($fieldName); |
187 | 187 | $count=$this->_instanceViewer->visiblePropertiesCount(); |
188 | - return $this->fieldAsMessage($count-1,$attributes); |
|
188 | + return $this->fieldAsMessage($count-1, $attributes); |
|
189 | 189 | } |
190 | 190 | |
191 | - public function addErrorMessage(){ |
|
192 | - return $this->addMessage(["error"=>true],"message"); |
|
191 | + public function addErrorMessage() { |
|
192 | + return $this->addMessage(["error"=>true], "message"); |
|
193 | 193 | } |
194 | 194 | |
195 | - public function insertField($index,$field,$key=null){ |
|
195 | + public function insertField($index, $field, $key=null) { |
|
196 | 196 | $index=$this->_getIndex($index); |
197 | - $this->_instanceViewer->insertField($index, $field,$key); |
|
197 | + $this->_instanceViewer->insertField($index, $field, $key); |
|
198 | 198 | return $this; |
199 | 199 | } |
200 | 200 | |
201 | - public function insertInField($index,$field,$key=null){ |
|
201 | + public function insertInField($index, $field, $key=null) { |
|
202 | 202 | $index=$this->_getIndex($index); |
203 | - if($index!==false){ |
|
204 | - $this->_instanceViewer->insertInField($index, $field,$key); |
|
203 | + if ($index!==false) { |
|
204 | + $this->_instanceViewer->insertInField($index, $field, $key); |
|
205 | 205 | } |
206 | 206 | return $this; |
207 | 207 | } |
@@ -212,15 +212,15 @@ discard block |
||
212 | 212 | * @param callable $callback function parameters are : $value : the field value, $instance : the active instance of model, $fieldIndex : the field index, $rowIndex : the row index |
213 | 213 | * @return Widget |
214 | 214 | */ |
215 | - public function setValueFunction($index,$callback){ |
|
215 | + public function setValueFunction($index, $callback) { |
|
216 | 216 | $index=$this->_getIndex($index); |
217 | - if($index!==false){ |
|
217 | + if ($index!==false) { |
|
218 | 218 | $this->_instanceViewer->setValueFunction($index, $callback); |
219 | 219 | } |
220 | 220 | return $this; |
221 | 221 | } |
222 | 222 | |
223 | - public function setIdentifierFunction($callback){ |
|
223 | + public function setIdentifierFunction($callback) { |
|
224 | 224 | $this->_instanceViewer->setIdentifierFunction($callback); |
225 | 225 | return $this; |
226 | 226 | } |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | /** |
229 | 229 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
230 | 230 | */ |
231 | - public function getToolbar(){ |
|
232 | - if(isset($this->_toolbar)===false){ |
|
231 | + public function getToolbar() { |
|
232 | + if (isset($this->_toolbar)===false) { |
|
233 | 233 | $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
234 | 234 | } |
235 | 235 | return $this->_toolbar; |
@@ -241,15 +241,15 @@ discard block |
||
241 | 241 | * @param callable $callback function to call on $element |
242 | 242 | * @return \Ajax\common\html\HtmlDoubleElement |
243 | 243 | */ |
244 | - public function addInToolbar($element,$callback=NULL){ |
|
244 | + public function addInToolbar($element, $callback=NULL) { |
|
245 | 245 | $tb=$this->getToolbar(); |
246 | - if($element instanceof BaseWidget){ |
|
247 | - if($element->getIdentifier()===""){ |
|
246 | + if ($element instanceof BaseWidget) { |
|
247 | + if ($element->getIdentifier()==="") { |
|
248 | 248 | $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
249 | 249 | } |
250 | 250 | } |
251 | - if(isset($callback)){ |
|
252 | - if(\is_callable($callback)){ |
|
251 | + if (isset($callback)) { |
|
252 | + if (\is_callable($callback)) { |
|
253 | 253 | $callback($element); |
254 | 254 | } |
255 | 255 | } |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param callable $callback function($element) |
263 | 263 | * @return \Ajax\common\html\HtmlDoubleElement |
264 | 264 | */ |
265 | - public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){ |
|
266 | - $result=$this->addInToolbar($caption,$callback); |
|
267 | - if(isset($icon) && method_exists($result, "addIcon")) |
|
265 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
266 | + $result=$this->addInToolbar($caption, $callback); |
|
267 | + if (isset($icon) && method_exists($result, "addIcon")) |
|
268 | 268 | $result->addIcon($icon); |
269 | 269 | return $result; |
270 | 270 | } |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | * @param callable $callback function($element) |
275 | 275 | * @return \Ajax\common\Widget |
276 | 276 | */ |
277 | - public function addItemsInToolbar(array $items,$callback=NULL){ |
|
278 | - if(JArray::isAssociative($items)){ |
|
279 | - foreach ($items as $icon=>$item){ |
|
280 | - $this->addItemInToolbar($item,$icon,$callback); |
|
277 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
278 | + if (JArray::isAssociative($items)) { |
|
279 | + foreach ($items as $icon=>$item) { |
|
280 | + $this->addItemInToolbar($item, $icon, $callback); |
|
281 | 281 | } |
282 | - }else{ |
|
283 | - foreach ($items as $item){ |
|
284 | - $this->addItemInToolbar($item,null,$callback); |
|
282 | + } else { |
|
283 | + foreach ($items as $item) { |
|
284 | + $this->addItemInToolbar($item, null, $callback); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | return $this; |
@@ -293,12 +293,12 @@ discard block |
||
293 | 293 | * @param callable $callback function($element) |
294 | 294 | * @return \Ajax\common\html\HtmlDoubleElement |
295 | 295 | */ |
296 | - public function addDropdownInToolbar($value,$items,$callback=NULL){ |
|
296 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
297 | 297 | $dd=$value; |
298 | 298 | if (\is_string($value)) { |
299 | - $dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items); |
|
299 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
300 | 300 | } |
301 | - return $this->addInToolbar($dd,$callback); |
|
301 | + return $this->addInToolbar($dd, $callback); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -307,9 +307,9 @@ discard block |
||
307 | 307 | * @param callable $callback function($element) |
308 | 308 | * @return \Ajax\common\html\HtmlDoubleElement |
309 | 309 | */ |
310 | - public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){ |
|
311 | - $bt=new HtmlButton("bt-".$caption,$caption,$cssStyle); |
|
312 | - return $this->addInToolbar($bt,$callback); |
|
310 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
311 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
312 | + return $this->addInToolbar($bt, $callback); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | * @param callable $callback function($element) |
319 | 319 | * @return \Ajax\common\html\HtmlDoubleElement |
320 | 320 | */ |
321 | - public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){ |
|
322 | - $bts=new HtmlButtonGroups("",$captions,$asIcon); |
|
323 | - return $this->addInToolbar($bts,$callback); |
|
321 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
322 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
323 | + return $this->addInToolbar($bts, $callback); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -330,15 +330,15 @@ discard block |
||
330 | 330 | * @param boolean $labeled |
331 | 331 | * @return \Ajax\common\html\HtmlDoubleElement |
332 | 332 | */ |
333 | - public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){ |
|
334 | - $bt=new HtmlButton("",$caption); |
|
335 | - $bt->addIcon($icon,$before,$labeled); |
|
333 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
334 | + $bt=new HtmlButton("", $caption); |
|
335 | + $bt->addIcon($icon, $before, $labeled); |
|
336 | 336 | return $this->addInToolbar($bt); |
337 | 337 | } |
338 | 338 | |
339 | - public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
340 | - $button=new HtmlButton($identifier,$value,$cssStyle); |
|
341 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters); |
|
339 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
340 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
341 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
|
342 | 342 | return $this->addInToolbar($button); |
343 | 343 | } |
344 | 344 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model |
369 | 369 | * @return \Ajax\common\Widget |
370 | 370 | */ |
371 | - public function setDefaultValueFunction($defaultValueFunction){ |
|
371 | + public function setDefaultValueFunction($defaultValueFunction) { |
|
372 | 372 | $this->_instanceViewer->setDefaultValueFunction($defaultValueFunction); |
373 | 373 | return $this; |
374 | 374 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | /** |
377 | 377 | * @return callable |
378 | 378 | */ |
379 | - public function getDefaultValueFunction(){ |
|
379 | + public function getDefaultValueFunction() { |
|
380 | 380 | return $this->_instanceViewer->getDefaultValueFunction(); |
381 | 381 | } |
382 | 382 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @param string|boolean $disable |
385 | 385 | * @return string |
386 | 386 | */ |
387 | - public function jsDisabled($disable=true){ |
|
387 | + public function jsDisabled($disable=true) { |
|
388 | 388 | return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
389 | 389 | } |
390 | 390 | |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | * @param callable $callback function($element) |
394 | 394 | * @return \Ajax\common\html\HtmlDoubleElement |
395 | 395 | */ |
396 | - public function addEditButtonInToolbar($caption,$callback=NULL){ |
|
397 | - $bt=new HtmlButton($this->identifier."-editBtn",$caption); |
|
396 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
397 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
398 | 398 | $bt->setToggle(); |
399 | 399 | $bt->setActive($this->_edition); |
400 | 400 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
401 | - return $this->addInToolbar($bt,$callback); |
|
401 | + return $this->addInToolbar($bt, $callback); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | public function setToolbar(HtmlMenu $_toolbar) { |
@@ -412,34 +412,34 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | public function getForm() { |
415 | - if(!isset($this->_form)){ |
|
415 | + if (!isset($this->_form)) { |
|
416 | 416 | $this->_form=new HtmlForm("frm-".$this->identifier); |
417 | 417 | $this->setEdition(true); |
418 | 418 | } |
419 | 419 | return $this->_form; |
420 | 420 | } |
421 | 421 | |
422 | - public function run(JsUtils $js){ |
|
422 | + public function run(JsUtils $js) { |
|
423 | 423 | parent::run($js); |
424 | - if(isset($this->_form)){ |
|
424 | + if (isset($this->_form)) { |
|
425 | 425 | $this->runForm($js); |
426 | 426 | } |
427 | 427 | } |
428 | 428 | |
429 | - protected function runForm(JsUtils $js){ |
|
429 | + protected function runForm(JsUtils $js) { |
|
430 | 430 | $fields=$this->getContentInstances(HtmlFormField::class); |
431 | - foreach ($fields as $field){ |
|
431 | + foreach ($fields as $field) { |
|
432 | 432 | $this->_form->addField($field); |
433 | 433 | } |
434 | 434 | return $this->_form->run($js); |
435 | 435 | } |
436 | 436 | |
437 | - protected function _compileForm(){ |
|
438 | - if(isset($this->_form)){ |
|
437 | + protected function _compileForm() { |
|
438 | + if (isset($this->_form)) { |
|
439 | 439 | $noValidate=""; |
440 | - if(\sizeof($this->_form->getValidationParams())>0) |
|
440 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
441 | 441 | $noValidate="novalidate"; |
442 | - $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>"); |
|
442 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
@@ -454,35 +454,35 @@ discard block |
||
454 | 454 | return $this; |
455 | 455 | } |
456 | 456 | |
457 | - public function moveFieldTo($from,$to){ |
|
457 | + public function moveFieldTo($from, $to) { |
|
458 | 458 | return $this->_instanceViewer->moveFieldTo($from, $to); |
459 | 459 | } |
460 | 460 | |
461 | - public function swapFields($index1,$index2){ |
|
461 | + public function swapFields($index1, $index2) { |
|
462 | 462 | $index1=$this->_getIndex($index1); |
463 | 463 | $index2=$this->_getIndex($index2); |
464 | 464 | return $this->_instanceViewer->swapFields($index1, $index2); |
465 | 465 | } |
466 | 466 | |
467 | - public function removeField($index){ |
|
467 | + public function removeField($index) { |
|
468 | 468 | $index=$this->_getIndex($index); |
469 | - if($index!==false){ |
|
469 | + if ($index!==false) { |
|
470 | 470 | $this->_instanceViewer->removeField($index); |
471 | 471 | } |
472 | 472 | return $this; |
473 | 473 | } |
474 | 474 | |
475 | - public function asModal($header=null){ |
|
476 | - $modal=new HtmlModal("modal-".$this->identifier,$header); |
|
475 | + public function asModal($header=null) { |
|
476 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
477 | 477 | $modal->setContent($this); |
478 | - if(isset($this->_form)){ |
|
478 | + if (isset($this->_form)) { |
|
479 | 479 | $this->_form->onSuccess($modal->jsHide()); |
480 | 480 | } |
481 | 481 | return $modal; |
482 | 482 | } |
483 | 483 | |
484 | 484 | public function addToProperty($name, $value, $separator=" ") { |
485 | - return $this->getHtmlComponent()->addToProperty($name,$value,$separator); |
|
485 | + return $this->getHtmlComponent()->addToProperty($name, $value, $separator); |
|
486 | 486 | } |
487 | 487 | /** |
488 | 488 | * @return mixed |