@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | use Ajax\common\html\traits\BaseHooksTrait; |
| 21 | 21 | |
| 22 | 22 | abstract class Widget extends HtmlDoubleElement { |
| 23 | - use FieldAsTrait,FormTrait,BaseHooksTrait; |
|
| 23 | + use FieldAsTrait, FormTrait, BaseHooksTrait; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * |
@@ -66,24 +66,24 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | protected $_hasRules; |
| 68 | 68 | |
| 69 | - public function __construct($identifier, $model, $modelInstance = NULL) { |
|
| 69 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 70 | 70 | parent::__construct($identifier); |
| 71 | - $this->_template = "%wrapContentBefore%%content%%wrapContentAfter%"; |
|
| 71 | + $this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
|
| 72 | 72 | $this->setModel($model); |
| 73 | 73 | if (isset($modelInstance)) { |
| 74 | 74 | $this->show($modelInstance); |
| 75 | 75 | } |
| 76 | - $this->_generated = false; |
|
| 76 | + $this->_generated=false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | protected function _init($instanceViewer, $contentKey, $content, $edition) { |
| 80 | - $this->_instanceViewer = $instanceViewer; |
|
| 81 | - $this->content = [ |
|
| 80 | + $this->_instanceViewer=$instanceViewer; |
|
| 81 | + $this->content=[ |
|
| 82 | 82 | $contentKey => $content |
| 83 | 83 | ]; |
| 84 | - $this->_self = $content; |
|
| 85 | - $this->_toolbarPosition = PositionInTable::BEFORETABLE; |
|
| 86 | - $this->_edition = $edition; |
|
| 84 | + $this->_self=$content; |
|
| 85 | + $this->_toolbarPosition=PositionInTable::BEFORETABLE; |
|
| 86 | + $this->_edition=$edition; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,16 +92,16 @@ discard block |
||
| 92 | 92 | * @return int|string|boolean |
| 93 | 93 | */ |
| 94 | 94 | protected function _getIndex($fieldName) { |
| 95 | - $index = $fieldName; |
|
| 95 | + $index=$fieldName; |
|
| 96 | 96 | if (\is_string($fieldName)) { |
| 97 | - $fields = $this->_instanceViewer->getVisibleProperties(); |
|
| 98 | - $index = \array_search($fieldName, $fields); |
|
| 97 | + $fields=$this->_instanceViewer->getVisibleProperties(); |
|
| 98 | + $index=\array_search($fieldName, $fields); |
|
| 99 | 99 | } |
| 100 | 100 | return $index; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - protected function _getFieldIdentifier($prefix, $name = "") { |
|
| 104 | - return $this->identifier . "-{$prefix}-" . $this->_instanceViewer->getIdentifier(); |
|
| 103 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 104 | + return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier(); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | protected function _getFieldName($index) { |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | return $this->_instanceViewer->getCaption($index); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - abstract protected function _setToolbarPosition($table, $captions = NULL); |
|
| 115 | + abstract protected function _setToolbarPosition($table, $captions=NULL); |
|
| 116 | 116 | |
| 117 | 117 | public function show($modelInstance) { |
| 118 | 118 | if (\is_array($modelInstance)) { |
| 119 | - $modelInstance = \json_decode(\json_encode($modelInstance), FALSE); |
|
| 119 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 120 | 120 | } |
| 121 | - $this->_modelInstance = $modelInstance; |
|
| 121 | + $this->_modelInstance=$modelInstance; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | public function getModel() { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function setModel($_model) { |
| 129 | - $this->_model = $_model; |
|
| 129 | + $this->_model=$_model; |
|
| 130 | 130 | return $this; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | public function setInstanceViewer($_instanceViewer) { |
| 138 | - $this->_instanceViewer = $_instanceViewer; |
|
| 138 | + $this->_instanceViewer=$_instanceViewer; |
|
| 139 | 139 | return $this; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | abstract public function getHtmlComponent(); |
| 143 | 143 | |
| 144 | - public function setAttached($value = true) { |
|
| 144 | + public function setAttached($value=true) { |
|
| 145 | 145 | return $this->getHtmlComponent()->setAttached($value); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | * @return Widget |
| 157 | 157 | */ |
| 158 | 158 | public function afterCompile($index, $callback) { |
| 159 | - $index = $this->_getIndex($index); |
|
| 160 | - if ($index !== false) { |
|
| 159 | + $index=$this->_getIndex($index); |
|
| 160 | + if ($index!==false) { |
|
| 161 | 161 | $this->_instanceViewer->afterCompile($index, $callback); |
| 162 | 162 | } |
| 163 | 163 | return $this; |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | return $this; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public function addField($field, $key = null) { |
|
| 185 | + public function addField($field, $key=null) { |
|
| 186 | 186 | $this->_instanceViewer->addField($field, $key); |
| 187 | 187 | return $this; |
| 188 | 188 | } |
@@ -196,10 +196,10 @@ discard block |
||
| 196 | 196 | return $this->_instanceViewer->visiblePropertiesCount(); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - public function addMessage($attributes = NULL, $fieldName = "message") { |
|
| 199 | + public function addMessage($attributes=NULL, $fieldName="message") { |
|
| 200 | 200 | $this->_instanceViewer->addField($fieldName); |
| 201 | - $count = $this->_instanceViewer->visiblePropertiesCount(); |
|
| 202 | - return $this->fieldAsMessage($count - 1, $attributes); |
|
| 201 | + $count=$this->_instanceViewer->visiblePropertiesCount(); |
|
| 202 | + return $this->fieldAsMessage($count-1, $attributes); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | public function addErrorMessage() { |
@@ -208,15 +208,15 @@ discard block |
||
| 208 | 208 | ], "message"); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function insertField($index, $field, $key = null) { |
|
| 212 | - $index = $this->_getIndex($index); |
|
| 211 | + public function insertField($index, $field, $key=null) { |
|
| 212 | + $index=$this->_getIndex($index); |
|
| 213 | 213 | $this->_instanceViewer->insertField($index, $field, $key); |
| 214 | 214 | return $this; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - public function insertInField($index, $field, $key = null) { |
|
| 218 | - $index = $this->_getIndex($index); |
|
| 219 | - if ($index !== false) { |
|
| 217 | + public function insertInField($index, $field, $key=null) { |
|
| 218 | + $index=$this->_getIndex($index); |
|
| 219 | + if ($index!==false) { |
|
| 220 | 220 | $this->_instanceViewer->insertInField($index, $field, $key); |
| 221 | 221 | } |
| 222 | 222 | return $this; |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | * @return Widget |
| 233 | 233 | */ |
| 234 | 234 | public function setValueFunction($index, $callback) { |
| 235 | - $index = $this->_getIndex($index); |
|
| 236 | - if ($index !== false) { |
|
| 235 | + $index=$this->_getIndex($index); |
|
| 236 | + if ($index!==false) { |
|
| 237 | 237 | $this->_instanceViewer->setValueFunction($index, $callback); |
| 238 | 238 | } |
| 239 | 239 | return $this; |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
| 250 | 250 | */ |
| 251 | 251 | public function getToolbar() { |
| 252 | - if (isset($this->_toolbar) === false) { |
|
| 253 | - $this->_toolbar = new HtmlMenu("toolbar-" . $this->identifier); |
|
| 252 | + if (isset($this->_toolbar)===false) { |
|
| 253 | + $this->_toolbar=new HtmlMenu("toolbar-".$this->identifier); |
|
| 254 | 254 | } |
| 255 | 255 | return $this->_toolbar; |
| 256 | 256 | } |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | * function to call on $element |
| 264 | 264 | * @return \Ajax\common\html\HtmlDoubleElement |
| 265 | 265 | */ |
| 266 | - public function addInToolbar($element, $callback = NULL) { |
|
| 267 | - $tb = $this->getToolbar(); |
|
| 266 | + public function addInToolbar($element, $callback=NULL) { |
|
| 267 | + $tb=$this->getToolbar(); |
|
| 268 | 268 | if ($element instanceof BaseWidget) { |
| 269 | - if ($element->getIdentifier() === "") { |
|
| 270 | - $element->setIdentifier("tb-item-" . $this->identifier . "-" . $tb->count()); |
|
| 269 | + if ($element->getIdentifier()==="") { |
|
| 270 | + $element->setIdentifier("tb-item-".$this->identifier."-".$tb->count()); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | if (isset($callback)) { |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * function($element) |
| 287 | 287 | * @return \Ajax\common\html\HtmlDoubleElement |
| 288 | 288 | */ |
| 289 | - public function addItemInToolbar($caption, $icon = NULL, $callback = NULL) { |
|
| 290 | - $result = $this->addInToolbar($caption, $callback); |
|
| 289 | + public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) { |
|
| 290 | + $result=$this->addInToolbar($caption, $callback); |
|
| 291 | 291 | if (isset($icon) && method_exists($result, "addIcon")) |
| 292 | 292 | $result->addIcon($icon); |
| 293 | 293 | return $result; |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * function($element) |
| 301 | 301 | * @return \Ajax\common\Widget |
| 302 | 302 | */ |
| 303 | - public function addItemsInToolbar(array $items, $callback = NULL) { |
|
| 303 | + public function addItemsInToolbar(array $items, $callback=NULL) { |
|
| 304 | 304 | if (JArray::isAssociative($items)) { |
| 305 | 305 | foreach ($items as $icon => $item) { |
| 306 | 306 | $this->addItemInToolbar($item, $icon, $callback); |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | * function($element) |
| 322 | 322 | * @return \Ajax\common\html\HtmlDoubleElement |
| 323 | 323 | */ |
| 324 | - public function addDropdownInToolbar($value, $items, $callback = NULL) { |
|
| 325 | - $dd = $value; |
|
| 324 | + public function addDropdownInToolbar($value, $items, $callback=NULL) { |
|
| 325 | + $dd=$value; |
|
| 326 | 326 | if (\is_string($value)) { |
| 327 | - $dd = new HtmlDropdown("dropdown-" . $this->identifier . "-" . $value, $value, $items); |
|
| 327 | + $dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items); |
|
| 328 | 328 | } |
| 329 | 329 | return $this->addInToolbar($dd, $callback); |
| 330 | 330 | } |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | * function($element) |
| 338 | 338 | * @return \Ajax\common\html\HtmlDoubleElement |
| 339 | 339 | */ |
| 340 | - public function addButtonInToolbar($caption, $cssStyle = null, $callback = NULL) { |
|
| 341 | - $bt = new HtmlButton("bt-" . $caption, $caption, $cssStyle); |
|
| 340 | + public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) { |
|
| 341 | + $bt=new HtmlButton("bt-".$caption, $caption, $cssStyle); |
|
| 342 | 342 | return $this->addInToolbar($bt, $callback); |
| 343 | 343 | } |
| 344 | 344 | |
@@ -350,8 +350,8 @@ discard block |
||
| 350 | 350 | * function($element) |
| 351 | 351 | * @return \Ajax\common\html\HtmlDoubleElement |
| 352 | 352 | */ |
| 353 | - public function addButtonsInToolbar(array $captions, $asIcon = false, $callback = NULL) { |
|
| 354 | - $bts = new HtmlButtonGroups("", $captions, $asIcon); |
|
| 353 | + public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) { |
|
| 354 | + $bts=new HtmlButtonGroups("", $captions, $asIcon); |
|
| 355 | 355 | return $this->addInToolbar($bts, $callback); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -363,14 +363,14 @@ discard block |
||
| 363 | 363 | * @param boolean $labeled |
| 364 | 364 | * @return \Ajax\common\html\HtmlDoubleElement |
| 365 | 365 | */ |
| 366 | - public function addLabelledIconButtonInToolbar($caption, $icon, $before = true, $labeled = false) { |
|
| 367 | - $bt = new HtmlButton("", $caption); |
|
| 366 | + public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) { |
|
| 367 | + $bt=new HtmlButton("", $caption); |
|
| 368 | 368 | $bt->addIcon($icon, $before, $labeled); |
| 369 | 369 | return $this->addInToolbar($bt); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - public function addSubmitInToolbar($identifier, $value, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $parameters = NULL) { |
|
| 373 | - $button = new HtmlButton($identifier, $value, $cssStyle); |
|
| 372 | + public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 373 | + $button=new HtmlButton($identifier, $value, $cssStyle); |
|
| 374 | 374 | $this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters); |
| 375 | 375 | return $this->addInToolbar($button); |
| 376 | 376 | } |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | * @param boolean $_edition |
| 394 | 394 | * @return \Ajax\common\Widget |
| 395 | 395 | */ |
| 396 | - public function setEdition($_edition = true) { |
|
| 397 | - $this->_edition = $_edition; |
|
| 396 | + public function setEdition($_edition=true) { |
|
| 397 | + $this->_edition=$_edition; |
|
| 398 | 398 | return $this; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -423,8 +423,8 @@ discard block |
||
| 423 | 423 | * @param string|boolean $disable |
| 424 | 424 | * @return string |
| 425 | 425 | */ |
| 426 | - public function jsDisabled($disable = true) { |
|
| 427 | - return "$('#" . $this->identifier . " .ui.input,#" . $this->identifier . " .ui.dropdown,#" . $this->identifier . " .ui.checkbox').toggleClass('disabled'," . $disable . ");"; |
|
| 426 | + public function jsDisabled($disable=true) { |
|
| 427 | + return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");"; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -434,8 +434,8 @@ discard block |
||
| 434 | 434 | * function($element) |
| 435 | 435 | * @return \Ajax\common\html\HtmlDoubleElement |
| 436 | 436 | */ |
| 437 | - public function addEditButtonInToolbar($caption, $callback = NULL) { |
|
| 438 | - $bt = new HtmlButton($this->identifier . "-editBtn", $caption); |
|
| 437 | + public function addEditButtonInToolbar($caption, $callback=NULL) { |
|
| 438 | + $bt=new HtmlButton($this->identifier."-editBtn", $caption); |
|
| 439 | 439 | $bt->setToggle(); |
| 440 | 440 | $bt->setActive($this->_edition); |
| 441 | 441 | $bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')"))); |
@@ -443,18 +443,18 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | public function setToolbar(HtmlMenu $_toolbar) { |
| 446 | - $this->_toolbar = $_toolbar; |
|
| 446 | + $this->_toolbar=$_toolbar; |
|
| 447 | 447 | return $this; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | public function setToolbarPosition($_toolbarPosition) { |
| 451 | - $this->_toolbarPosition = $_toolbarPosition; |
|
| 451 | + $this->_toolbarPosition=$_toolbarPosition; |
|
| 452 | 452 | return $this; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | public function getForm() { |
| 456 | - if (! isset($this->_form)) { |
|
| 457 | - $this->_form = new HtmlForm("frm-" . $this->identifier); |
|
| 456 | + if (!isset($this->_form)) { |
|
| 457 | + $this->_form=new HtmlForm("frm-".$this->identifier); |
|
| 458 | 458 | $this->setEdition(true); |
| 459 | 459 | } |
| 460 | 460 | return $this->_form; |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | protected function runForm(JsUtils $js) { |
| 471 | - $fields = $this->getContentInstances(HtmlFormField::class); |
|
| 471 | + $fields=$this->getContentInstances(HtmlFormField::class); |
|
| 472 | 472 | foreach ($fields as $field) { |
| 473 | 473 | $this->_form->addField($field); |
| 474 | 474 | } |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | |
| 478 | 478 | protected function _compileForm() { |
| 479 | 479 | if (isset($this->_form)) { |
| 480 | - $noValidate = ""; |
|
| 481 | - if (\sizeof($this->_form->getValidationParams()) > 0) |
|
| 482 | - $noValidate = "novalidate"; |
|
| 483 | - $this->wrapContent("<form class='ui form' id='frm-" . $this->identifier . "' name='frm-" . $this->identifier . "' " . $noValidate . ">", "</form>"); |
|
| 480 | + $noValidate=""; |
|
| 481 | + if (\sizeof($this->_form->getValidationParams())>0) |
|
| 482 | + $noValidate="novalidate"; |
|
| 483 | + $this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>"); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
@@ -502,21 +502,21 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | public function swapFields($index1, $index2) { |
| 505 | - $index1 = $this->_getIndex($index1); |
|
| 506 | - $index2 = $this->_getIndex($index2); |
|
| 505 | + $index1=$this->_getIndex($index1); |
|
| 506 | + $index2=$this->_getIndex($index2); |
|
| 507 | 507 | return $this->_instanceViewer->swapFields($index1, $index2); |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | public function removeField($index) { |
| 511 | - $index = $this->_getIndex($index); |
|
| 512 | - if ($index !== false) { |
|
| 511 | + $index=$this->_getIndex($index); |
|
| 512 | + if ($index!==false) { |
|
| 513 | 513 | $this->_instanceViewer->removeField($index); |
| 514 | 514 | } |
| 515 | 515 | return $this; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - public function asModal($header = null) { |
|
| 519 | - $modal = new HtmlModal("modal-" . $this->identifier, $header); |
|
| 518 | + public function asModal($header=null) { |
|
| 519 | + $modal=new HtmlModal("modal-".$this->identifier, $header); |
|
| 520 | 520 | $modal->setContent($this); |
| 521 | 521 | if (isset($this->_form)) { |
| 522 | 522 | $this->_form->onSuccess($modal->jsHide()); |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | return $modal; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - public function addToProperty($name, $value, $separator = " ") { |
|
| 527 | + public function addToProperty($name, $value, $separator=" ") { |
|
| 528 | 528 | return $this->getHtmlComponent()->addToProperty($name, $value, $separator); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | trait FieldAsTrait { |
| 38 | 38 | |
| 39 | - abstract protected function _getFieldIdentifier($prefix, $name = ""); |
|
| 39 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
| 40 | 40 | |
| 41 | 41 | abstract public function setValueFunction($index, $callback); |
| 42 | 42 | |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | abstract protected function _getFieldCaption($index); |
| 46 | 46 | |
| 47 | - abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement = NULL, $parameters = NULL); |
|
| 47 | + abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * |
| 51 | 51 | * @param HtmlFormField $element |
| 52 | 52 | * @param array $attributes |
| 53 | 53 | */ |
| 54 | - protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance = null) { |
|
| 54 | + protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance=null) { |
|
| 55 | 55 | if (isset($attributes["jsCallback"])) { |
| 56 | - $callback = $attributes["jsCallback"]; |
|
| 56 | + $callback=$attributes["jsCallback"]; |
|
| 57 | 57 | if (\is_callable($callback)) { |
| 58 | 58 | $callback($element, $instance, $index, InstanceViewer::$index); |
| 59 | 59 | } |
@@ -64,15 +64,15 @@ discard block |
||
| 64 | 64 | $element->fromArray($attributes); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - private function _getLabelField($caption, $icon = NULL) { |
|
| 68 | - $label = new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 67 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 68 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 69 | 69 | return $label; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | protected function _addRules(HtmlFormField $element, &$attributes) { |
| 73 | 73 | if (isset($attributes["rules"])) { |
| 74 | - $this->_hasRules = true; |
|
| 75 | - $rules = $attributes["rules"]; |
|
| 74 | + $this->_hasRules=true; |
|
| 75 | + $rules=$attributes["rules"]; |
|
| 76 | 76 | if (\is_array($rules)) { |
| 77 | 77 | $element->addRules($rules); |
| 78 | 78 | } else { |
@@ -88,62 +88,62 @@ discard block |
||
| 88 | 88 | return $field; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $prefix = null) { |
|
| 92 | - $this->setValueFunction($index, function ($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
| 93 | - $caption = $this->_getFieldCaption($index); |
|
| 94 | - $name = $this->_getFieldName($index); |
|
| 95 | - $id = $this->_getFieldIdentifier($prefix, $name); |
|
| 91 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
| 92 | + $this->setValueFunction($index, function($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
| 93 | + $caption=$this->_getFieldCaption($index); |
|
| 94 | + $name=$this->_getFieldName($index); |
|
| 95 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
| 96 | 96 | if (isset($attributes["name"])) { |
| 97 | - $name = $attributes["name"]; |
|
| 97 | + $name=$attributes["name"]; |
|
| 98 | 98 | unset($attributes["name"]); |
| 99 | 99 | } |
| 100 | - $element = $elementCallback($id, $name, $value, $caption); |
|
| 100 | + $element=$elementCallback($id, $name, $value, $caption); |
|
| 101 | 101 | if (\is_array($attributes)) { |
| 102 | 102 | $this->_applyAttributes($element, $attributes, $index, $instance); |
| 103 | 103 | } |
| 104 | - $element->setDisabled(! $this->_edition); |
|
| 104 | + $element->setDisabled(!$this->_edition); |
|
| 105 | 105 | return $element; |
| 106 | 106 | }); |
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function fieldAsProgress($index, $label = NULL, $attributes = array()) { |
|
| 111 | - $this->setValueFunction($index, function ($value) use ($label, $attributes) { |
|
| 112 | - $pb = new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 110 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 111 | + $this->setValueFunction($index, function($value) use ($label, $attributes) { |
|
| 112 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 113 | 113 | return $pb; |
| 114 | 114 | }); |
| 115 | 115 | return $this; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function fieldAsRating($index, $max = 5, $icon = "") { |
|
| 119 | - $this->setValueFunction($index, function ($value) use ($max, $icon) { |
|
| 120 | - $rating = new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 118 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 119 | + $this->setValueFunction($index, function($value) use ($max, $icon) { |
|
| 120 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 121 | 121 | return $rating; |
| 122 | 122 | }); |
| 123 | 123 | return $this; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function fieldAsLabel($index, $icon = NULL, $attributes = NULL) { |
|
| 127 | - return $this->_fieldAs(function ($id, $name, $value) use ($icon) { |
|
| 128 | - $lbl = new HtmlLabel($id, $value); |
|
| 126 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
| 127 | + return $this->_fieldAs(function($id, $name, $value) use ($icon) { |
|
| 128 | + $lbl=new HtmlLabel($id, $value); |
|
| 129 | 129 | if (isset($icon)) |
| 130 | 130 | $lbl->addIcon($icon); |
| 131 | 131 | return $lbl; |
| 132 | 132 | }, $index, $attributes, "label"); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function fieldAsHeader($index, $niveau = 1, $icon = NULL, $attributes = NULL) { |
|
| 136 | - return $this->_fieldAs(function ($id, $name, $value) use ($niveau, $icon) { |
|
| 137 | - $header = new HtmlHeader($id, $niveau, $value); |
|
| 135 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
| 136 | + return $this->_fieldAs(function($id, $name, $value) use ($niveau, $icon) { |
|
| 137 | + $header=new HtmlHeader($id, $niveau, $value); |
|
| 138 | 138 | if (isset($icon)) |
| 139 | 139 | $header->asIcon($icon, $value); |
| 140 | 140 | return $header; |
| 141 | 141 | }, $index, $attributes, "header"); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - public function fieldAsImage($index, $size = Size::MINI, $circular = false) { |
|
| 145 | - $this->setValueFunction($index, function ($img) use ($size, $circular) { |
|
| 146 | - $image = new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
| 144 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
| 145 | + $this->setValueFunction($index, function($img) use ($size, $circular) { |
|
| 146 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
| 147 | 147 | $image->setSize($size); |
| 148 | 148 | if ($circular) |
| 149 | 149 | $image->setCircular(); |
@@ -153,131 +153,131 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | public function fieldAsFlag($index) { |
| 156 | - $this->setValueFunction($index, function ($flag) { |
|
| 157 | - $flag = new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 156 | + $this->setValueFunction($index, function($flag) { |
|
| 157 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
| 158 | 158 | return $flag; |
| 159 | 159 | }); |
| 160 | 160 | return $this; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function fieldAsIcon($index) { |
| 164 | - $this->setValueFunction($index, function ($icon) { |
|
| 165 | - $icon = new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
| 164 | + $this->setValueFunction($index, function($icon) { |
|
| 165 | + $icon=new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
| 166 | 166 | return $icon; |
| 167 | 167 | }); |
| 168 | 168 | return $this; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - public function fieldAsAvatar($index, $attributes = NULL) { |
|
| 172 | - return $this->_fieldAs(function ($id, $name, $value) { |
|
| 173 | - $img = new HtmlImage($id, $value); |
|
| 171 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
| 172 | + return $this->_fieldAs(function($id, $name, $value) { |
|
| 173 | + $img=new HtmlImage($id, $value); |
|
| 174 | 174 | $img->asAvatar(); |
| 175 | 175 | return $img; |
| 176 | 176 | }, $index, $attributes, "avatar"); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - public function fieldAsRadio($index, $attributes = NULL) { |
|
| 180 | - return $this->_fieldAs(function ($id, $name, $value) use ($attributes) { |
|
| 181 | - $input = new HtmlFormRadio($id, $name, $value, $value); |
|
| 179 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 180 | + return $this->_fieldAs(function($id, $name, $value) use ($attributes) { |
|
| 181 | + $input=new HtmlFormRadio($id, $name, $value, $value); |
|
| 182 | 182 | return $this->_prepareFormFields($input, $name, $attributes); |
| 183 | 183 | }, $index, $attributes, "radio"); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function fieldAsRadios($index, $elements = [], $attributes = NULL) { |
|
| 187 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements) { |
|
| 186 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
| 187 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements) { |
|
| 188 | 188 | return HtmlFormFields::radios($name, $elements, $caption, $value); |
| 189 | 189 | }, $index, $attributes, "radios"); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - public function fieldAsList($index, $classNames = "", $attributes = NULL) { |
|
| 193 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($classNames) { |
|
| 194 | - $result = new HtmlList($name, $value); |
|
| 192 | + public function fieldAsList($index, $classNames="", $attributes=NULL) { |
|
| 193 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($classNames) { |
|
| 194 | + $result=new HtmlList($name, $value); |
|
| 195 | 195 | $result->addClass($classNames); |
| 196 | 196 | return $result; |
| 197 | 197 | }, $index, $attributes, "list"); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - public function fieldAsInput($index, $attributes = NULL) { |
|
| 201 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 202 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
| 200 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 201 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 202 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 203 | 203 | return $this->_prepareFormFields($input, $name, $attributes); |
| 204 | 204 | }, $index, $attributes, "input"); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - public function fieldAsDataList($index, ?array $items = [], $attributes = NULL) { |
|
| 208 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $items) { |
|
| 209 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
| 207 | + public function fieldAsDataList($index, ?array $items=[], $attributes=NULL) { |
|
| 208 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $items) { |
|
| 209 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
| 210 | 210 | $input->getField() |
| 211 | 211 | ->addDataList($items); |
| 212 | 212 | return $this->_prepareFormFields($input, $name, $attributes); |
| 213 | 213 | }, $index, $attributes, "input"); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - public function fieldAsFile($index, $attributes = NULL) { |
|
| 216 | + public function fieldAsFile($index, $attributes=NULL) { |
|
| 217 | 217 | if (isset($this->_form)) { |
| 218 | 218 | $this->_form->setProperty('enctype', 'multipart/form-data'); |
| 219 | 219 | } |
| 220 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 221 | - $input = new HtmlFormInput($id, $caption); |
|
| 220 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 221 | + $input=new HtmlFormInput($id, $caption); |
|
| 222 | 222 | $input->asFile(); |
| 223 | 223 | return $this->_prepareFormFields($input, $name, $attributes); |
| 224 | 224 | }, $index, $attributes, "input"); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - public function fieldAsTextarea($index, $attributes = NULL) { |
|
| 228 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 229 | - $textarea = new HtmlFormTextarea($id, $caption, $value); |
|
| 227 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
| 228 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 229 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
| 230 | 230 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 231 | 231 | }, $index, $attributes, "textarea"); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - public function fieldAsElement($index, $tagName = "div", $baseClass = "", $attributes = NULL) { |
|
| 235 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
| 236 | - $div = new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
| 234 | + public function fieldAsElement($index, $tagName="div", $baseClass="", $attributes=NULL) { |
|
| 235 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
| 236 | + $div=new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
| 237 | 237 | $div->setContent(\htmlentities($value)); |
| 238 | - $textarea = new HtmlFormField("field-" . $id, $div, $caption); |
|
| 238 | + $textarea=new HtmlFormField("field-".$id, $div, $caption); |
|
| 239 | 239 | return $this->_prepareFormFields($textarea, $name, $attributes); |
| 240 | 240 | }, $index, $attributes, "element"); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - public function fieldAsHidden($index, $attributes = NULL) { |
|
| 244 | - if (! \is_array($attributes)) { |
|
| 245 | - $attributes = []; |
|
| 243 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
| 244 | + if (!\is_array($attributes)) { |
|
| 245 | + $attributes=[]; |
|
| 246 | 246 | } |
| 247 | - $attributes["inputType"] = "hidden"; |
|
| 248 | - $attributes["style"] = "display:none;"; |
|
| 247 | + $attributes["inputType"]="hidden"; |
|
| 248 | + $attributes["style"]="display:none;"; |
|
| 249 | 249 | return $this->fieldAsInput($index, $attributes); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - public function fieldAsCheckbox($index, $attributes = NULL) { |
|
| 253 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
| 254 | - if ($caption === null || $caption === "") |
|
| 255 | - $caption = ""; |
|
| 256 | - $input = new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 252 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 253 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
| 254 | + if ($caption===null || $caption==="") |
|
| 255 | + $caption=""; |
|
| 256 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
| 257 | 257 | $input->setChecked(JString::isBooleanTrue($value)); |
| 258 | 258 | return $this->_prepareFormFields($input, $name, $attributes); |
| 259 | 259 | }, $index, $attributes, "ck"); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - public function fieldAsDropDown($index, $elements = [], $multiple = false, $attributes = NULL) { |
|
| 263 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
| 264 | - $dd = new HtmlFormDropdown($id, $elements, $caption, $value); |
|
| 262 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 263 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
| 264 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
| 265 | 265 | $dd->asSelect($name, $multiple); |
| 266 | 266 | return $this->_prepareFormFields($dd, $name, $attributes); |
| 267 | 267 | }, $index, $attributes, "dd"); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - public function fieldAsMessage($index, $attributes = NULL) { |
|
| 271 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
| 272 | - $mess = new HtmlMessage("message-" . $id, $caption); |
|
| 270 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
| 271 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 272 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
| 273 | 273 | $mess->addHeader($value); |
| 274 | 274 | return $mess; |
| 275 | 275 | }, $index, $attributes, "message"); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - public function fieldAsLink($index, $attributes = NULL) { |
|
| 279 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
| 280 | - $lnk = new HtmlLink("message-" . $id, "#", $caption); |
|
| 278 | + public function fieldAsLink($index, $attributes=NULL) { |
|
| 279 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
| 280 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
| 281 | 281 | return $lnk; |
| 282 | 282 | }, $index, $attributes, "link"); |
| 283 | 283 | } |
@@ -289,28 +289,28 @@ discard block |
||
| 289 | 289 | * an array or associative array $type=>$attributes |
| 290 | 290 | */ |
| 291 | 291 | public function fieldsAs(array $types) { |
| 292 | - $i = 0; |
|
| 292 | + $i=0; |
|
| 293 | 293 | if (JArray::isAssociative($types)) { |
| 294 | 294 | foreach ($types as $type => $attributes) { |
| 295 | 295 | if (\is_int($type)) |
| 296 | - $this->fieldAs($i ++, $attributes, []); |
|
| 296 | + $this->fieldAs($i++, $attributes, []); |
|
| 297 | 297 | else { |
| 298 | - $type = preg_replace('/\d/', '', $type); |
|
| 299 | - $this->fieldAs($i ++, $type, $attributes); |
|
| 298 | + $type=preg_replace('/\d/', '', $type); |
|
| 299 | + $this->fieldAs($i++, $type, $attributes); |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | } else { |
| 303 | 303 | foreach ($types as $type) { |
| 304 | - $this->fieldAs($i ++, $type); |
|
| 304 | + $this->fieldAs($i++, $type); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - public function fieldAs($index, $type, $attributes = NULL) { |
|
| 310 | - $method = "fieldAs" . \ucfirst($type); |
|
| 309 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
| 310 | + $method="fieldAs".\ucfirst($type); |
|
| 311 | 311 | if (\method_exists($this, $method)) { |
| 312 | - if (! \is_array($attributes)) { |
|
| 313 | - $attributes = [ |
|
| 312 | + if (!\is_array($attributes)) { |
|
| 313 | + $attributes=[ |
|
| 314 | 314 | $index |
| 315 | 315 | ]; |
| 316 | 316 | } else { |
@@ -323,17 +323,17 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - public function fieldAsSubmit($index, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $attributes = NULL) { |
|
| 327 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
| 328 | - $button = new HtmlButton($id, $caption, $cssStyle); |
|
| 326 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 327 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
| 328 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
| 329 | 329 | $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
| 330 | 330 | return $button; |
| 331 | 331 | }, $index, $attributes, "submit"); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - public function fieldAsButton($index, $cssStyle = NULL, $attributes = NULL) { |
|
| 335 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($cssStyle) { |
|
| 336 | - $button = new HtmlButton($id, $value, $cssStyle); |
|
| 334 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 335 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle) { |
|
| 336 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 337 | 337 | return $button; |
| 338 | 338 | }, $index, $attributes, "button"); |
| 339 | 339 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | trait JsUtilsActionsTrait { |
| 14 | 14 | |
| 15 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
| 15 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * show or hide with effect |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | * defers the execution if set to false |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 32 | - $element = Javascript::prep_element ( $element ); |
|
| 33 | - $speed = $this->_validate_speed ( $speed ); |
|
| 34 | - if ($callback != '') { |
|
| 35 | - $callback = ", function(){\n{$callback}\n}"; |
|
| 31 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
| 32 | + $element=Javascript::prep_element($element); |
|
| 33 | + $speed=$this->_validate_speed($speed); |
|
| 34 | + if ($callback!='') { |
|
| 35 | + $callback=", function(){\n{$callback}\n}"; |
|
| 36 | 36 | } |
| 37 | - $str = "$({$element}).{$action}({$speed}{$callback});"; |
|
| 37 | + $str="$({$element}).{$action}({$speed}{$callback});"; |
|
| 38 | 38 | if ($immediatly) |
| 39 | - $this->jquery_code_for_compile [] = $str; |
|
| 39 | + $this->jquery_code_for_compile []=$str; |
|
| 40 | 40 | return $str; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | private function _validate_speed($speed) { |
| 50 | - if (in_array ( $speed, array ( |
|
| 50 | + if (in_array($speed, array( |
|
| 51 | 51 | 'slow', |
| 52 | 52 | 'normal', |
| 53 | 53 | 'fast' |
| 54 | - ) )) { |
|
| 55 | - $speed = '"' . $speed . '"'; |
|
| 56 | - } elseif (preg_match ( "/[^0-9]/", $speed )) { |
|
| 57 | - $speed = ''; |
|
| 54 | + ))) { |
|
| 55 | + $speed='"'.$speed.'"'; |
|
| 56 | + } elseif (preg_match("/[^0-9]/", $speed)) { |
|
| 57 | + $speed=''; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $speed; |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | * @param boolean $immediatly |
| 70 | 70 | * delayed if false |
| 71 | 71 | */ |
| 72 | - public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) { |
|
| 73 | - $element = Javascript::prep_element ( $element ); |
|
| 74 | - if (isset ( $param )) { |
|
| 75 | - $param = Javascript::prep_value ( $param ); |
|
| 76 | - $str = "$({$element}).{$jQueryCall}({$param});"; |
|
| 72 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
| 73 | + $element=Javascript::prep_element($element); |
|
| 74 | + if (isset ($param)) { |
|
| 75 | + $param=Javascript::prep_value($param); |
|
| 76 | + $str="$({$element}).{$jQueryCall}({$param});"; |
|
| 77 | 77 | } else |
| 78 | - $str = "$({$element}).{$jQueryCall}();"; |
|
| 78 | + $str="$({$element}).{$jQueryCall}();"; |
|
| 79 | 79 | if ($immediatly) |
| 80 | - $this->jquery_code_for_compile [] = $str; |
|
| 80 | + $this->jquery_code_for_compile []=$str; |
|
| 81 | 81 | return $str; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | * delayed if false |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) { |
|
| 95 | - $to = Javascript::prep_element ( $to ); |
|
| 96 | - $element = Javascript::prep_element ( $element ); |
|
| 97 | - $str = "$({$to}).{$jQueryCall}({$element});"; |
|
| 94 | + public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) { |
|
| 95 | + $to=Javascript::prep_element($to); |
|
| 96 | + $element=Javascript::prep_element($element); |
|
| 97 | + $str="$({$to}).{$jQueryCall}({$element});"; |
|
| 98 | 98 | if ($immediatly) |
| 99 | - $this->jquery_code_for_compile [] = $str; |
|
| 99 | + $this->jquery_code_for_compile []=$str; |
|
| 100 | 100 | return $str; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | * defers the execution if set to false |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function addClass($element = 'this', $class = '', $immediatly = false) { |
|
| 114 | - return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly ); |
|
| 113 | + public function addClass($element='this', $class='', $immediatly=false) { |
|
| 114 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * defers the execution if set to false |
| 124 | 124 | * @return string |
| 125 | 125 | */ |
| 126 | - public function after($to, $element, $immediatly = false) { |
|
| 127 | - return $this->_genericCallElement ( 'after', $to, $element, $immediatly ); |
|
| 126 | + public function after($to, $element, $immediatly=false) { |
|
| 127 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * defers the execution if set to false |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - public function before($to, $element, $immediatly = false) { |
|
| 140 | - return $this->_genericCallElement ( 'before', $to, $element, $immediatly ); |
|
| 139 | + public function before($to, $element, $immediatly=false) { |
|
| 140 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -149,15 +149,15 @@ discard block |
||
| 149 | 149 | * @param boolean $immediatly |
| 150 | 150 | * delayed if false |
| 151 | 151 | */ |
| 152 | - public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) { |
|
| 153 | - $element = Javascript::prep_element ( $element ); |
|
| 154 | - if (isset ( $value )) { |
|
| 155 | - $value = Javascript::prep_value ( $value ); |
|
| 156 | - $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 152 | + public function attr($element='this', $attributeName='id', $value="", $immediatly=false) { |
|
| 153 | + $element=Javascript::prep_element($element); |
|
| 154 | + if (isset ($value)) { |
|
| 155 | + $value=Javascript::prep_value($value); |
|
| 156 | + $str="$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 157 | 157 | } else |
| 158 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
| 158 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
| 159 | 159 | if ($immediatly) |
| 160 | - $this->jquery_code_for_compile [] = $str; |
|
| 160 | + $this->jquery_code_for_compile []=$str; |
|
| 161 | 161 | return $str; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * @param boolean $immediatly |
| 170 | 170 | * defers the execution if set to false |
| 171 | 171 | */ |
| 172 | - public function val($element = 'this', $value = '', $immediatly = false) { |
|
| 173 | - return $this->_genericCallValue ( 'val', $element, $value, $immediatly ); |
|
| 172 | + public function val($element='this', $value='', $immediatly=false) { |
|
| 173 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param boolean $immediatly |
| 182 | 182 | * defers the execution if set to false |
| 183 | 183 | */ |
| 184 | - public function html($element = 'this', $value = '', $immediatly = false) { |
|
| 185 | - return $this->_genericCallValue ( 'html', $element, $value, $immediatly ); |
|
| 184 | + public function html($element='this', $value='', $immediatly=false) { |
|
| 185 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -198,30 +198,30 @@ discard block |
||
| 198 | 198 | * defers the execution if set to false |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) { |
|
| 202 | - $element = Javascript::prep_element ( $element ); |
|
| 203 | - $speed = $this->_validate_speed ( $speed ); |
|
| 201 | + public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
|
| 202 | + $element=Javascript::prep_element($element); |
|
| 203 | + $speed=$this->_validate_speed($speed); |
|
| 204 | 204 | |
| 205 | - $animations = "\t\t\t"; |
|
| 206 | - if (\is_array ( $params )) { |
|
| 207 | - foreach ( $params as $param => $value ) { |
|
| 208 | - $animations .= $param . ': \'' . $value . '\', '; |
|
| 205 | + $animations="\t\t\t"; |
|
| 206 | + if (\is_array($params)) { |
|
| 207 | + foreach ($params as $param => $value) { |
|
| 208 | + $animations.=$param.': \''.$value.'\', '; |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | - $animations = substr ( $animations, 0, - 2 ); // remove the last ", " |
|
| 211 | + $animations=substr($animations, 0, - 2); // remove the last ", " |
|
| 212 | 212 | |
| 213 | - if ($speed != '') { |
|
| 214 | - $speed = ', ' . $speed; |
|
| 213 | + if ($speed!='') { |
|
| 214 | + $speed=', '.$speed; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ($extra != '') { |
|
| 218 | - $extra = ', ' . $extra; |
|
| 217 | + if ($extra!='') { |
|
| 218 | + $extra=', '.$extra; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
|
| 221 | + $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
|
| 222 | 222 | |
| 223 | 223 | if ($immediatly) |
| 224 | - $this->jquery_code_for_compile [] = $str; |
|
| 224 | + $this->jquery_code_for_compile []=$str; |
|
| 225 | 225 | return $str; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * defers the execution if set to false |
| 235 | 235 | * @return string |
| 236 | 236 | */ |
| 237 | - public function append($to, $element, $immediatly = false) { |
|
| 238 | - return $this->_genericCallElement ( 'append', $to, $element, $immediatly ); |
|
| 237 | + public function append($to, $element, $immediatly=false) { |
|
| 238 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * defers the execution if set to false |
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | - public function prepend($to, $element, $immediatly = false) { |
|
| 251 | - return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly ); |
|
| 250 | + public function prepend($to, $element, $immediatly=false) { |
|
| 251 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | * defers the execution if set to false |
| 265 | 265 | * @return string |
| 266 | 266 | */ |
| 267 | - public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 268 | - return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly ); |
|
| 267 | + public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 268 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * defers the execution if set to false |
| 282 | 282 | * @return string |
| 283 | 283 | */ |
| 284 | - public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 285 | - return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly ); |
|
| 284 | + public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 285 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * defers the execution if set to false |
| 299 | 299 | * @return string |
| 300 | 300 | */ |
| 301 | - public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 302 | - return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly ); |
|
| 301 | + public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 302 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | * defers the execution if set to false |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - public function removeClass($element = 'this', $class = '', $immediatly = false) { |
|
| 317 | - return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly ); |
|
| 316 | + public function removeClass($element='this', $class='', $immediatly=false) { |
|
| 317 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | * defers the execution if set to false |
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | - public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 334 | - return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly ); |
|
| 333 | + public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 334 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * defers the execution if set to false |
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | - public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 351 | - return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly ); |
|
| 350 | + public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 351 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * defers the execution if set to false |
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | - public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 368 | - return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly ); |
|
| 367 | + public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 368 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * defers the execution if set to false |
| 382 | 382 | * @return string |
| 383 | 383 | */ |
| 384 | - public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 385 | - return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly ); |
|
| 384 | + public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 385 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * defers the execution if set to false |
| 396 | 396 | * @return string |
| 397 | 397 | */ |
| 398 | - public function toggleClass($element = 'this', $class = '', $immediatly = false) { |
|
| 399 | - return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly ); |
|
| 398 | + public function toggleClass($element='this', $class='', $immediatly=false) { |
|
| 399 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -407,12 +407,12 @@ discard block |
||
| 407 | 407 | * @param boolean $immediatly |
| 408 | 408 | * defers the execution if set to false |
| 409 | 409 | */ |
| 410 | - public function trigger($element = 'this', $event = 'click', $immediatly = false) { |
|
| 411 | - $element = Javascript::prep_element ( $element ); |
|
| 412 | - $str = "$({$element}).trigger(\"$event\");"; |
|
| 410 | + public function trigger($element='this', $event='click', $immediatly=false) { |
|
| 411 | + $element=Javascript::prep_element($element); |
|
| 412 | + $str="$({$element}).trigger(\"$event\");"; |
|
| 413 | 413 | |
| 414 | 414 | if ($immediatly) |
| 415 | - $this->jquery_code_for_compile [] = $str; |
|
| 415 | + $this->jquery_code_for_compile []=$str; |
|
| 416 | 416 | return $str; |
| 417 | 417 | } |
| 418 | 418 | |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * defers the execution if set to false |
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | - public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 433 | - return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly ); |
|
| 432 | + public function show($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 433 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -440,18 +440,18 @@ discard block |
||
| 440 | 440 | * @param array $options |
| 441 | 441 | * @return string |
| 442 | 442 | */ |
| 443 | - public function sortable($element, $options = array ()) { |
|
| 444 | - if (count ( $options ) > 0) { |
|
| 445 | - $sort_options = array (); |
|
| 446 | - foreach ( $options as $k => $v ) { |
|
| 447 | - $sort_options [] = "\n\t\t" . $k . ': ' . $v . ""; |
|
| 443 | + public function sortable($element, $options=array()) { |
|
| 444 | + if (count($options)>0) { |
|
| 445 | + $sort_options=array(); |
|
| 446 | + foreach ($options as $k => $v) { |
|
| 447 | + $sort_options []="\n\t\t".$k.': '.$v.""; |
|
| 448 | 448 | } |
| 449 | - $sort_options = implode ( ",", $sort_options ); |
|
| 449 | + $sort_options=implode(",", $sort_options); |
|
| 450 | 450 | } else { |
| 451 | - $sort_options = ''; |
|
| 451 | + $sort_options=''; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});"; |
|
| 454 | + return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});"; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | * plugin location |
| 464 | 464 | * @return string |
| 465 | 465 | */ |
| 466 | - public function tablesorter($table = '', $options = '') { |
|
| 467 | - $this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n"; |
|
| 466 | + public function tablesorter($table='', $options='') { |
|
| 467 | + $this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n"; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -476,14 +476,14 @@ discard block |
||
| 476 | 476 | * @param boolean $immediatly |
| 477 | 477 | * defers the execution if set to false |
| 478 | 478 | */ |
| 479 | - public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) { |
|
| 480 | - $str = "if(" . $condition . "){" . $jsCodeIfTrue . "}"; |
|
| 481 | - if (isset ( $jsCodeIfFalse )) { |
|
| 482 | - $str .= "else{" . $jsCodeIfFalse . "}"; |
|
| 479 | + public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
|
| 480 | + $str="if(".$condition."){".$jsCodeIfTrue."}"; |
|
| 481 | + if (isset ($jsCodeIfFalse)) { |
|
| 482 | + $str.="else{".$jsCodeIfFalse."}"; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | if ($immediatly) |
| 486 | - $this->jquery_code_for_compile [] = $str; |
|
| 486 | + $this->jquery_code_for_compile []=$str; |
|
| 487 | 487 | return $str; |
| 488 | 488 | } |
| 489 | 489 | |
@@ -498,14 +498,14 @@ discard block |
||
| 498 | 498 | * @param boolean $immediatly |
| 499 | 499 | * @return string |
| 500 | 500 | */ |
| 501 | - private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
|
| 502 | - $param = Javascript::prep_value ( $param ); |
|
| 503 | - $callback = ""; |
|
| 504 | - if ($jsCallback != "") |
|
| 505 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
| 506 | - $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
|
| 501 | + private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
|
| 502 | + $param=Javascript::prep_value($param); |
|
| 503 | + $callback=""; |
|
| 504 | + if ($jsCallback!="") |
|
| 505 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
| 506 | + $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
|
| 507 | 507 | if ($immediatly) |
| 508 | - $this->jquery_code_for_compile [] = $script; |
|
| 508 | + $this->jquery_code_for_compile []=$script; |
|
| 509 | 509 | return $script; |
| 510 | 510 | } |
| 511 | 511 | |
@@ -522,8 +522,8 @@ discard block |
||
| 522 | 522 | * javascript code to execute after the jquery call |
| 523 | 523 | * @return mixed |
| 524 | 524 | */ |
| 525 | - public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 526 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true ); |
|
| 525 | + public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 526 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * javascript code to execute after the jquery call |
| 540 | 540 | * @return mixed |
| 541 | 541 | */ |
| 542 | - public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 543 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false ); |
|
| 542 | + public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 543 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -557,8 +557,8 @@ discard block |
||
| 557 | 557 | * @param boolean $immediatly |
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) { |
|
| 561 | - return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 560 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
| 561 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | * @param array $parameters |
| 573 | 573 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
| 574 | 574 | */ |
| 575 | - public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) { |
|
| 576 | - $jsCallback = ""; |
|
| 577 | - $stopPropagation = false; |
|
| 578 | - $preventDefault = false; |
|
| 579 | - $immediatly = true; |
|
| 580 | - extract ( $parameters ); |
|
| 581 | - return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly ); |
|
| 575 | + public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
| 576 | + $jsCallback=""; |
|
| 577 | + $stopPropagation=false; |
|
| 578 | + $preventDefault=false; |
|
| 579 | + $immediatly=true; |
|
| 580 | + extract($parameters); |
|
| 581 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * delayed if false |
| 591 | 591 | * @return String |
| 592 | 592 | */ |
| 593 | - public function exec($js, $immediatly = false) { |
|
| 594 | - $script = $js . "\n"; |
|
| 593 | + public function exec($js, $immediatly=false) { |
|
| 594 | + $script=$js."\n"; |
|
| 595 | 595 | if ($immediatly) |
| 596 | - $this->jquery_code_for_compile [] = $script; |
|
| 596 | + $this->jquery_code_for_compile []=$script; |
|
| 597 | 597 | return $script; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -607,8 +607,8 @@ discard block |
||
| 607 | 607 | * @return String |
| 608 | 608 | */ |
| 609 | 609 | public function execAtLast($js) { |
| 610 | - $script = $js . "\n"; |
|
| 611 | - $this->jquery_code_for_compile_at_last [] = $script; |
|
| 610 | + $script=$js."\n"; |
|
| 611 | + $this->jquery_code_for_compile_at_last []=$script; |
|
| 612 | 612 | return $script; |
| 613 | 613 | } |
| 614 | 614 | |
@@ -623,18 +623,18 @@ discard block |
||
| 623 | 623 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 624 | 624 | * @return String |
| 625 | 625 | */ |
| 626 | - public function execOn($event, $element, $js, $parameters = array ()) { |
|
| 627 | - $stopPropagation = false; |
|
| 628 | - $preventDefault = false; |
|
| 629 | - $immediatly = true; |
|
| 630 | - extract ( $parameters ); |
|
| 631 | - $script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 626 | + public function execOn($event, $element, $js, $parameters=array()) { |
|
| 627 | + $stopPropagation=false; |
|
| 628 | + $preventDefault=false; |
|
| 629 | + $immediatly=true; |
|
| 630 | + extract($parameters); |
|
| 631 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 632 | 632 | return $script; |
| 633 | 633 | } |
| 634 | - public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) { |
|
| 635 | - $retour = "var data={$json};" . "\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);" . "\n\tvar pk=data['pk'];var object=data['object'];" . "\n\tfor(var field in object){" . "\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){" . "\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){" . "\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }" . "\n\t});" . "\n}};\n"; |
|
| 636 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 637 | - return $this->exec ( $retour, $immediatly ); |
|
| 634 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
| 635 | + $retour="var data={$json};"."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);"."\n\tvar pk=data['pk'];var object=data['object'];"."\n\tfor(var field in object){"."\n\tif($('[data-field='+field+']',$('._element[data-ajax='+pk+']')).length){"."\n\t\t$('[data-field='+field+']',$('._element[data-ajax='+pk+']')).each(function(){"."\n\t\t\tif($(this).is('[value]')) { $(this).val(object[field]);} else { $(this).html(object[field]); }"."\n\t});"."\n}};\n"; |
|
| 636 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 637 | + return $this->exec($retour, $immediatly); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -645,13 +645,13 @@ discard block |
||
| 645 | 645 | * @param array $parameters |
| 646 | 646 | * default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 647 | 647 | */ |
| 648 | - public function setDraggable($element, $parameters = [ ]) { |
|
| 649 | - $attr = "id"; |
|
| 650 | - $preventDefault = false; |
|
| 651 | - $stopPropagation = false; |
|
| 652 | - $immediatly = true; |
|
| 653 | - extract ( $parameters ); |
|
| 654 | - $script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly ); |
|
| 648 | + public function setDraggable($element, $parameters=[]) { |
|
| 649 | + $attr="id"; |
|
| 650 | + $preventDefault=false; |
|
| 651 | + $stopPropagation=false; |
|
| 652 | + $immediatly=true; |
|
| 653 | + extract($parameters); |
|
| 654 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly); |
|
| 655 | 655 | return $script; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -665,13 +665,13 @@ discard block |
||
| 665 | 665 | * @param string $jsCallback |
| 666 | 666 | * the js script to call when element is dropped |
| 667 | 667 | */ |
| 668 | - public function asDropZone($element, $jsCallback = "", $parameters = [ ]) { |
|
| 669 | - $stopPropagation = false; |
|
| 670 | - $immediatly = true; |
|
| 671 | - $jqueryDone = "append"; |
|
| 672 | - $script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly ); |
|
| 673 | - extract ( $parameters ); |
|
| 674 | - $script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly ); |
|
| 668 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
| 669 | + $stopPropagation=false; |
|
| 670 | + $immediatly=true; |
|
| 671 | + $jqueryDone="append"; |
|
| 672 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
| 673 | + extract($parameters); |
|
| 674 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
| 675 | 675 | return $script; |
| 676 | 676 | } |
| 677 | 677 | |
@@ -688,16 +688,16 @@ discard block |
||
| 688 | 688 | * delayed if false |
| 689 | 689 | * @return string |
| 690 | 690 | */ |
| 691 | - public function interval($jsCode, $time, $globalName = null, $immediatly = true) { |
|
| 692 | - if (! Javascript::isFunction ( $jsCode )) { |
|
| 693 | - $jsCode = "function(){\n" . $jsCode . "\n}"; |
|
| 691 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
| 692 | + if (!Javascript::isFunction($jsCode)) { |
|
| 693 | + $jsCode="function(){\n".$jsCode."\n}"; |
|
| 694 | 694 | } |
| 695 | - if (isset ( $globalName )) { |
|
| 696 | - $script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 695 | + if (isset ($globalName)) { |
|
| 696 | + $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 697 | 697 | } else { |
| 698 | - $script = "setInterval({$jsCode},{$time});"; |
|
| 698 | + $script="setInterval({$jsCode},{$time});"; |
|
| 699 | 699 | } |
| 700 | - return $this->exec ( $script, $immediatly ); |
|
| 700 | + return $this->exec($script, $immediatly); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -709,8 +709,8 @@ discard block |
||
| 709 | 709 | * delayed if false |
| 710 | 710 | * @return string |
| 711 | 711 | */ |
| 712 | - public function clearInterval($globalName, $immediatly = true) { |
|
| 713 | - return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly ); |
|
| 712 | + public function clearInterval($globalName, $immediatly=true) { |
|
| 713 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -731,20 +731,20 @@ discard block |
||
| 731 | 731 | * delayed if false |
| 732 | 732 | * @return string |
| 733 | 733 | */ |
| 734 | - public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) { |
|
| 735 | - $stop = ""; |
|
| 734 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
| 735 | + $stop=""; |
|
| 736 | 736 | if ($countDown) { |
| 737 | - $stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 737 | + $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 738 | 738 | } else { |
| 739 | - if ($limit != 0) { |
|
| 740 | - $stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 739 | + if ($limit!=0) { |
|
| 740 | + $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | - $global = ""; |
|
| 744 | - if (isset ( $globalName )) { |
|
| 745 | - $global = "\nwindow.{$globalName}=interval;"; |
|
| 743 | + $global=""; |
|
| 744 | + if (isset ($globalName)) { |
|
| 745 | + $global="\nwindow.{$globalName}=interval;"; |
|
| 746 | 746 | } |
| 747 | - $timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 747 | + $timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 748 | 748 | var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};}; |
| 749 | 749 | var shHide=function(v,k,kBefore){if(v==0 && display.find(k).closest('.timer').is(':visible') && (!kBefore || !display.find(kBefore).closest('.timer').is(':visible'))){display.find(k).closest('.timer').hide();}else{sh(display.find(k),v);}}; |
| 750 | 750 | var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';}; |
@@ -760,12 +760,12 @@ discard block |
||
| 760 | 760 | minutes = d0(parseInt((timer%3600) / 60, 10)); |
| 761 | 761 | seconds = d0(parseInt(timer%60, 10)); |
| 762 | 762 | mainSh(days,hours,minutes,seconds); |
| 763 | - " . $stop . " |
|
| 763 | + " . $stop." |
|
| 764 | 764 | }, 1000); |
| 765 | - " . $global . " |
|
| 765 | + " . $global." |
|
| 766 | 766 | }"; |
| 767 | - $element = '$("' . $counterSelector . '")'; |
|
| 768 | - return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly ); |
|
| 767 | + $element='$("'.$counterSelector.'")'; |
|
| 768 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -787,8 +787,8 @@ discard block |
||
| 787 | 787 | * count down if true or elapse if false |
| 788 | 788 | * @return string |
| 789 | 789 | */ |
| 790 | - public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) { |
|
| 791 | - return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) ); |
|
| 790 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
| 791 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
@@ -802,8 +802,8 @@ discard block |
||
| 802 | 802 | * the active href (if null, window.location.href is used) |
| 803 | 803 | * @return string |
| 804 | 804 | */ |
| 805 | - public function activateLink($target, $property = 'href', $href = null) { |
|
| 806 | - return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) ); |
|
| 805 | + public function activateLink($target, $property='href', $href=null) { |
|
| 806 | + return $this->execAtLast($this->_activateLink($target, $property, $href)); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -817,14 +817,14 @@ discard block |
||
| 817 | 817 | * the active href (if null, window.location.href is used) |
| 818 | 818 | * @return string |
| 819 | 819 | */ |
| 820 | - public function _activateLink($target, $property = 'href', $href = null) { |
|
| 821 | - $js = '$("' . $target . ' [' . $property . ']").removeClass("active");'; |
|
| 822 | - if (isset ( $href )) { |
|
| 823 | - $js .= 'var href="' . $href . '";'; |
|
| 820 | + public function _activateLink($target, $property='href', $href=null) { |
|
| 821 | + $js='$("'.$target.' ['.$property.']").removeClass("active");'; |
|
| 822 | + if (isset ($href)) { |
|
| 823 | + $js.='var href="'.$href.'";'; |
|
| 824 | 824 | } else { |
| 825 | - $js .= 'var href=window.location.href;'; |
|
| 825 | + $js.='var href=window.location.href;'; |
|
| 826 | 826 | } |
| 827 | - $js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});'; |
|
| 827 | + $js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});'; |
|
| 828 | 828 | return $js; |
| 829 | 829 | } |
| 830 | 830 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @property array $jquery_code_for_compile |
| 11 | 11 | */ |
| 12 | 12 | trait JsUtilsEventsTrait { |
| 13 | - protected $jquery_events = [ |
|
| 13 | + protected $jquery_events=[ |
|
| 14 | 14 | 'bind', |
| 15 | 15 | 'blur', |
| 16 | 16 | 'change', |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | 'unload' |
| 52 | 52 | ]; |
| 53 | 53 | |
| 54 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
| 54 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Outputs a javascript library blur event |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * code to execute |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - public function blur($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 66 | - return $this->_add_event ( $element, $js, 'blur', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 65 | + public function blur($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 66 | + return $this->_add_event($element, $js, 'blur', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - public function change($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 82 | - return $this->_add_event ( $element, $js, 'change', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 81 | + public function change($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 82 | + return $this->_add_event($element, $js, 'change', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -96,18 +96,18 @@ discard block |
||
| 96 | 96 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - public function click($element = 'this', $js = '', $ret_false = TRUE, $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 100 | - if (! is_array ( $js )) { |
|
| 101 | - $js = array ( |
|
| 99 | + public function click($element='this', $js='', $ret_false=TRUE, $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 100 | + if (!is_array($js)) { |
|
| 101 | + $js=array( |
|
| 102 | 102 | $js |
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | if ($ret_false) { |
| 107 | - $js [] = "return false;"; |
|
| 107 | + $js []="return false;"; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return $this->_add_event ( $element, $js, 'click', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 110 | + return $this->_add_event($element, $js, 'click', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - public function contextmenu($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 126 | - return $this->_add_event ( $element, $js, 'contextmenu', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 125 | + public function contextmenu($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 126 | + return $this->_add_event($element, $js, 'contextmenu', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - public function dblclick($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 142 | - return $this->_add_event ( $element, $js, 'dblclick', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 141 | + public function dblclick($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 142 | + return $this->_add_event($element, $js, 'dblclick', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * code to execute |
| 152 | 152 | * @return string |
| 153 | 153 | */ |
| 154 | - public function error($element = 'this', $js = '') { |
|
| 155 | - return $this->_add_event ( $element, $js, 'error' ); |
|
| 154 | + public function error($element='this', $js='') { |
|
| 155 | + return $this->_add_event($element, $js, 'error'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | - public function focus($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 171 | - return $this->_add_event ( $element, $js, 'focus', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 170 | + public function focus($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 171 | + return $this->_add_event($element, $js, 'focus', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | * code for mouse out |
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | - public function hover($element = 'this', $over = '', $out = '') { |
|
| 185 | - $event = "\n\t$(" . Javascript::prep_element ( $element ) . ").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
|
| 186 | - $this->jquery_code_for_compile [] = $event; |
|
| 184 | + public function hover($element='this', $over='', $out='') { |
|
| 185 | + $event="\n\t$(".Javascript::prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; |
|
| 186 | + $this->jquery_code_for_compile []=$event; |
|
| 187 | 187 | return $event; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function keydown($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 203 | - return $this->_add_event ( $element, $js, 'keydown', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 202 | + public function keydown($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 203 | + return $this->_add_event($element, $js, 'keydown', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function keypress($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 219 | - return $this->_add_event ( $element, $js, 'keypress', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 218 | + public function keypress($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 219 | + return $this->_add_event($element, $js, 'keypress', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 232 | 232 | * @return string |
| 233 | 233 | */ |
| 234 | - public function keyup($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 235 | - return $this->_add_event ( $element, $js, 'keyup', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 234 | + public function keyup($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 235 | + return $this->_add_event($element, $js, 'keyup', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | - public function load($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 251 | - return $this->_add_event ( $element, $js, 'load', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 250 | + public function load($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 251 | + return $this->_add_event($element, $js, 'load', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 264 | 264 | * @return string |
| 265 | 265 | */ |
| 266 | - public function mousedown($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 267 | - return $this->_add_event ( $element, $js, 'mousedown', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 266 | + public function mousedown($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 267 | + return $this->_add_event($element, $js, 'mousedown', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | - public function mouseout($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 283 | - return $this->_add_event ( $element, $js, 'mouseout', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 282 | + public function mouseout($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 283 | + return $this->_add_event($element, $js, 'mouseout', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 296 | 296 | * @return string |
| 297 | 297 | */ |
| 298 | - public function mouseleave($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 299 | - return $this->_add_event ( $element, $js, 'mouseleave', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 298 | + public function mouseleave($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 299 | + return $this->_add_event($element, $js, 'mouseleave', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 312 | 312 | * @return string |
| 313 | 313 | */ |
| 314 | - public function mouseenter($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 315 | - return $this->_add_event ( $element, $js, 'mouseenter', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 314 | + public function mouseenter($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 315 | + return $this->_add_event($element, $js, 'mouseenter', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | - public function mouseover($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 331 | - return $this->_add_event ( $element, $js, 'mouseover', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 330 | + public function mouseover($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 331 | + return $this->_add_event($element, $js, 'mouseover', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function mouseup($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 347 | - return $this->_add_event ( $element, $js, 'mouseup', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 346 | + public function mouseup($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 347 | + return $this->_add_event($element, $js, 'mouseup', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 360 | 360 | * @return string |
| 361 | 361 | */ |
| 362 | - public function unload($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 363 | - return $this->_add_event ( $element, $js, 'unload', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 362 | + public function unload($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 363 | + return $this->_add_event($element, $js, 'unload', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // -------------------------------------------------------------------- |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function resize($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 380 | - return $this->_add_event ( $element, $js, 'resize', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 379 | + public function resize($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 380 | + return $this->_add_event($element, $js, 'resize', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // -------------------------------------------------------------------- |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @param boolean|string $listenerOn use a selector for a delegated event handler |
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | - public function scroll($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false, $listenerOn=false) { |
|
| 397 | - return $this->_add_event ( $element, $js, 'scroll', $preventDefault, $stopPropagation, true, $listenerOn ); |
|
| 396 | + public function scroll($element='this', $js='', $preventDefault=false, $stopPropagation=false, $listenerOn=false) { |
|
| 397 | + return $this->_add_event($element, $js, 'scroll', $preventDefault, $stopPropagation, true, $listenerOn); |
|
| 398 | 398 | } |
| 399 | 399 | } |
@@ -14,215 +14,215 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | trait JsUtilsAjaxTrait { |
| 16 | 16 | protected $ajaxTransition; |
| 17 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 17 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 18 | 18 | abstract public function getUrl($url); |
| 19 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
| 20 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 21 | - |
|
| 22 | - protected function _ajax($method, $url, $responseElement = '', $parameters = [ ]) { |
|
| 23 | - if (isset ( $this->params ['ajax'] )) { |
|
| 24 | - extract ( $this->params ['ajax'] ); |
|
| 25 | - } |
|
| 26 | - extract ( $parameters ); |
|
| 27 | - |
|
| 28 | - $jsCallback = isset ( $jsCallback ) ? $jsCallback : ''; |
|
| 29 | - $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
| 30 | - $originalSelector = $responseElement; |
|
| 31 | - $responseElement = $this->_getResponseElement ( $responseElement ); |
|
| 32 | - $retour .= "var self=this;\n"; |
|
| 33 | - $before = isset ( $before ) ? $before : ""; |
|
| 34 | - $retour .= $before; |
|
| 35 | - if ($hasLoader === true && JString::isNotNull ( $responseElement )) { |
|
| 36 | - $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 37 | - } elseif ($hasLoader === 'response') { |
|
| 38 | - $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 39 | - } elseif ($hasLoader === 'internal') { |
|
| 40 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 41 | - } |
|
| 42 | - $ajaxParameters = [ |
|
| 19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 20 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 21 | + |
|
| 22 | + protected function _ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 23 | + if (isset ($this->params ['ajax'])) { |
|
| 24 | + extract($this->params ['ajax']); |
|
| 25 | + } |
|
| 26 | + extract($parameters); |
|
| 27 | + |
|
| 28 | + $jsCallback=isset ($jsCallback) ? $jsCallback : ''; |
|
| 29 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 30 | + $originalSelector=$responseElement; |
|
| 31 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 32 | + $retour.="var self=this;\n"; |
|
| 33 | + $before=isset ($before) ? $before : ""; |
|
| 34 | + $retour.=$before; |
|
| 35 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 36 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 37 | + } elseif ($hasLoader==='response') { |
|
| 38 | + $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
| 39 | + } elseif ($hasLoader==='internal') { |
|
| 40 | + $retour.="\n$(this).addClass('loading');"; |
|
| 41 | + } |
|
| 42 | + $ajaxParameters=[ |
|
| 43 | 43 | "url" => "url", |
| 44 | - "method" => "'" . \strtoupper ( $method ) . "'" |
|
| 44 | + "method" => "'".\strtoupper($method)."'" |
|
| 45 | 45 | ]; |
| 46 | 46 | |
| 47 | - $ajaxParameters ["async"] = ($async ? "true" : "false"); |
|
| 47 | + $ajaxParameters ["async"]=($async ? "true" : "false"); |
|
| 48 | 48 | |
| 49 | - if (isset ( $params )) { |
|
| 50 | - $ajaxParameters ["data"] = self::_correctParams ( $params, $parameters ); |
|
| 49 | + if (isset ($params)) { |
|
| 50 | + $ajaxParameters ["data"]=self::_correctParams($params, $parameters); |
|
| 51 | 51 | } |
| 52 | - if (isset ( $headers )) { |
|
| 53 | - $ajaxParameters ["headers"] = $headers; |
|
| 52 | + if (isset ($headers)) { |
|
| 53 | + $ajaxParameters ["headers"]=$headers; |
|
| 54 | 54 | } |
| 55 | 55 | if ($csrf) { |
| 56 | - $csrf=(is_string($csrf))?$csrf:'csrf-token'; |
|
| 57 | - $parameters ["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 56 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 57 | + $parameters ["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 58 | 58 | } |
| 59 | - if (isset ( $partial )) { |
|
| 60 | - $ajaxParameters ["xhr"] = "xhrProvider"; |
|
| 61 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 59 | + if (isset ($partial)) { |
|
| 60 | + $ajaxParameters ["xhr"]="xhrProvider"; |
|
| 61 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 62 | 62 | } |
| 63 | - $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
| 64 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 65 | - $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n"; |
|
| 63 | + $this->createAjaxParameters($ajaxParameters, $parameters); |
|
| 64 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 65 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 66 | 66 | |
| 67 | - $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
| 67 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 68 | 68 | if ($immediatly) |
| 69 | - $this->jquery_code_for_compile [] = $retour; |
|
| 69 | + $this->jquery_code_for_compile []=$retour; |
|
| 70 | 70 | return $retour; |
| 71 | 71 | } |
| 72 | 72 | protected function createAjaxParameters(&$original, $parameters) { |
| 73 | - $validParameters = [ |
|
| 73 | + $validParameters=[ |
|
| 74 | 74 | "contentType" => "%value%", |
| 75 | 75 | "dataType" => "'%value%'", |
| 76 | 76 | "beforeSend" => "function(jqXHR,settings){%value%}", |
| 77 | 77 | "complete" => "function(jqXHR){%value%}", |
| 78 | 78 | "processData" => "%value%" |
| 79 | 79 | ]; |
| 80 | - foreach ( $validParameters as $param => $mask ) { |
|
| 81 | - if (isset ( $parameters [$param] )) { |
|
| 82 | - $original [$param] = \str_replace ( "%value%", $parameters [$param], $mask ); |
|
| 80 | + foreach ($validParameters as $param => $mask) { |
|
| 81 | + if (isset ($parameters [$param])) { |
|
| 82 | + $original [$param]=\str_replace("%value%", $parameters [$param], $mask); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | protected function implodeAjaxParameters($ajaxParameters) { |
| 87 | - $s = ''; |
|
| 88 | - foreach ( $ajaxParameters as $k => $v ) { |
|
| 89 | - if ($s !== '') { |
|
| 90 | - $s .= ','; |
|
| 87 | + $s=''; |
|
| 88 | + foreach ($ajaxParameters as $k => $v) { |
|
| 89 | + if ($s!=='') { |
|
| 90 | + $s.=','; |
|
| 91 | 91 | } |
| 92 | - if (is_array ( $v )) { |
|
| 93 | - $s .= "'{$k}':{" . self::implodeAjaxParameters ( $v ) . "}"; |
|
| 92 | + if (is_array($v)) { |
|
| 93 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 94 | 94 | } else { |
| 95 | - $s .= "'{$k}':{$v}"; |
|
| 95 | + $s.="'{$k}':{$v}"; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | return $s; |
| 99 | 99 | } |
| 100 | 100 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 101 | - if (isset ( $jsCondition )) { |
|
| 102 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 101 | + if (isset ($jsCondition)) { |
|
| 102 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 103 | 103 | } |
| 104 | 104 | return $jsSource; |
| 105 | 105 | } |
| 106 | 106 | protected function _getAjaxUrl($url, $attr) { |
| 107 | - $url = $this->_correctAjaxUrl ( $url ); |
|
| 108 | - $retour = "url='" . $url . "';"; |
|
| 109 | - $slash = "/"; |
|
| 110 | - if (JString::endswith ( $url, "/" ) === true) { |
|
| 111 | - $slash = ""; |
|
| 112 | - } |
|
| 113 | - if (JString::isNotNull ( $attr )) { |
|
| 114 | - if ($attr === "value") { |
|
| 115 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 116 | - } elseif ($attr === "html") { |
|
| 117 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 118 | - } elseif (\substr ( $attr, 0, 3 ) === "js:") { |
|
| 119 | - $retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n"; |
|
| 120 | - } elseif ($attr !== null && $attr !== "") |
|
| 121 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 107 | + $url=$this->_correctAjaxUrl($url); |
|
| 108 | + $retour="url='".$url."';"; |
|
| 109 | + $slash="/"; |
|
| 110 | + if (JString::endswith($url, "/")===true) { |
|
| 111 | + $slash=""; |
|
| 112 | + } |
|
| 113 | + if (JString::isNotNull($attr)) { |
|
| 114 | + if ($attr==="value") { |
|
| 115 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 116 | + } elseif ($attr==="html") { |
|
| 117 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 118 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 119 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 120 | + } elseif ($attr!==null && $attr!=="") |
|
| 121 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 122 | 122 | } |
| 123 | 123 | return $retour; |
| 124 | 124 | } |
| 125 | 125 | protected function onPopstate() { |
| 126 | 126 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 127 | 127 | } |
| 128 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 129 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 130 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 128 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 129 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 130 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 131 | 131 | return $result; |
| 132 | 132 | } |
| 133 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 134 | - $retour = ""; |
|
| 135 | - $call = null; |
|
| 136 | - if (JString::isNotNull ( $responseElement )) { |
|
| 137 | - if (isset ( $ajaxTransition )) { |
|
| 138 | - $call = $this->setAjaxDataCall ( $ajaxTransition ); |
|
| 139 | - } elseif (isset ( $this->ajaxTransition )) { |
|
| 140 | - $call = $this->ajaxTransition; |
|
| 133 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 134 | + $retour=""; |
|
| 135 | + $call=null; |
|
| 136 | + if (JString::isNotNull($responseElement)) { |
|
| 137 | + if (isset ($ajaxTransition)) { |
|
| 138 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 139 | + } elseif (isset ($this->ajaxTransition)) { |
|
| 140 | + $call=$this->ajaxTransition; |
|
| 141 | 141 | } |
| 142 | - if (\is_callable ( $call )) |
|
| 143 | - $retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n"; |
|
| 142 | + if (\is_callable($call)) |
|
| 143 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 144 | 144 | else |
| 145 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 145 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 146 | 146 | } |
| 147 | - if (isset ( $history )) { |
|
| 147 | + if (isset ($history)) { |
|
| 148 | 148 | if ($this->params ["autoActiveLinks"]) { |
| 149 | - $retour .= $this->autoActiveLinks ( "url" ); |
|
| 149 | + $retour.=$this->autoActiveLinks("url"); |
|
| 150 | 150 | } |
| 151 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value ( $history ) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 151 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 152 | 152 | } |
| 153 | - if ($hasLoader === 'internal') { |
|
| 154 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 153 | + if ($hasLoader==='internal') { |
|
| 154 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 155 | 155 | } |
| 156 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 156 | + $retour.="\t".$jsCallback."\n"; |
|
| 157 | 157 | return $retour; |
| 158 | 158 | } |
| 159 | 159 | protected function _getResponseElement($responseElement) { |
| 160 | - if (JString::isNotNull ( $responseElement )) { |
|
| 161 | - $responseElement = Javascript::prep_jquery_selector ( $responseElement ); |
|
| 160 | + if (JString::isNotNull($responseElement)) { |
|
| 161 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 162 | 162 | } |
| 163 | 163 | return $responseElement; |
| 164 | 164 | } |
| 165 | 165 | protected function _correctAjaxUrl($url) { |
| 166 | - if ($url !== "/" && JString::endsWith ( $url, "/" ) === true) |
|
| 167 | - $url = substr ( $url, 0, strlen ( $url ) - 1 ); |
|
| 168 | - if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) { |
|
| 169 | - $url = $this->getUrl ( $url ); |
|
| 166 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 167 | + $url=substr($url, 0, strlen($url)-1); |
|
| 168 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 169 | + $url=$this->getUrl($url); |
|
| 170 | 170 | } |
| 171 | 171 | return $url; |
| 172 | 172 | } |
| 173 | - public static function _correctParams($params, $ajaxParameters = [ ]) { |
|
| 174 | - if (JString::isNull ( $params )) { |
|
| 173 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 174 | + if (JString::isNull($params)) { |
|
| 175 | 175 | return ""; |
| 176 | 176 | } |
| 177 | - if (\preg_match ( "@^\{.*?\}$@", $params )) { |
|
| 178 | - if (! isset ( $ajaxParameters ['contentType'] ) || ! JString::contains ( $ajaxParameters ['contentType'], 'json' )) { |
|
| 179 | - return '$.param(' . $params . ')'; |
|
| 177 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
| 178 | + if (!isset ($ajaxParameters ['contentType']) || !JString::contains($ajaxParameters ['contentType'], 'json')) { |
|
| 179 | + return '$.param('.$params.')'; |
|
| 180 | 180 | } else { |
| 181 | - return 'JSON.stringify(' . $params . ')'; |
|
| 181 | + return 'JSON.stringify('.$params.')'; |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | return $params; |
| 185 | 185 | } |
| 186 | 186 | public static function _implodeParams($parameters) { |
| 187 | - $allParameters = [ ]; |
|
| 188 | - foreach ( $parameters as $params ) { |
|
| 189 | - if (isset ( $params )) |
|
| 190 | - $allParameters [] = self::_correctParams ( $params ); |
|
| 187 | + $allParameters=[]; |
|
| 188 | + foreach ($parameters as $params) { |
|
| 189 | + if (isset ($params)) |
|
| 190 | + $allParameters []=self::_correctParams($params); |
|
| 191 | 191 | } |
| 192 | - return \implode ( "+'&'+", $allParameters ); |
|
| 192 | + return \implode("+'&'+", $allParameters); |
|
| 193 | 193 | } |
| 194 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 195 | - if (! isset ( $ajaxLoader )) { |
|
| 196 | - $ajaxLoader = $this->ajaxLoader; |
|
| 194 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 195 | + if (!isset ($ajaxLoader)) { |
|
| 196 | + $ajaxLoader=$this->ajaxLoader; |
|
| 197 | 197 | } |
| 198 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 199 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 198 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 199 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 200 | 200 | } |
| 201 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 202 | - if (! isset ( $ajaxLoader )) { |
|
| 203 | - $ajaxLoader = $this->ajaxLoader; |
|
| 201 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 202 | + if (!isset ($ajaxLoader)) { |
|
| 203 | + $ajaxLoader=$this->ajaxLoader; |
|
| 204 | 204 | } |
| 205 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 206 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 207 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 205 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 206 | + $retour.="{$responseElement}.empty();\n"; |
|
| 207 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 208 | 208 | } |
| 209 | 209 | protected function setAjaxDataCall($params) { |
| 210 | - $result = null; |
|
| 211 | - if (! \is_callable ( $params )) { |
|
| 212 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
| 213 | - return AjaxTransition::{$params} ( $responseElement, $jqueryDone ); |
|
| 210 | + $result=null; |
|
| 211 | + if (!\is_callable($params)) { |
|
| 212 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
| 213 | + return AjaxTransition::{$params} ($responseElement, $jqueryDone); |
|
| 214 | 214 | }; |
| 215 | 215 | } |
| 216 | 216 | return $result; |
| 217 | 217 | } |
| 218 | 218 | protected function setDefaultParameters(&$parameters, $default) { |
| 219 | - foreach ( $default as $k => $v ) { |
|
| 220 | - if (! isset ( $parameters [$k] )) |
|
| 221 | - $parameters [$k] = $v; |
|
| 219 | + foreach ($default as $k => $v) { |
|
| 220 | + if (!isset ($parameters [$k])) |
|
| 221 | + $parameters [$k]=$v; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | public function setAjaxLoader($loader) { |
| 225 | - $this->ajaxLoader = $loader; |
|
| 225 | + $this->ajaxLoader=$loader; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param string $responseElement |
| 234 | 234 | * selector of the HTML element displaying the answer |
| 235 | 235 | */ |
| 236 | - private function _get($url, $responseElement = '', $parameters = [ ]) { |
|
| 237 | - return $this->_ajax ( 'get', $url, $responseElement, $parameters ); |
|
| 236 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
| 237 | + return $this->_ajax('get', $url, $responseElement, $parameters); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | * @param array $parameters |
| 248 | 248 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 249 | 249 | */ |
| 250 | - public function get($url, $responseElement = '', $parameters = [ ]) { |
|
| 251 | - $parameters ['immediatly'] = true; |
|
| 252 | - return $this->_get ( $url, $responseElement, $parameters ); |
|
| 250 | + public function get($url, $responseElement='', $parameters=[]) { |
|
| 251 | + $parameters ['immediatly']=true; |
|
| 252 | + return $this->_get($url, $responseElement, $parameters); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * @param array $parameters |
| 265 | 265 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 266 | 266 | */ |
| 267 | - public function ajax($method, $url, $responseElement = '', $parameters = [ ]) { |
|
| 268 | - $parameters ['immediatly'] = true; |
|
| 269 | - return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
| 267 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 268 | + $parameters ['immediatly']=true; |
|
| 269 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | * $immediatly |
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [ ], $immediatly = true) { |
|
| 291 | - return $this->interval ( $this->ajaxDeferred ( $method, $url, $responseElement, $parameters ), $interval, $globalName, $immediatly ); |
|
| 290 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
| 291 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | * @param array $parameters |
| 304 | 304 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 305 | 305 | */ |
| 306 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = [ ]) { |
|
| 307 | - $parameters ['immediatly'] = false; |
|
| 308 | - return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
| 306 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
| 307 | + $parameters ['immediatly']=false; |
|
| 308 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -318,16 +318,16 @@ discard block |
||
| 318 | 318 | * @param array $parameters |
| 319 | 319 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 320 | 320 | */ |
| 321 | - private function _json($url, $method = "get", $parameters = [ ]) { |
|
| 322 | - $parameters = \array_merge ( $parameters, [ |
|
| 321 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 322 | + $parameters=\array_merge($parameters, [ |
|
| 323 | 323 | "hasLoader" => false |
| 324 | - ] ); |
|
| 325 | - $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
| 326 | - $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : "document"; |
|
| 327 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
| 328 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 329 | - $parameters ["jsCallback"] = $retour; |
|
| 330 | - return $this->_ajax ( $method, $url, null, $parameters ); |
|
| 324 | + ]); |
|
| 325 | + $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
| 326 | + $context=isset ($parameters ['context']) ? $parameters ['context'] : "document"; |
|
| 327 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
| 328 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 329 | + $parameters ["jsCallback"]=$retour; |
|
| 330 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -340,8 +340,8 @@ discard block |
||
| 340 | 340 | * @param array $parameters |
| 341 | 341 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 342 | 342 | */ |
| 343 | - public function json($url, $method = "get", $parameters = [ ]) { |
|
| 344 | - return $this->_json ( $url, $method, $parameters ); |
|
| 343 | + public function json($url, $method="get", $parameters=[]) { |
|
| 344 | + return $this->_json($url, $method, $parameters); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -356,14 +356,14 @@ discard block |
||
| 356 | 356 | * @param array $parameters |
| 357 | 357 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 358 | 358 | */ |
| 359 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array ()) { |
|
| 360 | - $this->setDefaultParameters ( $parameters, [ |
|
| 359 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
| 360 | + $this->setDefaultParameters($parameters, [ |
|
| 361 | 361 | 'preventDefault' => true, |
| 362 | 362 | 'stopPropagation' => true, |
| 363 | 363 | 'immediatly' => true, |
| 364 | 364 | 'listenerOn'=>false |
| 365 | - ] ); |
|
| 366 | - return $this->_add_event ( $element, $this->jsonDeferred ( $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
| 365 | + ]); |
|
| 366 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | * @param array $parameters |
| 377 | 377 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 378 | 378 | */ |
| 379 | - public function jsonDeferred($url, $method = 'get', $parameters = [ ]) { |
|
| 380 | - $parameters ['immediatly'] = false; |
|
| 381 | - return $this->_json ( $url, $method, $parameters ); |
|
| 379 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
| 380 | + $parameters ['immediatly']=false; |
|
| 381 | + return $this->_json($url, $method, $parameters); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -392,30 +392,30 @@ discard block |
||
| 392 | 392 | * @param array $parameters |
| 393 | 393 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 394 | 394 | */ |
| 395 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = [ ]) { |
|
| 396 | - $parameters = \array_merge ( $parameters, [ |
|
| 395 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 396 | + $parameters=\array_merge($parameters, [ |
|
| 397 | 397 | "hasLoader" => false |
| 398 | - ] ); |
|
| 399 | - $rowClass = isset ( $parameters ['rowClass'] ) ? $parameters ['rowClass'] : "_json"; |
|
| 400 | - $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
| 401 | - $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : null; |
|
| 402 | - if ($context === null) { |
|
| 403 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 404 | - $newElm = "$('#'+newId)"; |
|
| 398 | + ]); |
|
| 399 | + $rowClass=isset ($parameters ['rowClass']) ? $parameters ['rowClass'] : "_json"; |
|
| 400 | + $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
| 401 | + $context=isset ($parameters ['context']) ? $parameters ['context'] : null; |
|
| 402 | + if ($context===null) { |
|
| 403 | + $parent="$('".$maskSelector."').parent()"; |
|
| 404 | + $newElm="$('#'+newId)"; |
|
| 405 | 405 | } else { |
| 406 | - $parent = $context; |
|
| 407 | - $newElm = $context . ".find('#'+newId)"; |
|
| 406 | + $parent=$context; |
|
| 407 | + $newElm=$context.".find('#'+newId)"; |
|
| 408 | 408 | } |
| 409 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 410 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 411 | - $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n" . "\tvar created=false;var maskElm=$('" . $maskSelector . "').first();maskElm.hide();" . "\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;" . "\tvar newElm=" . $newElm . ";\n" . "\tif(!newElm.length){\n" . "\t\tnewElm=maskElm.clone(); |
|
| 409 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 410 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 411 | + $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
|
| 412 | 412 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
| 413 | - $retour .= $appendTo; |
|
| 414 | - $retour .= "\t}\n" . "\tfor(var key in value){\n" . "\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n" . "\t\t\tif(html.indexOf('__'+key+'__')>-1){\n" . "\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n" . "\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n" . "\t\t\t}\n" . "\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n" . "\t\t\tvar selElm=$(sel,newElm);\n" . "\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n" . "\t\t}\n" . "}\n" . "\t$(newElm).show(true);" . "\n" . "\t$(newElm).removeClass('hide');" . "});\n"; |
|
| 415 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 416 | - $retour .= "\t" . $jsCallback; |
|
| 417 | - $parameters ["jsCallback"] = $retour; |
|
| 418 | - return $this->_ajax ( $method, $url, null, $parameters ); |
|
| 413 | + $retour.=$appendTo; |
|
| 414 | + $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
|
| 415 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 416 | + $retour.="\t".$jsCallback; |
|
| 417 | + $parameters ["jsCallback"]=$retour; |
|
| 418 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * @param array $parameters |
| 430 | 430 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 431 | 431 | */ |
| 432 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = [ ]) { |
|
| 433 | - return $this->_jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
| 432 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 433 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -444,9 +444,9 @@ discard block |
||
| 444 | 444 | * @param array $parameters |
| 445 | 445 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 446 | 446 | */ |
| 447 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = [ ]) { |
|
| 448 | - $parameters ['immediatly'] = false; |
|
| 449 | - return $this->jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
| 447 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 448 | + $parameters ['immediatly']=false; |
|
| 449 | + return $this->jsonArray($maskSelector, $url, $method, $parameters); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -461,14 +461,14 @@ discard block |
||
| 461 | 461 | * @param array $parameters |
| 462 | 462 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 463 | 463 | */ |
| 464 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array ()) { |
|
| 465 | - $this->setDefaultParameters ( $parameters, [ |
|
| 464 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
| 465 | + $this->setDefaultParameters($parameters, [ |
|
| 466 | 466 | 'preventDefault' => true, |
| 467 | 467 | 'stopPropagation' => true, |
| 468 | 468 | 'immediatly' => true, |
| 469 | 469 | 'listenerOn'=>false |
| 470 | - ] ); |
|
| 471 | - return $this->_add_event ( $element, $this->jsonArrayDeferred ( $maskSelector, $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
| 470 | + ]); |
|
| 471 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** |
@@ -482,9 +482,9 @@ discard block |
||
| 482 | 482 | * @param array $parameters |
| 483 | 483 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 484 | 484 | */ |
| 485 | - public function getDeferred($url, $responseElement = "", $parameters = [ ]) { |
|
| 486 | - $parameters ['immediatly'] = false; |
|
| 487 | - return $this->_get ( $url, $responseElement, $parameters ); |
|
| 485 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 486 | + $parameters ['immediatly']=false; |
|
| 487 | + return $this->_get($url, $responseElement, $parameters); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -502,9 +502,9 @@ discard block |
||
| 502 | 502 | * @param array $parameters |
| 503 | 503 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 504 | 504 | */ |
| 505 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array ()) { |
|
| 505 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 506 | 506 | $parameters['method']='get'; |
| 507 | - return $this->ajaxOn($event, $element, $url,$responseElement,$parameters); |
|
| 507 | + return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -522,15 +522,15 @@ discard block |
||
| 522 | 522 | * @param array $parameters |
| 523 | 523 | * default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 524 | 524 | */ |
| 525 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array ()) { |
|
| 526 | - $this->setDefaultParameters ( $parameters, [ |
|
| 525 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
| 526 | + $this->setDefaultParameters($parameters, [ |
|
| 527 | 527 | 'preventDefault' => true, |
| 528 | 528 | 'stopPropagation' => true, |
| 529 | 529 | 'immediatly' => true, |
| 530 | 530 | 'method' => 'get', |
| 531 | 531 | 'listenerOn'=>false |
| 532 | - ] ); |
|
| 533 | - return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ['method'], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"],$parameters['listenerOn'] ); |
|
| 532 | + ]); |
|
| 533 | + return $this->_add_event($element, $this->ajaxDeferred($parameters ['method'], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -546,8 +546,8 @@ discard block |
||
| 546 | 546 | * @param array $parameters |
| 547 | 547 | * default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 548 | 548 | */ |
| 549 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array ()) { |
|
| 550 | - return $this->ajaxOn ( 'click', $element, $url, $responseElement, $parameters ); |
|
| 549 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 550 | + return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -563,8 +563,8 @@ discard block |
||
| 563 | 563 | * @param array $parameters |
| 564 | 564 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 565 | 565 | */ |
| 566 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array ()) { |
|
| 567 | - return $this->getOn ( 'click', $element, $url, $responseElement, $parameters ); |
|
| 566 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 567 | + return $this->getOn('click', $element, $url, $responseElement, $parameters); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -578,17 +578,17 @@ discard block |
||
| 578 | 578 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null) |
| 579 | 579 | * @return $this |
| 580 | 580 | */ |
| 581 | - public function getHref($element, $responseElement = "", $parameters = array ()) { |
|
| 582 | - $parameters ['attr'] = 'href'; |
|
| 583 | - if (JString::isNull ( $responseElement )) { |
|
| 584 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 581 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 582 | + $parameters ['attr']='href'; |
|
| 583 | + if (JString::isNull($responseElement)) { |
|
| 584 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 585 | 585 | } else { |
| 586 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 586 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 587 | 587 | } |
| 588 | - if (! isset ( $parameters ['historize'] )) { |
|
| 589 | - $parameters ['historize'] = true; |
|
| 588 | + if (!isset ($parameters ['historize'])) { |
|
| 589 | + $parameters ['historize']=true; |
|
| 590 | 590 | } |
| 591 | - return $this->getOnClick ( $element, "", $responseElement, $parameters ); |
|
| 591 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -602,21 +602,21 @@ discard block |
||
| 602 | 602 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null) |
| 603 | 603 | * @return $this |
| 604 | 604 | */ |
| 605 | - public function postHref($element, $responseElement = "", $parameters = array ()) { |
|
| 606 | - $parameters ['attr'] = 'href'; |
|
| 607 | - if (JString::isNull ( $responseElement )) { |
|
| 608 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 605 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 606 | + $parameters ['attr']='href'; |
|
| 607 | + if (JString::isNull($responseElement)) { |
|
| 608 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 609 | 609 | } else { |
| 610 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 610 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 611 | 611 | } |
| 612 | - if (! isset ( $parameters ['historize'] )) { |
|
| 613 | - $parameters ['historize'] = true; |
|
| 612 | + if (!isset ($parameters ['historize'])) { |
|
| 613 | + $parameters ['historize']=true; |
|
| 614 | 614 | } |
| 615 | - return $this->postOnClick ( $element, '', '{}', $responseElement, $parameters ); |
|
| 615 | + return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
|
| 616 | 616 | } |
| 617 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = [ ]) { |
|
| 618 | - $parameters ['params'] = $params; |
|
| 619 | - return $this->_ajax ( 'POST', $url, $responseElement, $parameters ); |
|
| 617 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
| 618 | + $parameters ['params']=$params; |
|
| 619 | + return $this->_ajax('POST', $url, $responseElement, $parameters); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -631,9 +631,9 @@ discard block |
||
| 631 | 631 | * @param array $parameters |
| 632 | 632 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 633 | 633 | */ |
| 634 | - public function post($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
| 635 | - $parameters ['immediatly'] = true; |
|
| 636 | - return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
| 634 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 635 | + $parameters ['immediatly']=true; |
|
| 636 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -649,9 +649,9 @@ discard block |
||
| 649 | 649 | * @param array $parameters |
| 650 | 650 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 651 | 651 | */ |
| 652 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
| 653 | - $parameters ['immediatly'] = false; |
|
| 654 | - return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
| 652 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 653 | + $parameters ['immediatly']=false; |
|
| 654 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -669,10 +669,10 @@ discard block |
||
| 669 | 669 | * @param array $parameters |
| 670 | 670 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 671 | 671 | */ |
| 672 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
| 672 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 673 | 673 | $parameters['method']='post'; |
| 674 | - $parameters ['params'] = $params; |
|
| 675 | - return $this->ajaxOn($event, $element, $url,$responseElement,$parameters); |
|
| 674 | + $parameters ['params']=$params; |
|
| 675 | + return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -689,65 +689,65 @@ discard block |
||
| 689 | 689 | * @param array $parameters |
| 690 | 690 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"before"=>null,"listenerOn"=>false) |
| 691 | 691 | */ |
| 692 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array ()) { |
|
| 693 | - return $this->postOn ( 'click', $element, $url, $params, $responseElement, $parameters ); |
|
| 694 | - } |
|
| 695 | - private function _postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
| 696 | - if (isset ( $this->params ['ajax'] )) { |
|
| 697 | - extract ( $this->params ['ajax'] ); |
|
| 698 | - } |
|
| 699 | - $params = '{}'; |
|
| 700 | - $validation = false; |
|
| 701 | - \extract ( $parameters ); |
|
| 702 | - $async = ($async) ? 'true' : 'false'; |
|
| 703 | - $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
| 704 | - $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
| 705 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
| 706 | - if (! isset ( $contentType ) || $contentType != 'false') { |
|
| 707 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
| 708 | - if (isset ( $params )) { |
|
| 709 | - $retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n"; |
|
| 692 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
| 693 | + return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
|
| 694 | + } |
|
| 695 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 696 | + if (isset ($this->params ['ajax'])) { |
|
| 697 | + extract($this->params ['ajax']); |
|
| 698 | + } |
|
| 699 | + $params='{}'; |
|
| 700 | + $validation=false; |
|
| 701 | + \extract($parameters); |
|
| 702 | + $async=($async) ? 'true' : 'false'; |
|
| 703 | + $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
| 704 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 705 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
| 706 | + if (!isset ($contentType) || $contentType!='false') { |
|
| 707 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
| 708 | + if (isset ($params)) { |
|
| 709 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 710 | 710 | } |
| 711 | 711 | } else { |
| 712 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
| 713 | - } |
|
| 714 | - $responseElement = $this->_getResponseElement ( $responseElement ); |
|
| 715 | - $retour .= "var self=this;\n"; |
|
| 716 | - $before = isset ( $before ) ? $before : ""; |
|
| 717 | - $retour .= $before; |
|
| 718 | - if ($hasLoader === true) { |
|
| 719 | - $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 720 | - } elseif ($hasLoader === 'response') { |
|
| 721 | - $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 722 | - } elseif ($hasLoader === 'internal') { |
|
| 723 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 724 | - } |
|
| 725 | - $ajaxParameters = [ |
|
| 712 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
| 713 | + } |
|
| 714 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 715 | + $retour.="var self=this;\n"; |
|
| 716 | + $before=isset ($before) ? $before : ""; |
|
| 717 | + $retour.=$before; |
|
| 718 | + if ($hasLoader===true) { |
|
| 719 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 720 | + } elseif ($hasLoader==='response') { |
|
| 721 | + $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
| 722 | + } elseif ($hasLoader==='internal') { |
|
| 723 | + $retour.="\n$(this).addClass('loading');"; |
|
| 724 | + } |
|
| 725 | + $ajaxParameters=[ |
|
| 726 | 726 | "url" => "url", |
| 727 | 727 | "method" => "'POST'", |
| 728 | 728 | "data" => "params", |
| 729 | 729 | "async" => $async |
| 730 | 730 | ]; |
| 731 | - if (isset ( $headers )) { |
|
| 732 | - $ajaxParameters ["headers"] = $headers; |
|
| 731 | + if (isset ($headers)) { |
|
| 732 | + $ajaxParameters ["headers"]=$headers; |
|
| 733 | 733 | } |
| 734 | - if (isset ( $partial )) { |
|
| 735 | - $ajaxParameters ["xhr"] = "xhrProvider"; |
|
| 736 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 734 | + if (isset ($partial)) { |
|
| 735 | + $ajaxParameters ["xhr"]="xhrProvider"; |
|
| 736 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 737 | 737 | } |
| 738 | - $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
| 739 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n"; |
|
| 740 | - $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n"; |
|
| 738 | + $this->createAjaxParameters($ajaxParameters, $parameters); |
|
| 739 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 740 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 741 | 741 | |
| 742 | 742 | if ($validation) { |
| 743 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
| 744 | - " . $retour . " |
|
| 743 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
| 744 | + " . $retour." |
|
| 745 | 745 | }});\n"; |
| 746 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
| 746 | + $retour.="$('#".$form."').submit();\n"; |
|
| 747 | 747 | } |
| 748 | - $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
| 748 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 749 | 749 | if ($immediatly) |
| 750 | - $this->jquery_code_for_compile [] = $retour; |
|
| 750 | + $this->jquery_code_for_compile []=$retour; |
|
| 751 | 751 | return $retour; |
| 752 | 752 | } |
| 753 | 753 | |
@@ -763,9 +763,9 @@ discard block |
||
| 763 | 763 | * @param array $parameters |
| 764 | 764 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 765 | 765 | */ |
| 766 | - public function postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
| 767 | - $parameters ['immediatly'] = true; |
|
| 768 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
| 766 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 767 | + $parameters ['immediatly']=true; |
|
| 768 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -781,9 +781,9 @@ discard block |
||
| 781 | 781 | * @param array $parameters |
| 782 | 782 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 783 | 783 | */ |
| 784 | - public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) { |
|
| 785 | - $parameters ['immediatly'] = false; |
|
| 786 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
| 784 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 785 | + $parameters ['immediatly']=false; |
|
| 786 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
@@ -799,14 +799,14 @@ discard block |
||
| 799 | 799 | * @param array $parameters |
| 800 | 800 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 801 | 801 | */ |
| 802 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
| 803 | - $this->setDefaultParameters ( $parameters, [ |
|
| 802 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 803 | + $this->setDefaultParameters($parameters, [ |
|
| 804 | 804 | 'preventDefault' => true, |
| 805 | 805 | 'stopPropagation' => true, |
| 806 | 806 | 'immediatly' => true, |
| 807 | 807 | 'listenerOn'=>false |
| 808 | - ] ); |
|
| 809 | - return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
| 808 | + ]); |
|
| 809 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -821,11 +821,11 @@ discard block |
||
| 821 | 821 | * @param array $parameters |
| 822 | 822 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false,"before"=>null,"listenerOn"=>false) |
| 823 | 823 | */ |
| 824 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
| 825 | - return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters ); |
|
| 824 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 825 | + return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - public function addCsrf($name='csrf-token'){ |
|
| 828 | + public function addCsrf($name='csrf-token') { |
|
| 829 | 829 | return " |
| 830 | 830 | $.ajaxSetup({ |
| 831 | 831 | beforeSend: function(xhr, settings) { |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | protected $groupByFields; |
| 31 | 31 | |
| 32 | - public static $index = 0; |
|
| 32 | + public static $index=0; |
|
| 33 | 33 | |
| 34 | - public function __construct($identifier, $instance = NULL, $captions = NULL) { |
|
| 35 | - $this->widgetIdentifier = $identifier; |
|
| 36 | - $this->values = []; |
|
| 37 | - $this->afterCompile = []; |
|
| 34 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
| 35 | + $this->widgetIdentifier=$identifier; |
|
| 36 | + $this->values=[]; |
|
| 37 | + $this->afterCompile=[]; |
|
| 38 | 38 | if (isset($instance)) |
| 39 | 39 | $this->setInstance($instance); |
| 40 | 40 | $this->setCaptions($captions); |
| 41 | - $this->captionCallback = NULL; |
|
| 42 | - $this->defaultValueFunction = function ($name, $value) { |
|
| 41 | + $this->captionCallback=NULL; |
|
| 42 | + $this->defaultValueFunction=function($name, $value) { |
|
| 43 | 43 | return $value; |
| 44 | 44 | }; |
| 45 | 45 | } |
@@ -66,47 +66,47 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | public function getValues() { |
| 69 | - $values = []; |
|
| 70 | - $index = 0; |
|
| 71 | - $count = $this->count(); |
|
| 72 | - $hasGroupby = is_array($this->groupByFields); |
|
| 73 | - if (! $hasGroupby) { |
|
| 74 | - while ($index < $count) { |
|
| 75 | - $values[] = $this->getValue($index ++); |
|
| 69 | + $values=[]; |
|
| 70 | + $index=0; |
|
| 71 | + $count=$this->count(); |
|
| 72 | + $hasGroupby=is_array($this->groupByFields); |
|
| 73 | + if (!$hasGroupby) { |
|
| 74 | + while ($index<$count) { |
|
| 75 | + $values[]=$this->getValue($index++); |
|
| 76 | 76 | } |
| 77 | 77 | } else { |
| 78 | - while ($index < $count) { |
|
| 79 | - if (array_search($index, $this->groupByFields) === false) { |
|
| 80 | - $values[] = $this->getValue($index); |
|
| 78 | + while ($index<$count) { |
|
| 79 | + if (array_search($index, $this->groupByFields)===false) { |
|
| 80 | + $values[]=$this->getValue($index); |
|
| 81 | 81 | } |
| 82 | - $index ++; |
|
| 82 | + $index++; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | return $values; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - public function getIdentifier($index = NULL) { |
|
| 89 | - if (! isset($index)) |
|
| 90 | - $index = self::$index; |
|
| 91 | - $value = $index; |
|
| 88 | + public function getIdentifier($index=NULL) { |
|
| 89 | + if (!isset($index)) |
|
| 90 | + $index=self::$index; |
|
| 91 | + $value=$index; |
|
| 92 | 92 | if (isset($this->values["identifier"])) { |
| 93 | 93 | if (\is_string($this->values["identifier"])) |
| 94 | - $value = JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 94 | + $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 95 | 95 | else |
| 96 | - $value = $this->values["identifier"]($index, $this->instance); |
|
| 96 | + $value=$this->values["identifier"]($index, $this->instance); |
|
| 97 | 97 | } |
| 98 | 98 | return $value; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function getValue($index) { |
| 102 | - $property = $this->properties[$index]; |
|
| 102 | + $property=$this->properties[$index]; |
|
| 103 | 103 | return $this->_getValue($property, $index); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | protected function _beforeAddProperty($index, &$field) {} |
| 107 | 107 | |
| 108 | 108 | protected function _getDefaultValue($name, $value, $index) { |
| 109 | - $func = $this->defaultValueFunction; |
|
| 109 | + $func=$this->defaultValueFunction; |
|
| 110 | 110 | return $func($name, $value, $index, $this->instance); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -116,27 +116,27 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | protected function _getValue($property, $index) { |
| 119 | - $value = null; |
|
| 120 | - $propertyName = $property; |
|
| 119 | + $value=null; |
|
| 120 | + $propertyName=$property; |
|
| 121 | 121 | if ($property instanceof \ReflectionProperty) { |
| 122 | - $value = $this->_getPropertyValue($property); |
|
| 123 | - $propertyName = $property->getName(); |
|
| 124 | - } elseif (\is_callable($property) && \array_search($property, ['system','date']) === false){ |
|
| 125 | - try{ |
|
| 126 | - $value = $property($this->instance); |
|
| 127 | - }catch(\Error $e){} |
|
| 122 | + $value=$this->_getPropertyValue($property); |
|
| 123 | + $propertyName=$property->getName(); |
|
| 124 | + } elseif (\is_callable($property) && \array_search($property, ['system', 'date'])===false) { |
|
| 125 | + try { |
|
| 126 | + $value=$property($this->instance); |
|
| 127 | + }catch (\Error $e) {} |
|
| 128 | 128 | } |
| 129 | 129 | elseif (\is_array($property)) { |
| 130 | - $values = \array_map(function ($v) use ($index) { |
|
| 130 | + $values=\array_map(function($v) use ($index) { |
|
| 131 | 131 | return $this->_getValue($v, $index); |
| 132 | 132 | }, $property); |
| 133 | - $value = \implode('', $values); |
|
| 133 | + $value=\implode('', $values); |
|
| 134 | 134 | } elseif (\is_string($property)) { |
| 135 | - $value = ''; |
|
| 135 | + $value=''; |
|
| 136 | 136 | if (isset($this->instance->{$property})) { |
| 137 | - $value = $this->instance->{$property}; |
|
| 138 | - } elseif (\method_exists($this->instance, $getter = JReflection::getterName($property))) { |
|
| 139 | - $value = JReflection::callMethod($this->instance, $getter, []); |
|
| 137 | + $value=$this->instance->{$property}; |
|
| 138 | + } elseif (\method_exists($this->instance, $getter=JReflection::getterName($property))) { |
|
| 139 | + $value=JReflection::callMethod($this->instance, $getter, []); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | protected function _postGetValue($index, $propertyName, $value) { |
| 147 | 147 | if (isset($this->values[$index])) { |
| 148 | - $value = $this->values[$index]($value, $this->instance, $index, self::$index); |
|
| 148 | + $value=$this->values[$index]($value, $this->instance, $index, self::$index); |
|
| 149 | 149 | } else { |
| 150 | - $value = $this->_getDefaultValue($propertyName, $value, $index); |
|
| 150 | + $value=$this->_getDefaultValue($propertyName, $value, $index); |
|
| 151 | 151 | } |
| 152 | 152 | if (isset($this->afterCompile[$index])) { |
| 153 | 153 | if (\is_callable($this->afterCompile[$index])) { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | return $value; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function insertField($index, $field, $key = null) { |
|
| 160 | + public function insertField($index, $field, $key=null) { |
|
| 161 | 161 | if (isset($key)) { |
| 162 | 162 | array_splice($this->visibleProperties, $index, 0, [ |
| 163 | 163 | $key => $field |
@@ -171,29 +171,29 @@ discard block |
||
| 171 | 171 | public function sortColumnContent($index, $array) { |
| 172 | 172 | if (isset($this->visibleProperties[$index])) { |
| 173 | 173 | if (is_array($this->visibleProperties[$index])) { |
| 174 | - $this->visibleProperties[$index] = JArray::sortAssociative($this->visibleProperties[$index], $array); |
|
| 174 | + $this->visibleProperties[$index]=JArray::sortAssociative($this->visibleProperties[$index], $array); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | return $this; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public function insertInField($index, $field, $key = null) { |
|
| 181 | - $vb = $this->visibleProperties; |
|
| 180 | + public function insertInField($index, $field, $key=null) { |
|
| 181 | + $vb=$this->visibleProperties; |
|
| 182 | 182 | if (isset($vb[$index])) { |
| 183 | 183 | if (isset($key)) { |
| 184 | 184 | if (\is_array($vb[$index])) { |
| 185 | - $this->visibleProperties[$index][$key] = $field; |
|
| 185 | + $this->visibleProperties[$index][$key]=$field; |
|
| 186 | 186 | } else { |
| 187 | - $this->visibleProperties[$index] = [ |
|
| 187 | + $this->visibleProperties[$index]=[ |
|
| 188 | 188 | $vb[$index], |
| 189 | 189 | $key => $field |
| 190 | 190 | ]; |
| 191 | 191 | } |
| 192 | 192 | } else { |
| 193 | 193 | if (\is_array($vb[$index])) { |
| 194 | - $this->visibleProperties[$index][] = $field; |
|
| 194 | + $this->visibleProperties[$index][]=$field; |
|
| 195 | 195 | } else { |
| 196 | - $this->visibleProperties[$index] = [ |
|
| 196 | + $this->visibleProperties[$index]=[ |
|
| 197 | 197 | $vb[$index], |
| 198 | 198 | $field |
| 199 | 199 | ]; |
@@ -205,19 +205,19 @@ discard block |
||
| 205 | 205 | return $this; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - public function addField($field, $key = null) { |
|
| 208 | + public function addField($field, $key=null) { |
|
| 209 | 209 | if (isset($key)) { |
| 210 | - $this->visibleProperties[] = [ |
|
| 210 | + $this->visibleProperties[]=[ |
|
| 211 | 211 | $key => $field |
| 212 | 212 | ]; |
| 213 | 213 | } else { |
| 214 | - $this->visibleProperties[] = $field; |
|
| 214 | + $this->visibleProperties[]=$field; |
|
| 215 | 215 | } |
| 216 | 216 | return $this; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public function addFields($fields) { |
| 220 | - $this->visibleProperties = \array_merge($this->visibleProperties, $fields); |
|
| 220 | + $this->visibleProperties=\array_merge($this->visibleProperties, $fields); |
|
| 221 | 221 | return $this; |
| 222 | 222 | } |
| 223 | 223 | |
@@ -234,30 +234,30 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | public function getFieldName($index) { |
| 237 | - $property = $this->getProperty($index); |
|
| 237 | + $property=$this->getProperty($index); |
|
| 238 | 238 | if ($property instanceof \ReflectionProperty) { |
| 239 | - $result = $property->getName(); |
|
| 239 | + $result=$property->getName(); |
|
| 240 | 240 | } elseif (\is_callable($property)) { |
| 241 | - $result = $this->visibleProperties[$index]; |
|
| 241 | + $result=$this->visibleProperties[$index]; |
|
| 242 | 242 | } else { |
| 243 | - $result = $property; |
|
| 243 | + $result=$property; |
|
| 244 | 244 | } |
| 245 | 245 | return $result; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | protected function showableProperty(\ReflectionProperty $rProperty) { |
| 249 | - return JString::startswith($rProperty->getName(), "_") === false; |
|
| 249 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function setInstance($instance) { |
| 253 | 253 | if (\is_string($instance)) { |
| 254 | - $instance = new $instance(); |
|
| 254 | + $instance=new $instance(); |
|
| 255 | 255 | } |
| 256 | - $this->instance = $instance; |
|
| 257 | - $this->properties = []; |
|
| 258 | - $this->reflect = new \ReflectionClass($instance); |
|
| 259 | - if (JArray::count($this->visibleProperties) === 0) { |
|
| 260 | - $this->properties = $this->getDefaultProperties(); |
|
| 256 | + $this->instance=$instance; |
|
| 257 | + $this->properties=[]; |
|
| 258 | + $this->reflect=new \ReflectionClass($instance); |
|
| 259 | + if (JArray::count($this->visibleProperties)===0) { |
|
| 260 | + $this->properties=$this->getDefaultProperties(); |
|
| 261 | 261 | } else { |
| 262 | 262 | foreach ($this->visibleProperties as $property) { |
| 263 | 263 | $this->setInstanceProperty($property); |
@@ -268,56 +268,56 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | private function setInstanceProperty($property) { |
| 270 | 270 | if (\is_callable($property)) { |
| 271 | - $this->properties[] = $property; |
|
| 271 | + $this->properties[]=$property; |
|
| 272 | 272 | } elseif (\is_string($property)) { |
| 273 | 273 | try { |
| 274 | 274 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 275 | - $rProperty = $this->reflect->getProperty($property); |
|
| 276 | - $this->properties[] = $rProperty; |
|
| 277 | - } catch (\Exception $e) { |
|
| 275 | + $rProperty=$this->reflect->getProperty($property); |
|
| 276 | + $this->properties[]=$rProperty; |
|
| 277 | + }catch (\Exception $e) { |
|
| 278 | 278 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 279 | - $this->properties[] = $property; |
|
| 279 | + $this->properties[]=$property; |
|
| 280 | 280 | } |
| 281 | 281 | } elseif (\is_int($property)) { |
| 282 | - $props = $this->getDefaultProperties(); |
|
| 282 | + $props=$this->getDefaultProperties(); |
|
| 283 | 283 | if (isset($props[$property])) |
| 284 | - $this->properties[] = $props[$property]; |
|
| 284 | + $this->properties[]=$props[$property]; |
|
| 285 | 285 | else |
| 286 | - $this->properties[] = $property; |
|
| 286 | + $this->properties[]=$property; |
|
| 287 | 287 | } else { |
| 288 | - $this->properties[] = $property; |
|
| 288 | + $this->properties[]=$property; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | protected function getDefaultProperties() { |
| 293 | - $result = []; |
|
| 294 | - $properties = $this->reflect->getProperties(); |
|
| 293 | + $result=[]; |
|
| 294 | + $properties=$this->reflect->getProperties(); |
|
| 295 | 295 | foreach ($properties as $property) { |
| 296 | - $showable = $this->showableProperty($property); |
|
| 297 | - if ($showable !== false) { |
|
| 298 | - $result[] = $property; |
|
| 296 | + $showable=$this->showableProperty($property); |
|
| 297 | + if ($showable!==false) { |
|
| 298 | + $result[]=$property; |
|
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | return $result; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | public function setVisibleProperties($visibleProperties) { |
| 305 | - $this->visibleProperties = $visibleProperties; |
|
| 305 | + $this->visibleProperties=$visibleProperties; |
|
| 306 | 306 | return $this; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | public function setValueFunction($index, $callback) { |
| 310 | - $this->values[$index] = $callback; |
|
| 310 | + $this->values[$index]=$callback; |
|
| 311 | 311 | return $this; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | public function setIdentifierFunction($callback) { |
| 315 | - $this->values["identifier"] = $callback; |
|
| 315 | + $this->values["identifier"]=$callback; |
|
| 316 | 316 | return $this; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | public static function setIndex($index) { |
| 320 | - self::$index = $index; |
|
| 320 | + self::$index=$index; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | public function getProperties() { |
@@ -337,43 +337,43 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | public function getCaptions() { |
| 340 | - $hasGroupby = is_array($this->groupByFields); |
|
| 341 | - $count = $this->count(); |
|
| 342 | - $moreAdded = false; |
|
| 340 | + $hasGroupby=is_array($this->groupByFields); |
|
| 341 | + $count=$this->count(); |
|
| 342 | + $moreAdded=false; |
|
| 343 | 343 | if (isset($this->captions)) { |
| 344 | - $captions = \array_values($this->captions); |
|
| 345 | - $gbSize = $hasGroupby ? sizeof($this->groupByFields) : 0; |
|
| 346 | - $captionsSize = \sizeof($captions); |
|
| 347 | - for ($i = $captionsSize; $i < $count - $gbSize; $i ++) { |
|
| 348 | - $captions[] = ""; |
|
| 349 | - $moreAdded = true; |
|
| 344 | + $captions=\array_values($this->captions); |
|
| 345 | + $gbSize=$hasGroupby ? sizeof($this->groupByFields) : 0; |
|
| 346 | + $captionsSize=\sizeof($captions); |
|
| 347 | + for ($i=$captionsSize; $i<$count-$gbSize; $i++) { |
|
| 348 | + $captions[]=""; |
|
| 349 | + $moreAdded=true; |
|
| 350 | 350 | } |
| 351 | 351 | } else { |
| 352 | - $captions = []; |
|
| 353 | - $index = 0; |
|
| 354 | - while ($index < $count) { |
|
| 355 | - $captions[] = $this->getCaption($index ++); |
|
| 352 | + $captions=[]; |
|
| 353 | + $index=0; |
|
| 354 | + while ($index<$count) { |
|
| 355 | + $captions[]=$this->getCaption($index++); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | - if ($hasGroupby && sizeof($captions) >= $count && ! $moreAdded) { |
|
| 359 | - $captions = JArray::removeByKeys($captions, $this->groupByFields); |
|
| 358 | + if ($hasGroupby && sizeof($captions)>=$count && !$moreAdded) { |
|
| 359 | + $captions=JArray::removeByKeys($captions, $this->groupByFields); |
|
| 360 | 360 | } |
| 361 | 361 | if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
| 362 | - $callback = $this->captionCallback; |
|
| 362 | + $callback=$this->captionCallback; |
|
| 363 | 363 | $callback($captions, $this->instance); |
| 364 | 364 | } |
| 365 | 365 | return $captions; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | public function setCaption($index, $caption) { |
| 369 | - if (isset($this->captions) === false) |
|
| 370 | - $this->captions = []; |
|
| 371 | - $this->captions[$index] = $caption; |
|
| 369 | + if (isset($this->captions)===false) |
|
| 370 | + $this->captions=[]; |
|
| 371 | + $this->captions[$index]=$caption; |
|
| 372 | 372 | return $this; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | public function setCaptions($captions) { |
| 376 | - $this->captions = $captions; |
|
| 376 | + $this->captions=$captions; |
|
| 377 | 377 | return $this; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @return InstanceViewer |
| 389 | 389 | */ |
| 390 | 390 | public function afterCompile($index, $callback) { |
| 391 | - $this->afterCompile[$index] = $callback; |
|
| 391 | + $this->afterCompile[$index]=$callback; |
|
| 392 | 392 | return $this; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | * @return \Ajax\semantic\widgets\base\InstanceViewer |
| 401 | 401 | */ |
| 402 | 402 | public function setCaptionCallback($captionCallback) { |
| 403 | - $this->captionCallback = $captionCallback; |
|
| 403 | + $this->captionCallback=$captionCallback; |
|
| 404 | 404 | return $this; |
| 405 | 405 | } |
| 406 | 406 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return \Ajax\semantic\widgets\base\InstanceViewer |
| 413 | 413 | */ |
| 414 | 414 | public function setDefaultValueFunction($defaultValueFunction) { |
| 415 | - $this->defaultValueFunction = $defaultValueFunction; |
|
| 415 | + $this->defaultValueFunction=$defaultValueFunction; |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | public function getSimpleProperties() { |
| 424 | - return array_filter($this->visibleProperties, function ($item) { |
|
| 425 | - return ! (is_array($item) || is_object($item)); |
|
| 424 | + return array_filter($this->visibleProperties, function($item) { |
|
| 425 | + return !(is_array($item) || is_object($item)); |
|
| 426 | 426 | }); |
| 427 | 427 | } |
| 428 | 428 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @param mixed $groupByFields |
| 448 | 448 | */ |
| 449 | 449 | public function setGroupByFields($groupByFields) { |
| 450 | - $this->groupByFields = $groupByFields; |
|
| 450 | + $this->groupByFields=$groupByFields; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | public function getGroupByFieldsCount() { |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | */ |
| 26 | 26 | class DataTable extends Widget { |
| 27 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait; |
|
| 27 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait, BaseTrait; |
|
| 28 | 28 | |
| 29 | 29 | protected $_searchField; |
| 30 | 30 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | protected $_displayBehavior; |
| 42 | 42 | |
| 43 | - protected $_visibleHover = false; |
|
| 43 | + protected $_visibleHover=false; |
|
| 44 | 44 | |
| 45 | 45 | protected $_targetSelector; |
| 46 | 46 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | protected $_json; |
| 52 | 52 | |
| 53 | - protected $_rowClass = "_element"; |
|
| 53 | + protected $_rowClass="_element"; |
|
| 54 | 54 | |
| 55 | 55 | protected $_sortable; |
| 56 | 56 | |
@@ -60,26 +60,26 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | protected $_paginationToolbar; |
| 62 | 62 | |
| 63 | - public function __construct($identifier, $model, $modelInstance = NULL) { |
|
| 63 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 64 | 64 | parent::__construct($identifier, $model, $modelInstance); |
| 65 | 65 | $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
| 66 | - $this->_urls = []; |
|
| 67 | - $this->_emptyMessage = new HtmlMessage("", "nothing to display"); |
|
| 66 | + $this->_urls=[]; |
|
| 67 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 68 | 68 | $this->_emptyMessage->setIcon("info circle"); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public function run(JsUtils $js) { |
| 72 | - if ($this->_runned !== true) { |
|
| 73 | - $offset = $js->scriptCount(); |
|
| 72 | + if ($this->_runned!==true) { |
|
| 73 | + $offset=$js->scriptCount(); |
|
| 74 | 74 | if ($this->_hasCheckboxes && isset($js)) { |
| 75 | 75 | $this->_runCheckboxes($js); |
| 76 | 76 | } |
| 77 | 77 | if ($this->_visibleHover) { |
| 78 | - $js->execOn("mouseover", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [ |
|
| 78 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [ |
|
| 79 | 79 | "preventDefault" => false, |
| 80 | 80 | "stopPropagation" => true |
| 81 | 81 | ]); |
| 82 | - $js->execOn("mouseout", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [ |
|
| 82 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [ |
|
| 83 | 83 | "preventDefault" => false, |
| 84 | 84 | "stopPropagation" => true |
| 85 | 85 | ]); |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | if (isset($this->_pagination)) |
| 96 | 96 | $this->_associatePaginationBehavior($js, $offset); |
| 97 | 97 | $this->_associateSearchFieldBehavior($js, $offset); |
| 98 | - $this->_runned = true; |
|
| 98 | + $this->_runned=true; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | protected function _generateBehavior($op, $params, JsUtils $js) { |
| 103 | 103 | if (isset($this->_urls[$op])) { |
| 104 | - $params = \array_merge($params, [ |
|
| 104 | + $params=\array_merge($params, [ |
|
| 105 | 105 | "attr" => "data-ajax" |
| 106 | 106 | ]); |
| 107 | - $js->ajaxOnClick("#" . $this->identifier . " ._" . $op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 107 | + $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -123,21 +123,21 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | public function refreshTD($fieldName, $jquery, $view) { |
| 126 | - $index = $this->_getIndex($fieldName); |
|
| 126 | + $index=$this->_getIndex($fieldName); |
|
| 127 | 127 | $this->compile($jquery, $view); |
| 128 | 128 | return $this->refreshTR() |
| 129 | 129 | ->getTable() |
| 130 | 130 | ->getCell(0, $index); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public function compile(JsUtils $js = NULL, &$view = NULL) { |
|
| 134 | - if (! $this->_generated) { |
|
| 133 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 134 | + if (!$this->_generated) { |
|
| 135 | 135 | if (isset($this->_buttonsColumn)) { |
| 136 | 136 | $this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons); |
| 137 | 137 | } |
| 138 | 138 | $this->_instanceViewer->setInstance($this->_model); |
| 139 | - $captions = $this->_instanceViewer->getCaptions(); |
|
| 140 | - $table = $this->content["table"]; |
|
| 139 | + $captions=$this->_instanceViewer->getCaptions(); |
|
| 140 | + $table=$this->content["table"]; |
|
| 141 | 141 | if ($this->_hasCheckboxes) { |
| 142 | 142 | $this->_generateMainCheckbox($captions); |
| 143 | 143 | } |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | $this->compileExtraElements($table, $captions); |
| 153 | 153 | $this->_compileSearchFieldBehavior($js); |
| 154 | 154 | |
| 155 | - $this->content = JArray::sortAssociative($this->content, [ |
|
| 155 | + $this->content=JArray::sortAssociative($this->content, [ |
|
| 156 | 156 | PositionInTable::BEFORETABLE, |
| 157 | 157 | "table", |
| 158 | 158 | PositionInTable::AFTERTABLE |
| 159 | 159 | ]); |
| 160 | 160 | $this->_compileForm(); |
| 161 | 161 | $this->_applyStyleAttributes($table); |
| 162 | - $this->_generated = true; |
|
| 162 | + $this->_generated=true; |
|
| 163 | 163 | } |
| 164 | 164 | return parent::compile($js, $view); |
| 165 | 165 | } |
@@ -204,21 +204,21 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | protected function _generateContent($table) { |
| 207 | - $objects = $this->_modelInstance; |
|
| 207 | + $objects=$this->_modelInstance; |
|
| 208 | 208 | if (isset($this->_pagination)) { |
| 209 | - $objects = $this->_pagination->getObjects($this->_modelInstance); |
|
| 209 | + $objects=$this->_pagination->getObjects($this->_modelInstance); |
|
| 210 | 210 | } |
| 211 | 211 | InstanceViewer::setIndex(0); |
| 212 | - $fields = $this->_instanceViewer->getSimpleProperties(); |
|
| 213 | - $groupByFields = $this->_instanceViewer->getGroupByFields(); |
|
| 214 | - if (! is_array($groupByFields)) { |
|
| 215 | - $table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields) { |
|
| 212 | + $fields=$this->_instanceViewer->getSimpleProperties(); |
|
| 213 | + $groupByFields=$this->_instanceViewer->getGroupByFields(); |
|
| 214 | + if (!is_array($groupByFields)) { |
|
| 215 | + $table->fromDatabaseObjects($objects, function($instance) use ($table, $fields) { |
|
| 216 | 216 | return $this->_generateRow($instance, $fields, $table); |
| 217 | 217 | }); |
| 218 | 218 | } else { |
| 219 | - $activeValues = array_combine($groupByFields, array_fill(0, sizeof($groupByFields), null)); |
|
| 220 | - $uuids = []; |
|
| 221 | - $table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids) { |
|
| 219 | + $activeValues=array_combine($groupByFields, array_fill(0, sizeof($groupByFields), null)); |
|
| 220 | + $uuids=[]; |
|
| 221 | + $table->fromDatabaseObjects($objects, function($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids) { |
|
| 222 | 222 | $this->_instanceViewer->setInstance($instance); |
| 223 | 223 | foreach ($groupByFields as $index => $gbField) { |
| 224 | 224 | $this->_generateGroupByRow($index, $gbField, $table, $fields, $activeValues, $uuids); |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | return $this->_generateRow($instance, $fields, $table, null, $uuids); |
| 227 | 227 | }); |
| 228 | 228 | } |
| 229 | - if ($table->getRowCount() == 0) { |
|
| 230 | - $result = $table->addRow(); |
|
| 229 | + if ($table->getRowCount()==0) { |
|
| 230 | + $result=$table->addRow(); |
|
| 231 | 231 | $result->mergeRow(); |
| 232 | 232 | $result->setValues([ |
| 233 | 233 | $this->_emptyMessage |
@@ -236,20 +236,20 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | protected function _generateGroupByRow($index, $gbField, $table, $fields, &$activeValues, &$uuids) { |
| 239 | - $newValue = $this->_instanceViewer->getValue($gbField); |
|
| 240 | - if ($this->getElementContent($activeValues[$gbField]) !== $this->getElementContent($newValue)) { |
|
| 241 | - if ($index == 0) { |
|
| 242 | - $uuids = []; |
|
| 239 | + $newValue=$this->_instanceViewer->getValue($gbField); |
|
| 240 | + if ($this->getElementContent($activeValues[$gbField])!==$this->getElementContent($newValue)) { |
|
| 241 | + if ($index==0) { |
|
| 242 | + $uuids=[]; |
|
| 243 | 243 | } |
| 244 | - $uuid = uniqid("grp"); |
|
| 245 | - $uuids[$gbField] = $uuid; |
|
| 246 | - $id = $this->_instanceViewer->getIdentifier(); |
|
| 247 | - $result = $table->addMergeRow(sizeof($fields) + 1, $newValue); |
|
| 248 | - $result->setIdentifier($this->identifier . "-tr-gb-" . $id); |
|
| 244 | + $uuid=uniqid("grp"); |
|
| 245 | + $uuids[$gbField]=$uuid; |
|
| 246 | + $id=$this->_instanceViewer->getIdentifier(); |
|
| 247 | + $result=$table->addMergeRow(sizeof($fields)+1, $newValue); |
|
| 248 | + $result->setIdentifier($this->identifier."-tr-gb-".$id); |
|
| 249 | 249 | $result->setProperty("data-ajax", $id); |
| 250 | 250 | $result->setProperty("data-group", $uuid); |
| 251 | 251 | $result->addToProperty("class", $this->_rowClass); |
| 252 | - $activeValues[$gbField] = $newValue; |
|
| 252 | + $activeValues[$gbField]=$newValue; |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
@@ -261,9 +261,9 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | public function getFieldValue($index) { |
| 264 | - $index = $this->_getIndex($index); |
|
| 264 | + $index=$this->_getIndex($index); |
|
| 265 | 265 | if (is_numeric($index)) { |
| 266 | - $values = $this->_instanceViewer->getValues(); |
|
| 266 | + $values=$this->_instanceViewer->getValues(); |
|
| 267 | 267 | if (isset($values[$index])) { |
| 268 | 268 | return $values[$index]; |
| 269 | 269 | } |
@@ -271,31 +271,31 @@ discard block |
||
| 271 | 271 | return null; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - protected function _generateRow($instance, $fields, &$table, $checkedClass = null, $uuids = null) { |
|
| 274 | + protected function _generateRow($instance, $fields, &$table, $checkedClass=null, $uuids=null) { |
|
| 275 | 275 | $this->_instanceViewer->setInstance($instance); |
| 276 | - InstanceViewer::$index ++; |
|
| 277 | - $values = $this->_instanceViewer->getValues(); |
|
| 278 | - $id = $this->_instanceViewer->getIdentifier(); |
|
| 279 | - $dataAjax = $id; |
|
| 280 | - $id = $this->cleanIdentifier($id); |
|
| 276 | + InstanceViewer::$index++; |
|
| 277 | + $values=$this->_instanceViewer->getValues(); |
|
| 278 | + $id=$this->_instanceViewer->getIdentifier(); |
|
| 279 | + $dataAjax=$id; |
|
| 280 | + $id=$this->cleanIdentifier($id); |
|
| 281 | 281 | if ($this->_hasCheckboxes) { |
| 282 | - $ck = new HtmlCheckbox("ck-" . $this->identifier . "-" . $id, ""); |
|
| 283 | - $checked = false; |
|
| 282 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
| 283 | + $checked=false; |
|
| 284 | 284 | if (isset($this->_checkedCallback)) { |
| 285 | - $func = $this->_checkedCallback; |
|
| 286 | - $checked = $func($instance); |
|
| 285 | + $func=$this->_checkedCallback; |
|
| 286 | + $checked=$func($instance); |
|
| 287 | 287 | } |
| 288 | 288 | $ck->setChecked($checked); |
| 289 | 289 | // $ck->setOnChange("event.stopPropagation();"); |
| 290 | - $field = $ck->getField(); |
|
| 290 | + $field=$ck->getField(); |
|
| 291 | 291 | $field->setProperty("value", $dataAjax); |
| 292 | 292 | $field->setProperty("name", "selection[]"); |
| 293 | 293 | if (isset($checkedClass)) |
| 294 | 294 | $field->setClass($checkedClass); |
| 295 | 295 | \array_unshift($values, $ck); |
| 296 | 296 | } |
| 297 | - $result = $table->newRow(); |
|
| 298 | - $result->setIdentifier($this->identifier . "-tr-" . $id); |
|
| 297 | + $result=$table->newRow(); |
|
| 298 | + $result->setIdentifier($this->identifier."-tr-".$id); |
|
| 299 | 299 | $result->setProperty("data-ajax", $dataAjax); |
| 300 | 300 | $result->setValues($values); |
| 301 | 301 | $result->addToProperty("class", $this->_rowClass); |
@@ -308,63 +308,63 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | protected function _generatePagination($table) { |
| 310 | 310 | if (isset($this->_toolbar)) { |
| 311 | - if ($this->_toolbarPosition == PositionInTable::FOOTER) |
|
| 311 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 312 | 312 | $this->_toolbar->setFloated("left"); |
| 313 | 313 | } |
| 314 | - $footer = $table->getFooter(); |
|
| 314 | + $footer=$table->getFooter(); |
|
| 315 | 315 | $footer->mergeCol(); |
| 316 | 316 | $this->_paginationToolbar=$this->_pagination->generateMenu($this->identifier); |
| 317 | 317 | $footer->addValues($this->_paginationToolbar); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - protected function _associatePaginationBehavior(JsUtils $js = NULL, $offset = null) { |
|
| 320 | + protected function _associatePaginationBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 321 | 321 | if (isset($this->_urls["refresh"])) { |
| 322 | - $menu = $this->_pagination->getMenu(); |
|
| 322 | + $menu=$this->_pagination->getMenu(); |
|
| 323 | 323 | if (isset($menu) && isset($js)) { |
| 324 | - $js->postOnClick("#" . $menu->getIdentifier() . " .item", $this->_urls["refresh"], "{'p':$(this).attr('data-page'),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", $this->getRefreshSelector(), [ |
|
| 324 | + $js->postOnClick("#".$menu->getIdentifier()." .item", $this->_urls["refresh"], "{'p':$(this).attr('data-page'),'_model':'".JString::doubleBackSlashes($this->_model)."'}", $this->getRefreshSelector(), [ |
|
| 325 | 325 | "preventDefault" => false, |
| 326 | 326 | "jqueryDone" => "replaceWith", |
| 327 | 327 | "hasLoader" => false, |
| 328 | - "jsCallback" => '$("#' . $this->identifier . '").trigger("pageChange");$("#' . $this->identifier . '").trigger("activeRowChange");' |
|
| 328 | + "jsCallback" => '$("#'.$this->identifier.'").trigger("pageChange");$("#'.$this->identifier.'").trigger("activeRowChange");' |
|
| 329 | 329 | ]); |
| 330 | - $page = $_POST["p"] ?? null; |
|
| 330 | + $page=$_POST["p"] ?? null; |
|
| 331 | 331 | if (isset($page)) { |
| 332 | - $js->execAtLast('$("#' . $this->getIdentifier() . ' .pagination").children("a.item").removeClass("active");$("#' . $this->getIdentifier() . ' .pagination").children("a.item[data-page=' . $page . ']:not(.no-active)").addClass("active");'); |
|
| 332 | + $js->execAtLast('$("#'.$this->getIdentifier().' .pagination").children("a.item").removeClass("active");$("#'.$this->getIdentifier().' .pagination").children("a.item[data-page='.$page.']:not(.no-active)").addClass("active");'); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - protected function _compileSearchFieldBehavior(JsUtils $js = NULL) { |
|
| 338 | + protected function _compileSearchFieldBehavior(JsUtils $js=NULL) { |
|
| 339 | 339 | if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
| 340 | - $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val(),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", "#" . $this->identifier . " tbody", [ |
|
| 340 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val(),'_model':'".JString::doubleBackSlashes($this->_model)."'}", "#".$this->identifier." tbody", [ |
|
| 341 | 341 | "preventDefault" => false, |
| 342 | 342 | "jqueryDone" => "replaceWith", |
| 343 | 343 | "hasLoader" => "internal", |
| 344 | - "jsCallback" => '$("#' . $this->identifier . '").trigger("searchTerminate",[$(self).val()]);' |
|
| 344 | + "jsCallback" => '$("#'.$this->identifier.'").trigger("searchTerminate",[$(self).val()]);' |
|
| 345 | 345 | ]); |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - protected function _associateSearchFieldBehavior(JsUtils $js = NULL, $offset = null) {} |
|
| 349 | + protected function _associateSearchFieldBehavior(JsUtils $js=NULL, $offset=null) {} |
|
| 350 | 350 | |
| 351 | 351 | protected function _getFieldName($index) { |
| 352 | - $fieldName = parent::_getFieldName($index); |
|
| 352 | + $fieldName=parent::_getFieldName($index); |
|
| 353 | 353 | if (\is_object($fieldName)) |
| 354 | - $fieldName = "field-" . $index; |
|
| 355 | - return $fieldName . "[]"; |
|
| 354 | + $fieldName="field-".$index; |
|
| 355 | + return $fieldName."[]"; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | protected function _getFieldCaption($index) { |
| 359 | 359 | return null; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - protected function _setToolbarPosition($table, $captions = NULL) { |
|
| 362 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 363 | 363 | switch ($this->_toolbarPosition) { |
| 364 | 364 | case PositionInTable::BEFORETABLE: |
| 365 | 365 | case PositionInTable::AFTERTABLE: |
| 366 | - if (isset($this->_compileParts) === false) { |
|
| 367 | - $this->content[$this->_toolbarPosition] = $this->_toolbar; |
|
| 366 | + if (isset($this->_compileParts)===false) { |
|
| 367 | + $this->content[$this->_toolbarPosition]=$this->_toolbar; |
|
| 368 | 368 | } |
| 369 | 369 | break; |
| 370 | 370 | case PositionInTable::HEADER: |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | private function addToolbarRow($part, $table, $captions) { |
| 394 | - $hasPart = $table->hasPart($part); |
|
| 394 | + $hasPart=$table->hasPart($part); |
|
| 395 | 395 | if ($hasPart) { |
| 396 | - $row = $table->getPart($part)->addRow(\sizeof($captions)); |
|
| 396 | + $row=$table->getPart($part)->addRow(\sizeof($captions)); |
|
| 397 | 397 | } else { |
| 398 | - $row = $table->getPart($part)->getRow(0); |
|
| 398 | + $row=$table->getPart($part)->getRow(0); |
|
| 399 | 399 | } |
| 400 | 400 | $row->mergeCol(); |
| 401 | 401 | $row->setValues([ |
@@ -427,12 +427,12 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function setUrls($urls) { |
| 429 | 429 | if (\is_array($urls)) { |
| 430 | - $this->_urls["refresh"] = JArray::getValue($urls, "refresh", 0); |
|
| 431 | - $this->_urls["edit"] = JArray::getValue($urls, "edit", 1); |
|
| 432 | - $this->_urls["delete"] = JArray::getValue($urls, "delete", 2); |
|
| 433 | - $this->_urls["display"] = JArray::getValue($urls, "display", 3); |
|
| 430 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 431 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 432 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 433 | + $this->_urls["display"]=JArray::getValue($urls, "display", 3); |
|
| 434 | 434 | } else { |
| 435 | - $this->_urls = [ |
|
| 435 | + $this->_urls=[ |
|
| 436 | 436 | "refresh" => $urls, |
| 437 | 437 | "edit" => $urls, |
| 438 | 438 | "delete" => $urls, |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | * The number of visible pages in the Pagination component |
| 456 | 456 | * @return DataTable |
| 457 | 457 | */ |
| 458 | - public function paginate($page, $total_rowcount, $items_per_page = 10, $pages_visibles = null) { |
|
| 459 | - $this->_pagination = new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 458 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 459 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 460 | 460 | return $this; |
| 461 | 461 | } |
| 462 | 462 | |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * The number of visible pages in the Pagination component |
| 472 | 472 | * @return DataTable |
| 473 | 473 | */ |
| 474 | - public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles = 4) { |
|
| 475 | - $this->_pagination = new Pagination($items_per_page, $pages_visibles, $page); |
|
| 474 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 475 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 476 | 476 | return $this; |
| 477 | 477 | } |
| 478 | 478 | |
@@ -481,10 +481,10 @@ discard block |
||
| 481 | 481 | * @param array $compileParts |
| 482 | 482 | * @return DataTable |
| 483 | 483 | */ |
| 484 | - public function refresh($compileParts = [ |
|
| 484 | + public function refresh($compileParts=[ |
|
| 485 | 485 | "tbody" |
| 486 | 486 | ]) { |
| 487 | - $this->_compileParts = $compileParts; |
|
| 487 | + $this->_compileParts=$compileParts; |
|
| 488 | 488 | return $this; |
| 489 | 489 | } |
| 490 | 490 | |
@@ -494,14 +494,14 @@ discard block |
||
| 494 | 494 | * @param string $position |
| 495 | 495 | * @return \Ajax\common\html\HtmlDoubleElement |
| 496 | 496 | */ |
| 497 | - public function addSearchInToolbar($position = Direction::RIGHT) { |
|
| 497 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 498 | 498 | return $this->addInToolbar($this->getSearchField()) |
| 499 | 499 | ->setPosition($position); |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | public function getSearchField() { |
| 503 | - if (isset($this->_searchField) === false) { |
|
| 504 | - $this->_searchField = new HtmlInput("search-" . $this->identifier, "search", "", "Search..."); |
|
| 503 | + if (isset($this->_searchField)===false) { |
|
| 504 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 505 | 505 | $this->_searchField->addIcon("search", Direction::RIGHT); |
| 506 | 506 | } |
| 507 | 507 | return $this->_searchField; |
@@ -529,9 +529,9 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | protected function getTargetSelector($op) { |
| 532 | - $result = $this->_targetSelector; |
|
| 533 | - if (! isset($result[$op])) |
|
| 534 | - $result = "#" . $this->identifier; |
|
| 532 | + $result=$this->_targetSelector; |
|
| 533 | + if (!isset($result[$op])) |
|
| 534 | + $result="#".$this->identifier; |
|
| 535 | 535 | return $result[$op]; |
| 536 | 536 | } |
| 537 | 537 | |
@@ -543,20 +543,20 @@ discard block |
||
| 543 | 543 | * @return DataTable |
| 544 | 544 | */ |
| 545 | 545 | public function setTargetSelector($_targetSelector) { |
| 546 | - if (! \is_array($_targetSelector)) { |
|
| 547 | - $_targetSelector = [ |
|
| 546 | + if (!\is_array($_targetSelector)) { |
|
| 547 | + $_targetSelector=[ |
|
| 548 | 548 | "edit" => $_targetSelector, |
| 549 | 549 | "delete" => $_targetSelector |
| 550 | 550 | ]; |
| 551 | 551 | } |
| 552 | - $this->_targetSelector = $_targetSelector; |
|
| 552 | + $this->_targetSelector=$_targetSelector; |
|
| 553 | 553 | return $this; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | public function getRefreshSelector() { |
| 557 | 557 | if (isset($this->_refreshSelector)) |
| 558 | 558 | return $this->_refreshSelector; |
| 559 | - return "#" . $this->identifier . " tbody"; |
|
| 559 | + return "#".$this->identifier." tbody"; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /** |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * @return DataTable |
| 566 | 566 | */ |
| 567 | 567 | public function setRefreshSelector($_refreshSelector) { |
| 568 | - $this->_refreshSelector = $_refreshSelector; |
|
| 568 | + $this->_refreshSelector=$_refreshSelector; |
|
| 569 | 569 | return $this; |
| 570 | 570 | } |
| 571 | 571 | |
@@ -577,9 +577,9 @@ discard block |
||
| 577 | 577 | public function show($modelInstance) { |
| 578 | 578 | if (\is_array($modelInstance)) { |
| 579 | 579 | if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
| 580 | - $modelInstance = \json_decode(\json_encode($modelInstance), FALSE); |
|
| 580 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 581 | 581 | } |
| 582 | - $this->_modelInstance = $modelInstance; |
|
| 582 | + $this->_modelInstance=$modelInstance; |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | public function getRowClass() { |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | * @return DataTable |
| 594 | 594 | */ |
| 595 | 595 | public function setRowClass($_rowClass) { |
| 596 | - $this->_rowClass = $_rowClass; |
|
| 596 | + $this->_rowClass=$_rowClass; |
|
| 597 | 597 | return $this; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -604,34 +604,34 @@ discard block |
||
| 604 | 604 | * @return DataTable |
| 605 | 605 | */ |
| 606 | 606 | public function setEmptyMessage($_emptyMessage) { |
| 607 | - $this->_emptyMessage = $_emptyMessage; |
|
| 607 | + $this->_emptyMessage=$_emptyMessage; |
|
| 608 | 608 | return $this; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - public function setSortable($colIndex = NULL) { |
|
| 612 | - $this->_sortable = $colIndex; |
|
| 611 | + public function setSortable($colIndex=NULL) { |
|
| 612 | + $this->_sortable=$colIndex; |
|
| 613 | 613 | return $this; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - public function setActiveRowSelector($class = "active", $event = "click", $multiple = false) { |
|
| 616 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 617 | 617 | $this->_self->setActiveRowSelector($class, $event, $multiple); |
| 618 | 618 | return $this; |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | public function hideColumn($colIndex) { |
| 622 | - if (! \is_array($this->_hiddenColumns)) |
|
| 623 | - $this->_hiddenColumns = []; |
|
| 624 | - $this->_hiddenColumns[] = $colIndex; |
|
| 622 | + if (!\is_array($this->_hiddenColumns)) |
|
| 623 | + $this->_hiddenColumns=[]; |
|
| 624 | + $this->_hiddenColumns[]=$colIndex; |
|
| 625 | 625 | return $this; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | public function setColWidth($colIndex, $width) { |
| 629 | - $this->_colWidths[$colIndex] = $width; |
|
| 629 | + $this->_colWidths[$colIndex]=$width; |
|
| 630 | 630 | return $this; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | public function setColWidths($_colWidths) { |
| 634 | - $this->_colWidths = $_colWidths; |
|
| 634 | + $this->_colWidths=$_colWidths; |
|
| 635 | 635 | return $this; |
| 636 | 636 | } |
| 637 | 637 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | return $this; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - public function trigger($event, $params = "[]") { |
|
| 643 | + public function trigger($event, $params="[]") { |
|
| 644 | 644 | return $this->getHtmlComponent()->trigger($event, $params); |
| 645 | 645 | } |
| 646 | 646 | |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | * @param mixed $_displayBehavior |
| 679 | 679 | */ |
| 680 | 680 | public function setDisplayBehavior($_displayBehavior) { |
| 681 | - $this->_displayBehavior = $_displayBehavior; |
|
| 681 | + $this->_displayBehavior=$_displayBehavior; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @param boolean $_visibleHover |
| 703 | 703 | */ |
| 704 | 704 | public function setVisibleHover($_visibleHover) { |
| 705 | - $this->_visibleHover = $_visibleHover; |
|
| 705 | + $this->_visibleHover=$_visibleHover; |
|
| 706 | 706 | } |
| 707 | 707 | /** |
| 708 | 708 | * @return \Ajax\semantic\html\collections\menus\HtmlPaginationMenu |