@@ -13,17 +13,17 @@ discard block |
||
| 13 | 13 | use Ajax\service\JArray; |
| 14 | 14 | |
| 15 | 15 | class HtmlDropdown extends HtmlSemDoubleElement { |
| 16 | - use FieldTrait,LabeledIconTrait { |
|
| 16 | + use FieldTrait, LabeledIconTrait { |
|
| 17 | 17 | addIcon as addIconP; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - protected $mClass = "menu"; |
|
| 20 | + protected $mClass="menu"; |
|
| 21 | 21 | |
| 22 | - protected $mTagName = "div"; |
|
| 22 | + protected $mTagName="div"; |
|
| 23 | 23 | |
| 24 | - protected $items = array(); |
|
| 24 | + protected $items=array(); |
|
| 25 | 25 | |
| 26 | - protected $_params = array( |
|
| 26 | + protected $_params=array( |
|
| 27 | 27 | "action" => "nothing", |
| 28 | 28 | "on" => "hover", |
| 29 | 29 | "showOnFocus" => true |
@@ -37,29 +37,29 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | protected $_multiple; |
| 39 | 39 | |
| 40 | - public function __construct($identifier, $value = "", $items = array(), $associative = true) { |
|
| 40 | + public function __construct($identifier, $value="", $items=array(), $associative=true) { |
|
| 41 | 41 | parent::__construct($identifier, "div"); |
| 42 | - $this->_template = include dirname(__FILE__) . '/../templates/tplDropdown.php'; |
|
| 42 | + $this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php'; |
|
| 43 | 43 | $this->setProperty("class", "ui dropdown"); |
| 44 | - $this->_multiple = false; |
|
| 45 | - $content = []; |
|
| 46 | - $text = ''; |
|
| 44 | + $this->_multiple=false; |
|
| 45 | + $content=[]; |
|
| 46 | + $text=''; |
|
| 47 | 47 | if ($value instanceof HtmlSemDoubleElement) { |
| 48 | - $text = $value; |
|
| 49 | - } elseif ($value !== null) { |
|
| 50 | - $text = new HtmlSemDoubleElement("text-" . $this->identifier, "div"); |
|
| 48 | + $text=$value; |
|
| 49 | + } elseif ($value!==null) { |
|
| 50 | + $text=new HtmlSemDoubleElement("text-".$this->identifier, "div"); |
|
| 51 | 51 | $text->setClass("text"); |
| 52 | 52 | $this->setValue($value); |
| 53 | 53 | } |
| 54 | - if ($text != null) { |
|
| 55 | - $content = [ |
|
| 54 | + if ($text!=null) { |
|
| 55 | + $content=[ |
|
| 56 | 56 | "text" => $text |
| 57 | 57 | ]; |
| 58 | 58 | } |
| 59 | - $content["arrow"] = new HtmlIcon($identifier . "-icon", "dropdown"); |
|
| 60 | - $this->content = $content; |
|
| 61 | - $this->tagName = "div"; |
|
| 62 | - $this->_associative = $associative; |
|
| 59 | + $content["arrow"]=new HtmlIcon($identifier."-icon", "dropdown"); |
|
| 60 | + $this->content=$content; |
|
| 61 | + $this->tagName="div"; |
|
| 62 | + $this->_associative=$associative; |
|
| 63 | 63 | $this->addItems($items); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | return $this->input; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public function addItem($item, $value = NULL, $image = NULL, $description = NULL) { |
|
| 75 | - $itemO = $this->beforeAddItem($item, $value, $image, $description); |
|
| 76 | - $this->items[] = $itemO; |
|
| 74 | + public function addItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
| 75 | + $itemO=$this->beforeAddItem($item, $value, $image, $description); |
|
| 76 | + $this->items[]=$itemO; |
|
| 77 | 77 | return $itemO; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function addIcon($icon, $before = true, $labeled = false) { |
|
| 80 | + public function addIcon($icon, $before=true, $labeled=false) { |
|
| 81 | 81 | $this->removeArrow(); |
| 82 | 82 | $this->addIconP($icon, $before, $labeled); |
| 83 | - $elm = $this->getElementById("text-" . $this->identifier, $this->content); |
|
| 83 | + $elm=$this->getElementById("text-".$this->identifier, $this->content); |
|
| 84 | 84 | if (isset($elm)) { |
| 85 | 85 | $elm->setWrapAfter(""); |
| 86 | 86 | } |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function addIcons($icons) { |
| 91 | - $count = $this->count(); |
|
| 92 | - for ($i = 0; $i < \sizeof($icons) && $i < $count; $i ++) { |
|
| 91 | + $count=$this->count(); |
|
| 92 | + for ($i=0; $i<\sizeof($icons) && $i<$count; $i++) { |
|
| 93 | 93 | $this->getItem($i)->addIcon($icons[$i]); |
| 94 | 94 | } |
| 95 | 95 | } |
@@ -101,32 +101,32 @@ discard block |
||
| 101 | 101 | * @param int $position |
| 102 | 102 | * @return HtmlDropdownItem |
| 103 | 103 | */ |
| 104 | - public function insertItem($item, $position = 0) { |
|
| 105 | - $itemO = $this->beforeAddItem($item); |
|
| 106 | - $start = array_slice($this->items, 0, $position); |
|
| 107 | - $end = array_slice($this->items, $position); |
|
| 108 | - $start[] = $item; |
|
| 109 | - $this->items = array_merge($start, $end); |
|
| 104 | + public function insertItem($item, $position=0) { |
|
| 105 | + $itemO=$this->beforeAddItem($item); |
|
| 106 | + $start=array_slice($this->items, 0, $position); |
|
| 107 | + $end=array_slice($this->items, $position); |
|
| 108 | + $start[]=$item; |
|
| 109 | + $this->items=array_merge($start, $end); |
|
| 110 | 110 | return $itemO; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | protected function removeArrow() { |
| 114 | - if (\sizeof($this->content) > 1) { |
|
| 114 | + if (\sizeof($this->content)>1) { |
|
| 115 | 115 | unset($this->content["arrow"]); |
| 116 | - $this->content = \array_values($this->content); |
|
| 116 | + $this->content=\array_values($this->content); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - protected function beforeAddItem($item, $value = NULL, $image = NULL, $description = NULL) { |
|
| 121 | - $itemO = $item; |
|
| 120 | + protected function beforeAddItem($item, $value=NULL, $image=NULL, $description=NULL) { |
|
| 121 | + $itemO=$item; |
|
| 122 | 122 | if (\is_array($item)) { |
| 123 | - $description = JArray::getValue($item, "description", 3); |
|
| 124 | - $value = JArray::getValue($item, "value", 1); |
|
| 125 | - $image = JArray::getValue($item, "image", 2); |
|
| 126 | - $item = JArray::getValue($item, "item", 0); |
|
| 123 | + $description=JArray::getValue($item, "description", 3); |
|
| 124 | + $value=JArray::getValue($item, "value", 1); |
|
| 125 | + $image=JArray::getValue($item, "image", 2); |
|
| 126 | + $item=JArray::getValue($item, "item", 0); |
|
| 127 | 127 | } |
| 128 | - if (! $item instanceof HtmlDropdownItem) { |
|
| 129 | - $itemO = new HtmlDropdownItem("dd-item-" . $this->identifier . "-" . \sizeof($this->items), $item, $value, $image, $description); |
|
| 128 | + if (!$item instanceof HtmlDropdownItem) { |
|
| 129 | + $itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items), $item, $value, $image, $description); |
|
| 130 | 130 | } elseif ($itemO instanceof HtmlDropdownItem) { |
| 131 | 131 | $this->addToProperty("class", "vertical"); |
| 132 | 132 | } |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | public function addInput($name) { |
| 145 | - if (! isset($name)) |
|
| 146 | - $name = "input-" . $this->identifier; |
|
| 145 | + if (!isset($name)) |
|
| 146 | + $name="input-".$this->identifier; |
|
| 147 | 147 | $this->setAction("activate"); |
| 148 | - $this->input = new HtmlInput($name, "hidden"); |
|
| 149 | - $this->input->setIdentifier("input-" . $this->identifier); |
|
| 148 | + $this->input=new HtmlInput($name, "hidden"); |
|
| 149 | + $this->input->setIdentifier("input-".$this->identifier); |
|
| 150 | 150 | return $this->input; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $icon |
| 158 | 158 | * @return HtmlDropdownItem |
| 159 | 159 | */ |
| 160 | - public function addSearchInputItem($placeHolder = NULL, $icon = NULL) { |
|
| 160 | + public function addSearchInputItem($placeHolder=NULL, $icon=NULL) { |
|
| 161 | 161 | return $this->addItem(HtmlDropdownItem::searchInput($placeHolder, $icon)); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param string $icon |
| 178 | 178 | * @return HtmlDropdownItem |
| 179 | 179 | */ |
| 180 | - public function addHeaderItem($caption = NULL, $icon = NULL) { |
|
| 180 | + public function addHeaderItem($caption=NULL, $icon=NULL) { |
|
| 181 | 181 | return $this->addItem(HtmlDropdownItem::header($caption, $icon)); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | * @return $this |
| 223 | 223 | */ |
| 224 | 224 | public function setPropertyValues($property, $values) { |
| 225 | - $i = 0; |
|
| 226 | - if (\is_array($values) === false) { |
|
| 227 | - $values = \array_fill(0, $this->count(), $values); |
|
| 225 | + $i=0; |
|
| 226 | + if (\is_array($values)===false) { |
|
| 227 | + $values=\array_fill(0, $this->count(), $values); |
|
| 228 | 228 | } |
| 229 | 229 | foreach ($values as $value) { |
| 230 | - $c = $this->items[$i ++]; |
|
| 230 | + $c=$this->items[$i++]; |
|
| 231 | 231 | if (isset($c)) { |
| 232 | 232 | $c->setProperty($property, $value); |
| 233 | 233 | } else { |
@@ -261,12 +261,12 @@ discard block |
||
| 261 | 261 | * @param boolean $dropdown |
| 262 | 262 | */ |
| 263 | 263 | public function asDropdown($dropdown) { |
| 264 | - if ($dropdown === false) { |
|
| 265 | - $this->_template = include dirname(__FILE__) . '/../templates/tplDropdownMenu.php'; |
|
| 266 | - $dropdown = "menu"; |
|
| 264 | + if ($dropdown===false) { |
|
| 265 | + $this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php'; |
|
| 266 | + $dropdown="menu"; |
|
| 267 | 267 | } else { |
| 268 | - $dropdown = "dropdown"; |
|
| 269 | - $this->mClass = "menu"; |
|
| 268 | + $dropdown="dropdown"; |
|
| 269 | + $this->mClass="menu"; |
|
| 270 | 270 | } |
| 271 | 271 | return $this->addToPropertyCtrl("class", $dropdown, array( |
| 272 | 272 | "menu", |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | )); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - public function asButton($floating = false) { |
|
| 295 | + public function asButton($floating=false) { |
|
| 296 | 296 | $this->removeArrow(); |
| 297 | 297 | if ($floating) |
| 298 | 298 | $this->addToProperty("class", "floating"); |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | return $this->addToProperty("class", "button"); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - public function asSelect($name = NULL, $multiple = false, $selection = true) { |
|
| 304 | - $this->_multiple = $multiple; |
|
| 303 | + public function asSelect($name=NULL, $multiple=false, $selection=true) { |
|
| 304 | + $this->_multiple=$multiple; |
|
| 305 | 305 | if (isset($name)) |
| 306 | 306 | $this->addInput($name); |
| 307 | 307 | if ($multiple) { |
| 308 | 308 | $this->addToProperty("class", "multiple"); |
| 309 | 309 | } |
| 310 | 310 | if ($selection) { |
| 311 | - if ($this->propertyContains("class", "button") === false) |
|
| 311 | + if ($this->propertyContains("class", "button")===false) |
|
| 312 | 312 | $this->addToPropertyCtrl("class", "selection", array( |
| 313 | 313 | "selection" |
| 314 | 314 | )); |
@@ -316,31 +316,31 @@ discard block |
||
| 316 | 316 | return $this; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - public function asSearch($name = NULL, $multiple = false, $selection = true) { |
|
| 319 | + public function asSearch($name=NULL, $multiple=false, $selection=true) { |
|
| 320 | 320 | $this->asSelect($name, $multiple, $selection); |
| 321 | 321 | return $this->addToProperty("class", "search"); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - public function setSelect($name = NULL, $multiple = false) { |
|
| 325 | - $this->_template = '<%tagName% id="%identifier%" %properties%>%items%</%tagName%>'; |
|
| 326 | - if (! isset($name)) |
|
| 327 | - $name = "select-" . $this->identifier; |
|
| 328 | - $this->input = null; |
|
| 324 | + public function setSelect($name=NULL, $multiple=false) { |
|
| 325 | + $this->_template='<%tagName% id="%identifier%" %properties%>%items%</%tagName%>'; |
|
| 326 | + if (!isset($name)) |
|
| 327 | + $name="select-".$this->identifier; |
|
| 328 | + $this->input=null; |
|
| 329 | 329 | if ($multiple) { |
| 330 | 330 | $this->setProperty("multiple", true); |
| 331 | 331 | $this->addToProperty("class", "multiple"); |
| 332 | 332 | } |
| 333 | 333 | $this->setAction("activate"); |
| 334 | - $this->tagName = "select"; |
|
| 334 | + $this->tagName="select"; |
|
| 335 | 335 | $this->setProperty("name", $name); |
| 336 | - $this->content = null; |
|
| 336 | + $this->content=null; |
|
| 337 | 337 | foreach ($this->items as $item) { |
| 338 | 338 | $item->asOption(); |
| 339 | 339 | } |
| 340 | 340 | return $this; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - public function asSubmenu($pointing = NULL) { |
|
| 343 | + public function asSubmenu($pointing=NULL) { |
|
| 344 | 344 | $this->setClass("ui dropdown link item"); |
| 345 | 345 | if (isset($pointing)) { |
| 346 | 346 | $this->setPointing($pointing); |
@@ -348,29 +348,29 @@ discard block |
||
| 348 | 348 | return $this; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - public function setPointing($value = Direction::NONE) { |
|
| 352 | - return $this->addToPropertyCtrl("class", $value . " pointing", Direction::getConstantValues("pointing")); |
|
| 351 | + public function setPointing($value=Direction::NONE) { |
|
| 352 | + return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing")); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | public function setValue($value) { |
| 356 | - $this->value = $value; |
|
| 356 | + $this->value=$value; |
|
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | public function setDefaultText($text) { |
| 361 | - $this->content["text"] = new HtmlSemDoubleElement("", "div", "default text", $text); |
|
| 361 | + $this->content["text"]=new HtmlSemDoubleElement("", "div", "default text", $text); |
|
| 362 | 362 | return $this; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | private function applyValue() { |
| 366 | - $value = $this->value; |
|
| 366 | + $value=$this->value; |
|
| 367 | 367 | if (isset($this->input) && isset($value)) { |
| 368 | 368 | $this->input->setProperty("value", $value); |
| 369 | 369 | } else { |
| 370 | 370 | $this->setProperty("value", $value); |
| 371 | 371 | } |
| 372 | - $textElement = $this->getElementById("text-" . $this->identifier, $this->content); |
|
| 373 | - if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && ! $this->_multiple) |
|
| 372 | + $textElement=$this->getElementById("text-".$this->identifier, $this->content); |
|
| 373 | + if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple) |
|
| 374 | 374 | $textElement->setContent($value); |
| 375 | 375 | return $this; |
| 376 | 376 | } |
@@ -380,9 +380,9 @@ discard block |
||
| 380 | 380 | * @see BaseHtml::run() |
| 381 | 381 | */ |
| 382 | 382 | public function run(JsUtils $js) { |
| 383 | - if ($this->propertyContains("class", "simple") === false) { |
|
| 384 | - if (isset($this->_bsComponent) === false) { |
|
| 385 | - $this->_bsComponent = $js->semantic()->dropdown("#" . $this->identifier, $this->_params); |
|
| 383 | + if ($this->propertyContains("class", "simple")===false) { |
|
| 384 | + if (isset($this->_bsComponent)===false) { |
|
| 385 | + $this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier, $this->_params); |
|
| 386 | 386 | $this->_bsComponent->setItemSelector(".item"); |
| 387 | 387 | } |
| 388 | 388 | $this->addEventsOnRun($js); |
@@ -397,31 +397,31 @@ discard block |
||
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | public function setAction($action) { |
| 400 | - $this->_params["action"] = $action; |
|
| 400 | + $this->_params["action"]=$action; |
|
| 401 | 401 | return $this; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | public function setOn($on) { |
| 405 | - $this->_params["on"] = $on; |
|
| 405 | + $this->_params["on"]=$on; |
|
| 406 | 406 | return $this; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | public function setShowOnFocus($value) { |
| 410 | - $this->_params["showOnFocus"] = $value; |
|
| 410 | + $this->_params["showOnFocus"]=$value; |
|
| 411 | 411 | return $this; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | public function setAllowAdditions($value) { |
| 415 | - $this->_params["allowAdditions"] = $value; |
|
| 415 | + $this->_params["allowAdditions"]=$value; |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | public function setFullTextSearch($value) { |
| 420 | - $this->_params["fullTextSearch"] = $value; |
|
| 420 | + $this->_params["fullTextSearch"]=$value; |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - public function compile(JsUtils $js = NULL, &$view = NULL) { |
|
| 424 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 425 | 425 | $this->applyValue(); |
| 426 | 426 | return parent::compile($js, $view); |
| 427 | 427 | } |
@@ -430,19 +430,19 @@ discard block |
||
| 430 | 430 | return $this->input; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - public function setIcon($icon = "dropdown") { |
|
| 434 | - $this->content["arrow"] = new HtmlIcon($this->identifier . "-icon", $icon); |
|
| 433 | + public function setIcon($icon="dropdown") { |
|
| 434 | + $this->content["arrow"]=new HtmlIcon($this->identifier."-icon", $icon); |
|
| 435 | 435 | return $this; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - public function jsAddItem($caption, $value = null) { |
|
| 439 | - $value = $value ?? $caption; |
|
| 440 | - $js = "var first=$('#{$this->identifier} .item').first();if(first!=undefined){var newItem =first.clone();first.parent().append(newItem);newItem.html({$caption});newItem.attr('data-value',{$value}).removeClass('active filtered');}"; |
|
| 438 | + public function jsAddItem($caption, $value=null) { |
|
| 439 | + $value=$value ?? $caption; |
|
| 440 | + $js="var first=$('#{$this->identifier} .item').first();if(first!=undefined){var newItem =first.clone();first.parent().append(newItem);newItem.html({$caption});newItem.attr('data-value',{$value}).removeClass('active filtered');}"; |
|
| 441 | 441 | return $js; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | public function setClearable($value) { |
| 445 | - $this->_params["clearable"] = $value; |
|
| 445 | + $this->_params["clearable"]=$value; |
|
| 446 | 446 | return $this; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | * Parameters addedValue, addedText, $addedChoice |
| 452 | 452 | */ |
| 453 | 453 | public function setOnAdd($jsCode) { |
| 454 | - $this->_params["onAdd"] = $jsCode; |
|
| 454 | + $this->_params["onAdd"]=$jsCode; |
|
| 455 | 455 | return $this; |
| 456 | 456 | } |
| 457 | 457 | |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | * Parameters removedValue, removedText, $removedChoice |
| 461 | 461 | */ |
| 462 | 462 | public function setOnRemove($jsCode) { |
| 463 | - $this->_params["onRemove"] = $jsCode; |
|
| 463 | + $this->_params["onRemove"]=$jsCode; |
|
| 464 | 464 | return $this; |
| 465 | 465 | } |
| 466 | 466 | } |
@@ -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 | |
@@ -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 | |
@@ -58,26 +58,26 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | protected $_colWidths; |
| 60 | 60 | |
| 61 | - public function __construct($identifier, $model, $modelInstance = NULL) { |
|
| 61 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 62 | 62 | parent::__construct($identifier, $model, $modelInstance); |
| 63 | 63 | $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
| 64 | - $this->_urls = []; |
|
| 65 | - $this->_emptyMessage = new HtmlMessage("", "nothing to display"); |
|
| 64 | + $this->_urls=[]; |
|
| 65 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 66 | 66 | $this->_emptyMessage->setIcon("info circle"); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function run(JsUtils $js) { |
| 70 | - if ($this->_runned !== true) { |
|
| 71 | - $offset = $js->scriptCount(); |
|
| 70 | + if ($this->_runned!==true) { |
|
| 71 | + $offset=$js->scriptCount(); |
|
| 72 | 72 | if ($this->_hasCheckboxes && isset($js)) { |
| 73 | 73 | $this->_runCheckboxes($js); |
| 74 | 74 | } |
| 75 | 75 | if ($this->_visibleHover) { |
| 76 | - $js->execOn("mouseover", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [ |
|
| 76 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [ |
|
| 77 | 77 | "preventDefault" => false, |
| 78 | 78 | "stopPropagation" => true |
| 79 | 79 | ]); |
| 80 | - $js->execOn("mouseout", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [ |
|
| 80 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [ |
|
| 81 | 81 | "preventDefault" => false, |
| 82 | 82 | "stopPropagation" => true |
| 83 | 83 | ]); |
@@ -93,16 +93,16 @@ discard block |
||
| 93 | 93 | if (isset($this->_pagination)) |
| 94 | 94 | $this->_associatePaginationBehavior($js, $offset); |
| 95 | 95 | $this->_associateSearchFieldBehavior($js, $offset); |
| 96 | - $this->_runned = true; |
|
| 96 | + $this->_runned=true; |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | protected function _generateBehavior($op, $params, JsUtils $js) { |
| 101 | 101 | if (isset($this->_urls[$op])) { |
| 102 | - $params = \array_merge($params, [ |
|
| 102 | + $params=\array_merge($params, [ |
|
| 103 | 103 | "attr" => "data-ajax" |
| 104 | 104 | ]); |
| 105 | - $js->ajaxOnClick("#" . $this->identifier . " ._" . $op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 105 | + $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
@@ -121,21 +121,21 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function refreshTD($fieldName, $jquery, $view) { |
| 124 | - $index = $this->_getIndex($fieldName); |
|
| 124 | + $index=$this->_getIndex($fieldName); |
|
| 125 | 125 | $this->compile($jquery, $view); |
| 126 | 126 | return $this->refreshTR() |
| 127 | 127 | ->getTable() |
| 128 | 128 | ->getCell(0, $index); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function compile(JsUtils $js = NULL, &$view = NULL) { |
|
| 132 | - if (! $this->_generated) { |
|
| 131 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 132 | + if (!$this->_generated) { |
|
| 133 | 133 | if (isset($this->_buttonsColumn)) { |
| 134 | 134 | $this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons); |
| 135 | 135 | } |
| 136 | 136 | $this->_instanceViewer->setInstance($this->_model); |
| 137 | - $captions = $this->_instanceViewer->getCaptions(); |
|
| 138 | - $table = $this->content["table"]; |
|
| 137 | + $captions=$this->_instanceViewer->getCaptions(); |
|
| 138 | + $table=$this->content["table"]; |
|
| 139 | 139 | if ($this->_hasCheckboxes) { |
| 140 | 140 | $this->_generateMainCheckbox($captions); |
| 141 | 141 | } |
@@ -150,14 +150,14 @@ discard block |
||
| 150 | 150 | $this->compileExtraElements($table, $captions); |
| 151 | 151 | $this->_compileSearchFieldBehavior($js); |
| 152 | 152 | |
| 153 | - $this->content = JArray::sortAssociative($this->content, [ |
|
| 153 | + $this->content=JArray::sortAssociative($this->content, [ |
|
| 154 | 154 | PositionInTable::BEFORETABLE, |
| 155 | 155 | "table", |
| 156 | 156 | PositionInTable::AFTERTABLE |
| 157 | 157 | ]); |
| 158 | 158 | $this->_compileForm(); |
| 159 | 159 | $this->_applyStyleAttributes($table); |
| 160 | - $this->_generated = true; |
|
| 160 | + $this->_generated=true; |
|
| 161 | 161 | } |
| 162 | 162 | return parent::compile($js, $view); |
| 163 | 163 | } |
@@ -202,21 +202,21 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | protected function _generateContent($table) { |
| 205 | - $objects = $this->_modelInstance; |
|
| 205 | + $objects=$this->_modelInstance; |
|
| 206 | 206 | if (isset($this->_pagination)) { |
| 207 | - $objects = $this->_pagination->getObjects($this->_modelInstance); |
|
| 207 | + $objects=$this->_pagination->getObjects($this->_modelInstance); |
|
| 208 | 208 | } |
| 209 | 209 | InstanceViewer::setIndex(0); |
| 210 | - $fields = $this->_instanceViewer->getSimpleProperties(); |
|
| 211 | - $groupByFields = $this->_instanceViewer->getGroupByFields(); |
|
| 212 | - if (! is_array($groupByFields)) { |
|
| 213 | - $table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields) { |
|
| 210 | + $fields=$this->_instanceViewer->getSimpleProperties(); |
|
| 211 | + $groupByFields=$this->_instanceViewer->getGroupByFields(); |
|
| 212 | + if (!is_array($groupByFields)) { |
|
| 213 | + $table->fromDatabaseObjects($objects, function($instance) use ($table, $fields) { |
|
| 214 | 214 | return $this->_generateRow($instance, $fields, $table); |
| 215 | 215 | }); |
| 216 | 216 | } else { |
| 217 | - $activeValues = array_combine($groupByFields, array_fill(0, sizeof($groupByFields), null)); |
|
| 218 | - $uuids = []; |
|
| 219 | - $table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids) { |
|
| 217 | + $activeValues=array_combine($groupByFields, array_fill(0, sizeof($groupByFields), null)); |
|
| 218 | + $uuids=[]; |
|
| 219 | + $table->fromDatabaseObjects($objects, function($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids) { |
|
| 220 | 220 | $this->_instanceViewer->setInstance($instance); |
| 221 | 221 | foreach ($groupByFields as $index => $gbField) { |
| 222 | 222 | $this->_generateGroupByRow($index, $gbField, $table, $fields, $activeValues, $uuids); |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | return $this->_generateRow($instance, $fields, $table, null, $uuids); |
| 225 | 225 | }); |
| 226 | 226 | } |
| 227 | - if ($table->getRowCount() == 0) { |
|
| 228 | - $result = $table->addRow(); |
|
| 227 | + if ($table->getRowCount()==0) { |
|
| 228 | + $result=$table->addRow(); |
|
| 229 | 229 | $result->mergeRow(); |
| 230 | 230 | $result->setValues([ |
| 231 | 231 | $this->_emptyMessage |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | protected function _generateGroupByRow($index, $gbField, $table, $fields, &$activeValues, &$uuids) { |
| 237 | - $newValue = $this->_instanceViewer->getValue($gbField); |
|
| 238 | - if ($this->getElementContent($activeValues[$gbField]) !== $this->getElementContent($newValue)) { |
|
| 239 | - if ($index == 0) { |
|
| 240 | - $uuids = []; |
|
| 237 | + $newValue=$this->_instanceViewer->getValue($gbField); |
|
| 238 | + if ($this->getElementContent($activeValues[$gbField])!==$this->getElementContent($newValue)) { |
|
| 239 | + if ($index==0) { |
|
| 240 | + $uuids=[]; |
|
| 241 | 241 | } |
| 242 | - $uuid = uniqid("grp"); |
|
| 243 | - $uuids[$gbField] = $uuid; |
|
| 244 | - $id = $this->_instanceViewer->getIdentifier(); |
|
| 245 | - $result = $table->addMergeRow(sizeof($fields) + 1, $newValue); |
|
| 246 | - $result->setIdentifier($this->identifier . "-tr-gb-" . $id); |
|
| 242 | + $uuid=uniqid("grp"); |
|
| 243 | + $uuids[$gbField]=$uuid; |
|
| 244 | + $id=$this->_instanceViewer->getIdentifier(); |
|
| 245 | + $result=$table->addMergeRow(sizeof($fields)+1, $newValue); |
|
| 246 | + $result->setIdentifier($this->identifier."-tr-gb-".$id); |
|
| 247 | 247 | $result->setProperty("data-ajax", $id); |
| 248 | 248 | $result->setProperty("data-group", $uuid); |
| 249 | 249 | $result->addToProperty("class", $this->_rowClass); |
| 250 | - $activeValues[$gbField] = $newValue; |
|
| 250 | + $activeValues[$gbField]=$newValue; |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | public function getFieldValue($index) { |
| 262 | - $index = $this->_getIndex($index); |
|
| 262 | + $index=$this->_getIndex($index); |
|
| 263 | 263 | if (is_numeric($index)) { |
| 264 | - $values = $this->_instanceViewer->getValues(); |
|
| 264 | + $values=$this->_instanceViewer->getValues(); |
|
| 265 | 265 | if (isset($values[$index])) { |
| 266 | 266 | return $values[$index]; |
| 267 | 267 | } |
@@ -269,31 +269,31 @@ discard block |
||
| 269 | 269 | return null; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - protected function _generateRow($instance, $fields, &$table, $checkedClass = null, $uuids = null) { |
|
| 272 | + protected function _generateRow($instance, $fields, &$table, $checkedClass=null, $uuids=null) { |
|
| 273 | 273 | $this->_instanceViewer->setInstance($instance); |
| 274 | - InstanceViewer::$index ++; |
|
| 275 | - $values = $this->_instanceViewer->getValues(); |
|
| 276 | - $id = $this->_instanceViewer->getIdentifier(); |
|
| 277 | - $dataAjax = $id; |
|
| 278 | - $id = $this->cleanIdentifier($id); |
|
| 274 | + InstanceViewer::$index++; |
|
| 275 | + $values=$this->_instanceViewer->getValues(); |
|
| 276 | + $id=$this->_instanceViewer->getIdentifier(); |
|
| 277 | + $dataAjax=$id; |
|
| 278 | + $id=$this->cleanIdentifier($id); |
|
| 279 | 279 | if ($this->_hasCheckboxes) { |
| 280 | - $ck = new HtmlCheckbox("ck-" . $this->identifier . "-" . $id, ""); |
|
| 281 | - $checked = false; |
|
| 280 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
| 281 | + $checked=false; |
|
| 282 | 282 | if (isset($this->_checkedCallback)) { |
| 283 | - $func = $this->_checkedCallback; |
|
| 284 | - $checked = $func($instance); |
|
| 283 | + $func=$this->_checkedCallback; |
|
| 284 | + $checked=$func($instance); |
|
| 285 | 285 | } |
| 286 | 286 | $ck->setChecked($checked); |
| 287 | 287 | // $ck->setOnChange("event.stopPropagation();"); |
| 288 | - $field = $ck->getField(); |
|
| 288 | + $field=$ck->getField(); |
|
| 289 | 289 | $field->setProperty("value", $dataAjax); |
| 290 | 290 | $field->setProperty("name", "selection[]"); |
| 291 | 291 | if (isset($checkedClass)) |
| 292 | 292 | $field->setClass($checkedClass); |
| 293 | 293 | \array_unshift($values, $ck); |
| 294 | 294 | } |
| 295 | - $result = $table->newRow(); |
|
| 296 | - $result->setIdentifier($this->identifier . "-tr-" . $id); |
|
| 295 | + $result=$table->newRow(); |
|
| 296 | + $result->setIdentifier($this->identifier."-tr-".$id); |
|
| 297 | 297 | $result->setProperty("data-ajax", $dataAjax); |
| 298 | 298 | $result->setValues($values); |
| 299 | 299 | $result->addToProperty("class", $this->_rowClass); |
@@ -306,62 +306,62 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | protected function _generatePagination($table) { |
| 308 | 308 | if (isset($this->_toolbar)) { |
| 309 | - if ($this->_toolbarPosition == PositionInTable::FOOTER) |
|
| 309 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 310 | 310 | $this->_toolbar->setFloated("left"); |
| 311 | 311 | } |
| 312 | - $footer = $table->getFooter(); |
|
| 312 | + $footer=$table->getFooter(); |
|
| 313 | 313 | $footer->mergeCol(); |
| 314 | 314 | $footer->addValues($this->_pagination->generateMenu($this->identifier)); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - protected function _associatePaginationBehavior(JsUtils $js = NULL, $offset = null) { |
|
| 317 | + protected function _associatePaginationBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 318 | 318 | if (isset($this->_urls["refresh"])) { |
| 319 | - $menu = $this->_pagination->getMenu(); |
|
| 319 | + $menu=$this->_pagination->getMenu(); |
|
| 320 | 320 | if (isset($menu) && isset($js)) { |
| 321 | - $js->postOnClick("#" . $menu->getIdentifier() . " .item", $this->_urls["refresh"], "{'p':$(this).attr('data-page'),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", $this->getRefreshSelector(), [ |
|
| 321 | + $js->postOnClick("#".$menu->getIdentifier()." .item", $this->_urls["refresh"], "{'p':$(this).attr('data-page'),'_model':'".JString::doubleBackSlashes($this->_model)."'}", $this->getRefreshSelector(), [ |
|
| 322 | 322 | "preventDefault" => false, |
| 323 | 323 | "jqueryDone" => "replaceWith", |
| 324 | 324 | "hasLoader" => false, |
| 325 | - "jsCallback" => '$("#' . $this->identifier . '").trigger("pageChange");$("#' . $this->identifier . '").trigger("activeRowChange");' |
|
| 325 | + "jsCallback" => '$("#'.$this->identifier.'").trigger("pageChange");$("#'.$this->identifier.'").trigger("activeRowChange");' |
|
| 326 | 326 | ]); |
| 327 | - $page = $_POST["p"] ?? null; |
|
| 327 | + $page=$_POST["p"] ?? null; |
|
| 328 | 328 | if (isset($page)) { |
| 329 | - $js->execAtLast('$("#' . $this->getIdentifier() . ' .pagination").children("a.item").removeClass("active");$("#' . $this->getIdentifier() . ' .pagination").children("a.item[data-page=' . $page . ']:not(.no-active)").addClass("active");'); |
|
| 329 | + $js->execAtLast('$("#'.$this->getIdentifier().' .pagination").children("a.item").removeClass("active");$("#'.$this->getIdentifier().' .pagination").children("a.item[data-page='.$page.']:not(.no-active)").addClass("active");'); |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - protected function _compileSearchFieldBehavior(JsUtils $js = NULL) { |
|
| 335 | + protected function _compileSearchFieldBehavior(JsUtils $js=NULL) { |
|
| 336 | 336 | if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
| 337 | - $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val(),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", "#" . $this->identifier . " tbody", [ |
|
| 337 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val(),'_model':'".JString::doubleBackSlashes($this->_model)."'}", "#".$this->identifier." tbody", [ |
|
| 338 | 338 | "preventDefault" => false, |
| 339 | 339 | "jqueryDone" => "replaceWith", |
| 340 | 340 | "hasLoader" => "internal", |
| 341 | - "jsCallback" => '$("#' . $this->identifier . '").trigger("searchTerminate",[$(self).val()]);' |
|
| 341 | + "jsCallback" => '$("#'.$this->identifier.'").trigger("searchTerminate",[$(self).val()]);' |
|
| 342 | 342 | ]); |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - protected function _associateSearchFieldBehavior(JsUtils $js = NULL, $offset = null) {} |
|
| 346 | + protected function _associateSearchFieldBehavior(JsUtils $js=NULL, $offset=null) {} |
|
| 347 | 347 | |
| 348 | 348 | protected function _getFieldName($index) { |
| 349 | - $fieldName = parent::_getFieldName($index); |
|
| 349 | + $fieldName=parent::_getFieldName($index); |
|
| 350 | 350 | if (\is_object($fieldName)) |
| 351 | - $fieldName = "field-" . $index; |
|
| 352 | - return $fieldName . "[]"; |
|
| 351 | + $fieldName="field-".$index; |
|
| 352 | + return $fieldName."[]"; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | protected function _getFieldCaption($index) { |
| 356 | 356 | return null; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - protected function _setToolbarPosition($table, $captions = NULL) { |
|
| 359 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 360 | 360 | switch ($this->_toolbarPosition) { |
| 361 | 361 | case PositionInTable::BEFORETABLE: |
| 362 | 362 | case PositionInTable::AFTERTABLE: |
| 363 | - if (isset($this->_compileParts) === false) { |
|
| 364 | - $this->content[$this->_toolbarPosition] = $this->_toolbar; |
|
| 363 | + if (isset($this->_compileParts)===false) { |
|
| 364 | + $this->content[$this->_toolbarPosition]=$this->_toolbar; |
|
| 365 | 365 | } |
| 366 | 366 | break; |
| 367 | 367 | case PositionInTable::HEADER: |
@@ -388,11 +388,11 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | private function addToolbarRow($part, $table, $captions) { |
| 391 | - $hasPart = $table->hasPart($part); |
|
| 391 | + $hasPart=$table->hasPart($part); |
|
| 392 | 392 | if ($hasPart) { |
| 393 | - $row = $table->getPart($part)->addRow(\sizeof($captions)); |
|
| 393 | + $row=$table->getPart($part)->addRow(\sizeof($captions)); |
|
| 394 | 394 | } else { |
| 395 | - $row = $table->getPart($part)->getRow(0); |
|
| 395 | + $row=$table->getPart($part)->getRow(0); |
|
| 396 | 396 | } |
| 397 | 397 | $row->mergeCol(); |
| 398 | 398 | $row->setValues([ |
@@ -424,12 +424,12 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | public function setUrls($urls) { |
| 426 | 426 | if (\is_array($urls)) { |
| 427 | - $this->_urls["refresh"] = JArray::getValue($urls, "refresh", 0); |
|
| 428 | - $this->_urls["edit"] = JArray::getValue($urls, "edit", 1); |
|
| 429 | - $this->_urls["delete"] = JArray::getValue($urls, "delete", 2); |
|
| 430 | - $this->_urls["display"] = JArray::getValue($urls, "display", 3); |
|
| 427 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 428 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 429 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 430 | + $this->_urls["display"]=JArray::getValue($urls, "display", 3); |
|
| 431 | 431 | } else { |
| 432 | - $this->_urls = [ |
|
| 432 | + $this->_urls=[ |
|
| 433 | 433 | "refresh" => $urls, |
| 434 | 434 | "edit" => $urls, |
| 435 | 435 | "delete" => $urls, |
@@ -452,8 +452,8 @@ discard block |
||
| 452 | 452 | * The number of visible pages in the Pagination component |
| 453 | 453 | * @return DataTable |
| 454 | 454 | */ |
| 455 | - public function paginate($page, $total_rowcount, $items_per_page = 10, $pages_visibles = null) { |
|
| 456 | - $this->_pagination = new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 455 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 456 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 457 | 457 | return $this; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | * The number of visible pages in the Pagination component |
| 469 | 469 | * @return DataTable |
| 470 | 470 | */ |
| 471 | - public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles = 4) { |
|
| 472 | - $this->_pagination = new Pagination($items_per_page, $pages_visibles, $page); |
|
| 471 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 472 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 473 | 473 | return $this; |
| 474 | 474 | } |
| 475 | 475 | |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | * @param array $compileParts |
| 479 | 479 | * @return DataTable |
| 480 | 480 | */ |
| 481 | - public function refresh($compileParts = [ |
|
| 481 | + public function refresh($compileParts=[ |
|
| 482 | 482 | "tbody" |
| 483 | 483 | ]) { |
| 484 | - $this->_compileParts = $compileParts; |
|
| 484 | + $this->_compileParts=$compileParts; |
|
| 485 | 485 | return $this; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -491,14 +491,14 @@ discard block |
||
| 491 | 491 | * @param string $position |
| 492 | 492 | * @return \Ajax\common\html\HtmlDoubleElement |
| 493 | 493 | */ |
| 494 | - public function addSearchInToolbar($position = Direction::RIGHT) { |
|
| 494 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 495 | 495 | return $this->addInToolbar($this->getSearchField()) |
| 496 | 496 | ->setPosition($position); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | public function getSearchField() { |
| 500 | - if (isset($this->_searchField) === false) { |
|
| 501 | - $this->_searchField = new HtmlInput("search-" . $this->identifier, "search", "", "Search..."); |
|
| 500 | + if (isset($this->_searchField)===false) { |
|
| 501 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 502 | 502 | $this->_searchField->addIcon("search", Direction::RIGHT); |
| 503 | 503 | } |
| 504 | 504 | return $this->_searchField; |
@@ -526,9 +526,9 @@ discard block |
||
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | protected function getTargetSelector($op) { |
| 529 | - $result = $this->_targetSelector; |
|
| 530 | - if (! isset($result[$op])) |
|
| 531 | - $result = "#" . $this->identifier; |
|
| 529 | + $result=$this->_targetSelector; |
|
| 530 | + if (!isset($result[$op])) |
|
| 531 | + $result="#".$this->identifier; |
|
| 532 | 532 | return $result[$op]; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -540,20 +540,20 @@ discard block |
||
| 540 | 540 | * @return DataTable |
| 541 | 541 | */ |
| 542 | 542 | public function setTargetSelector($_targetSelector) { |
| 543 | - if (! \is_array($_targetSelector)) { |
|
| 544 | - $_targetSelector = [ |
|
| 543 | + if (!\is_array($_targetSelector)) { |
|
| 544 | + $_targetSelector=[ |
|
| 545 | 545 | "edit" => $_targetSelector, |
| 546 | 546 | "delete" => $_targetSelector |
| 547 | 547 | ]; |
| 548 | 548 | } |
| 549 | - $this->_targetSelector = $_targetSelector; |
|
| 549 | + $this->_targetSelector=$_targetSelector; |
|
| 550 | 550 | return $this; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | public function getRefreshSelector() { |
| 554 | 554 | if (isset($this->_refreshSelector)) |
| 555 | 555 | return $this->_refreshSelector; |
| 556 | - return "#" . $this->identifier . " tbody"; |
|
| 556 | + return "#".$this->identifier." tbody"; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @return DataTable |
| 563 | 563 | */ |
| 564 | 564 | public function setRefreshSelector($_refreshSelector) { |
| 565 | - $this->_refreshSelector = $_refreshSelector; |
|
| 565 | + $this->_refreshSelector=$_refreshSelector; |
|
| 566 | 566 | return $this; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | public function show($modelInstance) { |
| 575 | 575 | if (\is_array($modelInstance)) { |
| 576 | 576 | if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
| 577 | - $modelInstance = \json_decode(\json_encode($modelInstance), FALSE); |
|
| 577 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 578 | 578 | } |
| 579 | - $this->_modelInstance = $modelInstance; |
|
| 579 | + $this->_modelInstance=$modelInstance; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | public function getRowClass() { |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @return DataTable |
| 591 | 591 | */ |
| 592 | 592 | public function setRowClass($_rowClass) { |
| 593 | - $this->_rowClass = $_rowClass; |
|
| 593 | + $this->_rowClass=$_rowClass; |
|
| 594 | 594 | return $this; |
| 595 | 595 | } |
| 596 | 596 | |
@@ -601,34 +601,34 @@ discard block |
||
| 601 | 601 | * @return DataTable |
| 602 | 602 | */ |
| 603 | 603 | public function setEmptyMessage($_emptyMessage) { |
| 604 | - $this->_emptyMessage = $_emptyMessage; |
|
| 604 | + $this->_emptyMessage=$_emptyMessage; |
|
| 605 | 605 | return $this; |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - public function setSortable($colIndex = NULL) { |
|
| 609 | - $this->_sortable = $colIndex; |
|
| 608 | + public function setSortable($colIndex=NULL) { |
|
| 609 | + $this->_sortable=$colIndex; |
|
| 610 | 610 | return $this; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - public function setActiveRowSelector($class = "active", $event = "click", $multiple = false) { |
|
| 613 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 614 | 614 | $this->_self->setActiveRowSelector($class, $event, $multiple); |
| 615 | 615 | return $this; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | public function hideColumn($colIndex) { |
| 619 | - if (! \is_array($this->_hiddenColumns)) |
|
| 620 | - $this->_hiddenColumns = []; |
|
| 621 | - $this->_hiddenColumns[] = $colIndex; |
|
| 619 | + if (!\is_array($this->_hiddenColumns)) |
|
| 620 | + $this->_hiddenColumns=[]; |
|
| 621 | + $this->_hiddenColumns[]=$colIndex; |
|
| 622 | 622 | return $this; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | public function setColWidth($colIndex, $width) { |
| 626 | - $this->_colWidths[$colIndex] = $width; |
|
| 626 | + $this->_colWidths[$colIndex]=$width; |
|
| 627 | 627 | return $this; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | public function setColWidths($_colWidths) { |
| 631 | - $this->_colWidths = $_colWidths; |
|
| 631 | + $this->_colWidths=$_colWidths; |
|
| 632 | 632 | return $this; |
| 633 | 633 | } |
| 634 | 634 | |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | return $this; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - public function trigger($event, $params = "[]") { |
|
| 640 | + public function trigger($event, $params="[]") { |
|
| 641 | 641 | return $this->getHtmlComponent()->trigger($event, $params); |
| 642 | 642 | } |
| 643 | 643 | |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * @param mixed $_displayBehavior |
| 676 | 676 | */ |
| 677 | 677 | public function setDisplayBehavior($_displayBehavior) { |
| 678 | - $this->_displayBehavior = $_displayBehavior; |
|
| 678 | + $this->_displayBehavior=$_displayBehavior; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -699,6 +699,6 @@ discard block |
||
| 699 | 699 | * @param boolean $_visibleHover |
| 700 | 700 | */ |
| 701 | 701 | public function setVisibleHover($_visibleHover) { |
| 702 | - $this->_visibleHover = $_visibleHover; |
|
| 702 | + $this->_visibleHover=$_visibleHover; |
|
| 703 | 703 | } |
| 704 | 704 | } |
@@ -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 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @property array $jquery_code_for_compile |
| 11 | 11 | */ |
| 12 | 12 | trait JsUtilsEventsTrait { |
| 13 | - protected $jquery_events = array ( |
|
| 13 | + protected $jquery_events=array( |
|
| 14 | 14 | "bind", |
| 15 | 15 | "blur", |
| 16 | 16 | "change", |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | "undelegate", |
| 51 | 51 | "unload" |
| 52 | 52 | ); |
| 53 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
| 53 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Outputs a javascript library blur event |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * code to execute |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function blur($element = 'this', $js = '') { |
|
| 65 | - return $this->_add_event ( $element, $js, 'blur' ); |
|
| 64 | + public function blur($element='this', $js='') { |
|
| 65 | + return $this->_add_event($element, $js, 'blur'); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @param boolean $stopPropagation |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - public function change($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
| 80 | - return $this->_add_event ( $element, $js, 'change', $preventDefault, $stopPropagation ); |
|
| 79 | + public function change($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
| 80 | + return $this->_add_event($element, $js, 'change', $preventDefault, $stopPropagation); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -93,18 +93,18 @@ discard block |
||
| 93 | 93 | * @param boolean $stopPropagation |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - public function click($element = 'this', $js = '', $ret_false = TRUE, $preventDefault = false, $stopPropagation = false) { |
|
| 97 | - if (! is_array ( $js )) { |
|
| 98 | - $js = array ( |
|
| 96 | + public function click($element='this', $js='', $ret_false=TRUE, $preventDefault=false, $stopPropagation=false) { |
|
| 97 | + if (!is_array($js)) { |
|
| 98 | + $js=array( |
|
| 99 | 99 | $js |
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ($ret_false) { |
| 104 | - $js [] = "return false;"; |
|
| 104 | + $js []="return false;"; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return $this->_add_event ( $element, $js, 'click', $preventDefault, $stopPropagation ); |
|
| 107 | + return $this->_add_event($element, $js, 'click', $preventDefault, $stopPropagation); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | * code to execute |
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | - public function contextmenu($element = 'this', $js = '') { |
|
| 120 | - return $this->_add_event ( $element, $js, 'contextmenu' ); |
|
| 119 | + public function contextmenu($element='this', $js='') { |
|
| 120 | + return $this->_add_event($element, $js, 'contextmenu'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * code to execute |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - public function dblclick($element = 'this', $js = '') { |
|
| 133 | - return $this->_add_event ( $element, $js, 'dblclick' ); |
|
| 132 | + public function dblclick($element='this', $js='') { |
|
| 133 | + return $this->_add_event($element, $js, 'dblclick'); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | * code to execute |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function error($element = 'this', $js = '') { |
|
| 146 | - return $this->_add_event ( $element, $js, 'error' ); |
|
| 145 | + public function error($element='this', $js='') { |
|
| 146 | + return $this->_add_event($element, $js, 'error'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | * code to execute |
| 156 | 156 | * @return string |
| 157 | 157 | */ |
| 158 | - public function focus($element = 'this', $js = '') { |
|
| 159 | - return $this->_add_event ( $element, $js, 'focus' ); |
|
| 158 | + public function focus($element='this', $js='') { |
|
| 159 | + return $this->_add_event($element, $js, 'focus'); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * code for mouse out |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - public function hover($element = 'this', $over = '', $out = '') { |
|
| 173 | - $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"; |
|
| 174 | - $this->jquery_code_for_compile [] = $event; |
|
| 172 | + public function hover($element='this', $over='', $out='') { |
|
| 173 | + $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"; |
|
| 174 | + $this->jquery_code_for_compile []=$event; |
|
| 175 | 175 | return $event; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | * code to execute |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public function keydown($element = 'this', $js = '') { |
|
| 188 | - return $this->_add_event ( $element, $js, 'keydown' ); |
|
| 187 | + public function keydown($element='this', $js='') { |
|
| 188 | + return $this->_add_event($element, $js, 'keydown'); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | * code to execute |
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | - public function keypress($element = 'this', $js = '') { |
|
| 201 | - return $this->_add_event ( $element, $js, 'keypress' ); |
|
| 200 | + public function keypress($element='this', $js='') { |
|
| 201 | + return $this->_add_event($element, $js, 'keypress'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * code to execute |
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | - public function keyup($element = 'this', $js = '') { |
|
| 214 | - return $this->_add_event ( $element, $js, 'keyup' ); |
|
| 213 | + public function keyup($element='this', $js='') { |
|
| 214 | + return $this->_add_event($element, $js, 'keyup'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * code to execute |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - public function load($element = 'this', $js = '') { |
|
| 227 | - return $this->_add_event ( $element, $js, 'load' ); |
|
| 226 | + public function load($element='this', $js='') { |
|
| 227 | + return $this->_add_event($element, $js, 'load'); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -236,8 +236,8 @@ discard block |
||
| 236 | 236 | * code to execute |
| 237 | 237 | * @return string |
| 238 | 238 | */ |
| 239 | - public function mousedown($element = 'this', $js = '') { |
|
| 240 | - return $this->_add_event ( $element, $js, 'mousedown' ); |
|
| 239 | + public function mousedown($element='this', $js='') { |
|
| 240 | + return $this->_add_event($element, $js, 'mousedown'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * code to execute |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function mouseout($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
| 253 | - return $this->_add_event ( $element, $js, 'mouseout', $preventDefault, $stopPropagation ); |
|
| 252 | + public function mouseout($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
| 253 | + return $this->_add_event($element, $js, 'mouseout', $preventDefault, $stopPropagation); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | * code to execute |
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | - public function mouseleave($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
| 266 | - return $this->_add_event ( $element, $js, 'mouseleave', $preventDefault, $stopPropagation ); |
|
| 265 | + public function mouseleave($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
| 266 | + return $this->_add_event($element, $js, 'mouseleave', $preventDefault, $stopPropagation); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | * code to execute |
| 276 | 276 | * @return string |
| 277 | 277 | */ |
| 278 | - public function mouseenter($element = 'this', $js = '', $preventDefault = false, $stopPropagation = false) { |
|
| 279 | - return $this->_add_event ( $element, $js, 'mouseenter', $preventDefault, $stopPropagation ); |
|
| 278 | + public function mouseenter($element='this', $js='', $preventDefault=false, $stopPropagation=false) { |
|
| 279 | + return $this->_add_event($element, $js, 'mouseenter', $preventDefault, $stopPropagation); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | * code to execute |
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | - public function mouseover($element = 'this', $js = '') { |
|
| 292 | - return $this->_add_event ( $element, $js, 'mouseover' ); |
|
| 291 | + public function mouseover($element='this', $js='') { |
|
| 292 | + return $this->_add_event($element, $js, 'mouseover'); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * code to execute |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function mouseup($element = 'this', $js = '') { |
|
| 305 | - return $this->_add_event ( $element, $js, 'mouseup' ); |
|
| 304 | + public function mouseup($element='this', $js='') { |
|
| 305 | + return $this->_add_event($element, $js, 'mouseup'); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | * code to execute |
| 315 | 315 | * @return string |
| 316 | 316 | */ |
| 317 | - public function unload($element = 'this', $js = '') { |
|
| 318 | - return $this->_add_event ( $element, $js, 'unload' ); |
|
| 317 | + public function unload($element='this', $js='') { |
|
| 318 | + return $this->_add_event($element, $js, 'unload'); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | // -------------------------------------------------------------------- |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | * code to execute |
| 329 | 329 | * @return string |
| 330 | 330 | */ |
| 331 | - public function resize($element = 'this', $js = '') { |
|
| 332 | - return $this->_add_event ( $element, $js, 'resize' ); |
|
| 331 | + public function resize($element='this', $js='') { |
|
| 332 | + return $this->_add_event($element, $js, 'resize'); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // -------------------------------------------------------------------- |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * code to execute |
| 343 | 343 | * @return string |
| 344 | 344 | */ |
| 345 | - public function scroll($element = 'this', $js = '') { |
|
| 346 | - return $this->_add_event ( $element, $js, 'scroll' ); |
|
| 345 | + public function scroll($element='this', $js='') { |
|
| 346 | + return $this->_add_event($element, $js, 'scroll'); |
|
| 347 | 347 | } |
| 348 | 348 | } |
@@ -14,210 +14,210 @@ 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); |
|
| 20 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 21 | - protected function _ajax($method, $url, $responseElement = "", $parameters = [ ]) { |
|
| 22 | - if (isset ( $this->params ["ajax"] )) { |
|
| 23 | - extract ( $this->params ["ajax"] ); |
|
| 24 | - } |
|
| 25 | - extract ( $parameters ); |
|
| 26 | - |
|
| 27 | - $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
| 28 | - $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
| 29 | - $originalSelector = $responseElement; |
|
| 30 | - $responseElement = $this->_getResponseElement ( $responseElement ); |
|
| 31 | - $retour .= "var self=this;\n"; |
|
| 32 | - $before = isset ( $before ) ? $before : ""; |
|
| 33 | - $retour .= $before; |
|
| 34 | - if ($hasLoader === true && JString::isNotNull ( $responseElement )) { |
|
| 35 | - $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 36 | - } elseif ($hasLoader === 'response') { |
|
| 37 | - $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 38 | - } elseif ($hasLoader === 'internal') { |
|
| 39 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 40 | - } |
|
| 41 | - $ajaxParameters = [ |
|
| 19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 20 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 21 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 22 | + if (isset ($this->params ["ajax"])) { |
|
| 23 | + extract($this->params ["ajax"]); |
|
| 24 | + } |
|
| 25 | + extract($parameters); |
|
| 26 | + |
|
| 27 | + $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
| 28 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 29 | + $originalSelector=$responseElement; |
|
| 30 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 31 | + $retour.="var self=this;\n"; |
|
| 32 | + $before=isset ($before) ? $before : ""; |
|
| 33 | + $retour.=$before; |
|
| 34 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 35 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 36 | + } elseif ($hasLoader==='response') { |
|
| 37 | + $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
| 38 | + } elseif ($hasLoader==='internal') { |
|
| 39 | + $retour.="\n$(this).addClass('loading');"; |
|
| 40 | + } |
|
| 41 | + $ajaxParameters=[ |
|
| 42 | 42 | "url" => "url", |
| 43 | - "method" => "'" . \strtoupper ( $method ) . "'" |
|
| 43 | + "method" => "'".\strtoupper($method)."'" |
|
| 44 | 44 | ]; |
| 45 | 45 | |
| 46 | - $ajaxParameters ["async"] = ($async ? "true" : "false"); |
|
| 46 | + $ajaxParameters ["async"]=($async ? "true" : "false"); |
|
| 47 | 47 | |
| 48 | - if (isset ( $params )) { |
|
| 49 | - $ajaxParameters ["data"] = self::_correctParams ( $params, $parameters ); |
|
| 48 | + if (isset ($params)) { |
|
| 49 | + $ajaxParameters ["data"]=self::_correctParams($params, $parameters); |
|
| 50 | 50 | } |
| 51 | - if (isset ( $headers )) { |
|
| 52 | - $ajaxParameters ["headers"] = $headers; |
|
| 51 | + if (isset ($headers)) { |
|
| 52 | + $ajaxParameters ["headers"]=$headers; |
|
| 53 | 53 | } |
| 54 | - if (isset ( $partial )) { |
|
| 55 | - $ajaxParameters ["xhr"] = "xhrProvider"; |
|
| 56 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 54 | + if (isset ($partial)) { |
|
| 55 | + $ajaxParameters ["xhr"]="xhrProvider"; |
|
| 56 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 57 | 57 | } |
| 58 | - $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
| 59 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 60 | - $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n"; |
|
| 58 | + $this->createAjaxParameters($ajaxParameters, $parameters); |
|
| 59 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 60 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 61 | 61 | |
| 62 | - $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
| 62 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 63 | 63 | if ($immediatly) |
| 64 | - $this->jquery_code_for_compile [] = $retour; |
|
| 64 | + $this->jquery_code_for_compile []=$retour; |
|
| 65 | 65 | return $retour; |
| 66 | 66 | } |
| 67 | 67 | protected function createAjaxParameters(&$original, $parameters) { |
| 68 | - $validParameters = [ |
|
| 68 | + $validParameters=[ |
|
| 69 | 69 | "contentType" => "%value%", |
| 70 | 70 | "dataType" => "'%value%'", |
| 71 | 71 | "beforeSend" => "function(jqXHR,settings){%value%}", |
| 72 | 72 | "complete" => "function(jqXHR){%value%}", |
| 73 | 73 | "processData" => "%value%" |
| 74 | 74 | ]; |
| 75 | - foreach ( $validParameters as $param => $mask ) { |
|
| 76 | - if (isset ( $parameters [$param] )) { |
|
| 77 | - $original [$param] = \str_replace ( "%value%", $parameters [$param], $mask ); |
|
| 75 | + foreach ($validParameters as $param => $mask) { |
|
| 76 | + if (isset ($parameters [$param])) { |
|
| 77 | + $original [$param]=\str_replace("%value%", $parameters [$param], $mask); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | protected function implodeAjaxParameters($ajaxParameters) { |
| 82 | - $s = ''; |
|
| 83 | - foreach ( $ajaxParameters as $k => $v ) { |
|
| 84 | - if ($s !== '') { |
|
| 85 | - $s .= ','; |
|
| 82 | + $s=''; |
|
| 83 | + foreach ($ajaxParameters as $k => $v) { |
|
| 84 | + if ($s!=='') { |
|
| 85 | + $s.=','; |
|
| 86 | 86 | } |
| 87 | - if (is_array ( $v )) { |
|
| 88 | - $s .= "'{$k}':{" . self::implodeAjaxParameters ( $v ) . "}"; |
|
| 87 | + if (is_array($v)) { |
|
| 88 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 89 | 89 | } else { |
| 90 | - $s .= "'{$k}':{$v}"; |
|
| 90 | + $s.="'{$k}':{$v}"; |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | return $s; |
| 94 | 94 | } |
| 95 | 95 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 96 | - if (isset ( $jsCondition )) { |
|
| 97 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 96 | + if (isset ($jsCondition)) { |
|
| 97 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 98 | 98 | } |
| 99 | 99 | return $jsSource; |
| 100 | 100 | } |
| 101 | 101 | protected function _getAjaxUrl($url, $attr) { |
| 102 | - $url = $this->_correctAjaxUrl ( $url ); |
|
| 103 | - $retour = "url='" . $url . "';"; |
|
| 104 | - $slash = "/"; |
|
| 105 | - if (JString::endswith ( $url, "/" ) === true) { |
|
| 106 | - $slash = ""; |
|
| 107 | - } |
|
| 108 | - if (JString::isNotNull ( $attr )) { |
|
| 109 | - if ($attr === "value") { |
|
| 110 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 111 | - } elseif ($attr === "html") { |
|
| 112 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 113 | - } elseif (\substr ( $attr, 0, 3 ) === "js:") { |
|
| 114 | - $retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n"; |
|
| 115 | - } elseif ($attr !== null && $attr !== "") |
|
| 116 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 102 | + $url=$this->_correctAjaxUrl($url); |
|
| 103 | + $retour="url='".$url."';"; |
|
| 104 | + $slash="/"; |
|
| 105 | + if (JString::endswith($url, "/")===true) { |
|
| 106 | + $slash=""; |
|
| 107 | + } |
|
| 108 | + if (JString::isNotNull($attr)) { |
|
| 109 | + if ($attr==="value") { |
|
| 110 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 111 | + } elseif ($attr==="html") { |
|
| 112 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 113 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 114 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 115 | + } elseif ($attr!==null && $attr!=="") |
|
| 116 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 117 | 117 | } |
| 118 | 118 | return $retour; |
| 119 | 119 | } |
| 120 | 120 | protected function onPopstate() { |
| 121 | 121 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 122 | 122 | } |
| 123 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 124 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 125 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 123 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 124 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 125 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 126 | 126 | return $result; |
| 127 | 127 | } |
| 128 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 129 | - $retour = ""; |
|
| 130 | - $call = null; |
|
| 131 | - if (JString::isNotNull ( $responseElement )) { |
|
| 132 | - if (isset ( $ajaxTransition )) { |
|
| 133 | - $call = $this->setAjaxDataCall ( $ajaxTransition ); |
|
| 134 | - } elseif (isset ( $this->ajaxTransition )) { |
|
| 135 | - $call = $this->ajaxTransition; |
|
| 128 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 129 | + $retour=""; |
|
| 130 | + $call=null; |
|
| 131 | + if (JString::isNotNull($responseElement)) { |
|
| 132 | + if (isset ($ajaxTransition)) { |
|
| 133 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 134 | + } elseif (isset ($this->ajaxTransition)) { |
|
| 135 | + $call=$this->ajaxTransition; |
|
| 136 | 136 | } |
| 137 | - if (\is_callable ( $call )) |
|
| 138 | - $retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n"; |
|
| 137 | + if (\is_callable($call)) |
|
| 138 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 139 | 139 | else |
| 140 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 140 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 141 | 141 | } |
| 142 | - if (isset ( $history )) { |
|
| 142 | + if (isset ($history)) { |
|
| 143 | 143 | if ($this->params ["autoActiveLinks"]) { |
| 144 | - $retour .= $this->autoActiveLinks ( "url" ); |
|
| 144 | + $retour.=$this->autoActiveLinks("url"); |
|
| 145 | 145 | } |
| 146 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value ( $history ) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 146 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 147 | 147 | } |
| 148 | - if ($hasLoader === "internal") { |
|
| 149 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 148 | + if ($hasLoader==="internal") { |
|
| 149 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 150 | 150 | } |
| 151 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 151 | + $retour.="\t".$jsCallback."\n"; |
|
| 152 | 152 | return $retour; |
| 153 | 153 | } |
| 154 | 154 | protected function _getResponseElement($responseElement) { |
| 155 | - if (JString::isNotNull ( $responseElement )) { |
|
| 156 | - $responseElement = Javascript::prep_jquery_selector ( $responseElement ); |
|
| 155 | + if (JString::isNotNull($responseElement)) { |
|
| 156 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 157 | 157 | } |
| 158 | 158 | return $responseElement; |
| 159 | 159 | } |
| 160 | 160 | protected function _correctAjaxUrl($url) { |
| 161 | - if ($url !== "/" && JString::endsWith ( $url, "/" ) === true) |
|
| 162 | - $url = substr ( $url, 0, strlen ( $url ) - 1 ); |
|
| 163 | - if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) { |
|
| 164 | - $url = $this->getUrl ( $url ); |
|
| 161 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 162 | + $url=substr($url, 0, strlen($url)-1); |
|
| 163 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 164 | + $url=$this->getUrl($url); |
|
| 165 | 165 | } |
| 166 | 166 | return $url; |
| 167 | 167 | } |
| 168 | - public static function _correctParams($params, $ajaxParameters = [ ]) { |
|
| 169 | - if (JString::isNull ( $params )) { |
|
| 168 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 169 | + if (JString::isNull($params)) { |
|
| 170 | 170 | return ""; |
| 171 | 171 | } |
| 172 | - if (\preg_match ( "@^\{.*?\}$@", $params )) { |
|
| 173 | - if (! isset ( $ajaxParameters ['contentType'] ) || ! JString::contains ( $ajaxParameters ['contentType'], 'json' )) { |
|
| 174 | - return '$.param(' . $params . ')'; |
|
| 172 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
| 173 | + if (!isset ($ajaxParameters ['contentType']) || !JString::contains($ajaxParameters ['contentType'], 'json')) { |
|
| 174 | + return '$.param('.$params.')'; |
|
| 175 | 175 | } else { |
| 176 | - return 'JSON.stringify(' . $params . ')'; |
|
| 176 | + return 'JSON.stringify('.$params.')'; |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | return $params; |
| 180 | 180 | } |
| 181 | 181 | public static function _implodeParams($parameters) { |
| 182 | - $allParameters = [ ]; |
|
| 183 | - foreach ( $parameters as $params ) { |
|
| 184 | - if (isset ( $params )) |
|
| 185 | - $allParameters [] = self::_correctParams ( $params ); |
|
| 182 | + $allParameters=[]; |
|
| 183 | + foreach ($parameters as $params) { |
|
| 184 | + if (isset ($params)) |
|
| 185 | + $allParameters []=self::_correctParams($params); |
|
| 186 | 186 | } |
| 187 | - return \implode ( "+'&'+", $allParameters ); |
|
| 187 | + return \implode("+'&'+", $allParameters); |
|
| 188 | 188 | } |
| 189 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 190 | - if (! isset ( $ajaxLoader )) { |
|
| 191 | - $ajaxLoader = $this->ajaxLoader; |
|
| 189 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 190 | + if (!isset ($ajaxLoader)) { |
|
| 191 | + $ajaxLoader=$this->ajaxLoader; |
|
| 192 | 192 | } |
| 193 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 194 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 193 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 194 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 195 | 195 | } |
| 196 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 197 | - if (! isset ( $ajaxLoader )) { |
|
| 198 | - $ajaxLoader = $this->ajaxLoader; |
|
| 196 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 197 | + if (!isset ($ajaxLoader)) { |
|
| 198 | + $ajaxLoader=$this->ajaxLoader; |
|
| 199 | 199 | } |
| 200 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 201 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 202 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 200 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 201 | + $retour.="{$responseElement}.empty();\n"; |
|
| 202 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 203 | 203 | } |
| 204 | 204 | protected function setAjaxDataCall($params) { |
| 205 | - $result = null; |
|
| 206 | - if (! \is_callable ( $params )) { |
|
| 207 | - $result = function ($responseElement, $jqueryDone = "html") use ($params) { |
|
| 208 | - return AjaxTransition::{$params} ( $responseElement, $jqueryDone ); |
|
| 205 | + $result=null; |
|
| 206 | + if (!\is_callable($params)) { |
|
| 207 | + $result=function($responseElement, $jqueryDone="html") use ($params) { |
|
| 208 | + return AjaxTransition::{$params} ($responseElement, $jqueryDone); |
|
| 209 | 209 | }; |
| 210 | 210 | } |
| 211 | 211 | return $result; |
| 212 | 212 | } |
| 213 | 213 | protected function setDefaultParameters(&$parameters, $default) { |
| 214 | - foreach ( $default as $k => $v ) { |
|
| 215 | - if (! isset ( $parameters [$k] )) |
|
| 216 | - $parameters [$k] = $v; |
|
| 214 | + foreach ($default as $k => $v) { |
|
| 215 | + if (!isset ($parameters [$k])) |
|
| 216 | + $parameters [$k]=$v; |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | public function setAjaxLoader($loader) { |
| 220 | - $this->ajaxLoader = $loader; |
|
| 220 | + $this->ajaxLoader=$loader; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -228,8 +228,8 @@ discard block |
||
| 228 | 228 | * @param string $responseElement |
| 229 | 229 | * selector of the HTML element displaying the answer |
| 230 | 230 | */ |
| 231 | - private function _get($url, $responseElement = "", $parameters = [ ]) { |
|
| 232 | - return $this->_ajax ( "get", $url, $responseElement, $parameters ); |
|
| 231 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 232 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | * @param array $parameters |
| 243 | 243 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 244 | 244 | */ |
| 245 | - public function get($url, $responseElement = "", $parameters = [ ]) { |
|
| 246 | - $parameters ["immediatly"] = true; |
|
| 247 | - return $this->_get ( $url, $responseElement, $parameters ); |
|
| 245 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 246 | + $parameters ["immediatly"]=true; |
|
| 247 | + return $this->_get($url, $responseElement, $parameters); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | * @param array $parameters |
| 260 | 260 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 261 | 261 | */ |
| 262 | - public function ajax($method, $url, $responseElement = "", $parameters = [ ]) { |
|
| 263 | - $parameters ["immediatly"] = true; |
|
| 264 | - return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
| 262 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 263 | + $parameters ["immediatly"]=true; |
|
| 264 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | * $immediatly |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [ ], $immediatly = true) { |
|
| 286 | - return $this->interval ( $this->ajaxDeferred ( $method, $url, $responseElement, $parameters ), $interval, $globalName, $immediatly ); |
|
| 285 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) { |
|
| 286 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | * @param array $parameters |
| 299 | 299 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 300 | 300 | */ |
| 301 | - public function ajaxDeferred($method, $url, $responseElement = "", $parameters = [ ]) { |
|
| 302 | - $parameters ["immediatly"] = false; |
|
| 303 | - return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
| 301 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 302 | + $parameters ["immediatly"]=false; |
|
| 303 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -313,16 +313,16 @@ discard block |
||
| 313 | 313 | * @param array $parameters |
| 314 | 314 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 315 | 315 | */ |
| 316 | - private function _json($url, $method = "get", $parameters = [ ]) { |
|
| 317 | - $parameters = \array_merge ( $parameters, [ |
|
| 316 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 317 | + $parameters=\array_merge($parameters, [ |
|
| 318 | 318 | "hasLoader" => false |
| 319 | - ] ); |
|
| 320 | - $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
| 321 | - $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : "document"; |
|
| 322 | - $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"; |
|
| 323 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 324 | - $parameters ["jsCallback"] = $retour; |
|
| 325 | - return $this->_ajax ( $method, $url, null, $parameters ); |
|
| 319 | + ]); |
|
| 320 | + $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
| 321 | + $context=isset ($parameters ['context']) ? $parameters ['context'] : "document"; |
|
| 322 | + $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"; |
|
| 323 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 324 | + $parameters ["jsCallback"]=$retour; |
|
| 325 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -335,8 +335,8 @@ discard block |
||
| 335 | 335 | * @param array $parameters |
| 336 | 336 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 337 | 337 | */ |
| 338 | - public function json($url, $method = "get", $parameters = [ ]) { |
|
| 339 | - return $this->_json ( $url, $method, $parameters ); |
|
| 338 | + public function json($url, $method="get", $parameters=[]) { |
|
| 339 | + return $this->_json($url, $method, $parameters); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -351,13 +351,13 @@ discard block |
||
| 351 | 351 | * @param array $parameters |
| 352 | 352 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null) |
| 353 | 353 | */ |
| 354 | - public function jsonOn($event, $element, $url, $method = "get", $parameters = array ()) { |
|
| 355 | - $this->setDefaultParameters ( $parameters, [ |
|
| 354 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
| 355 | + $this->setDefaultParameters($parameters, [ |
|
| 356 | 356 | "preventDefault" => true, |
| 357 | 357 | "stopPropagation" => true, |
| 358 | 358 | "immediatly" => true |
| 359 | - ] ); |
|
| 360 | - return $this->_add_event ( $element, $this->jsonDeferred ( $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 359 | + ]); |
|
| 360 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | * @param array $parameters |
| 371 | 371 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 372 | 372 | */ |
| 373 | - public function jsonDeferred($url, $method = "get", $parameters = [ ]) { |
|
| 374 | - $parameters ["immediatly"] = false; |
|
| 375 | - return $this->_json ( $url, $method, $parameters ); |
|
| 373 | + public function jsonDeferred($url, $method="get", $parameters=[]) { |
|
| 374 | + $parameters ["immediatly"]=false; |
|
| 375 | + return $this->_json($url, $method, $parameters); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -386,30 +386,30 @@ discard block |
||
| 386 | 386 | * @param array $parameters |
| 387 | 387 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 388 | 388 | */ |
| 389 | - private function _jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
| 390 | - $parameters = \array_merge ( $parameters, [ |
|
| 389 | + private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 390 | + $parameters=\array_merge($parameters, [ |
|
| 391 | 391 | "hasLoader" => false |
| 392 | - ] ); |
|
| 393 | - $rowClass = isset ( $parameters ['rowClass'] ) ? $parameters ['rowClass'] : "_json"; |
|
| 394 | - $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
| 395 | - $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : null; |
|
| 396 | - if ($context === null) { |
|
| 397 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 398 | - $newElm = "$('#'+newId)"; |
|
| 392 | + ]); |
|
| 393 | + $rowClass=isset ($parameters ['rowClass']) ? $parameters ['rowClass'] : "_json"; |
|
| 394 | + $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
| 395 | + $context=isset ($parameters ['context']) ? $parameters ['context'] : null; |
|
| 396 | + if ($context===null) { |
|
| 397 | + $parent="$('".$maskSelector."').parent()"; |
|
| 398 | + $newElm="$('#'+newId)"; |
|
| 399 | 399 | } else { |
| 400 | - $parent = $context; |
|
| 401 | - $newElm = $context . ".find('#'+newId)"; |
|
| 400 | + $parent=$context; |
|
| 401 | + $newElm=$context.".find('#'+newId)"; |
|
| 402 | 402 | } |
| 403 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 404 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 405 | - $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(); |
|
| 403 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 404 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 405 | + $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(); |
|
| 406 | 406 | 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"; |
| 407 | - $retour .= $appendTo; |
|
| 408 | - $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"; |
|
| 409 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 410 | - $retour .= "\t" . $jsCallback; |
|
| 411 | - $parameters ["jsCallback"] = $retour; |
|
| 412 | - return $this->_ajax ( $method, $url, null, $parameters ); |
|
| 407 | + $retour.=$appendTo; |
|
| 408 | + $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"; |
|
| 409 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 410 | + $retour.="\t".$jsCallback; |
|
| 411 | + $parameters ["jsCallback"]=$retour; |
|
| 412 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -423,8 +423,8 @@ discard block |
||
| 423 | 423 | * @param array $parameters |
| 424 | 424 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 425 | 425 | */ |
| 426 | - public function jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
| 427 | - return $this->_jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
| 426 | + public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 427 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -438,9 +438,9 @@ discard block |
||
| 438 | 438 | * @param array $parameters |
| 439 | 439 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 440 | 440 | */ |
| 441 | - public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
| 442 | - $parameters ["immediatly"] = false; |
|
| 443 | - return $this->jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
| 441 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 442 | + $parameters ["immediatly"]=false; |
|
| 443 | + return $this->jsonArray($maskSelector, $url, $method, $parameters); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | /** |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | * @param array $parameters |
| 456 | 456 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null) |
| 457 | 457 | */ |
| 458 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array ()) { |
|
| 459 | - $this->setDefaultParameters ( $parameters, [ |
|
| 458 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
| 459 | + $this->setDefaultParameters($parameters, [ |
|
| 460 | 460 | "preventDefault" => true, |
| 461 | 461 | "stopPropagation" => true, |
| 462 | 462 | "immediatly" => true |
| 463 | - ] ); |
|
| 464 | - return $this->_add_event ( $element, $this->jsonArrayDeferred ( $maskSelector, $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 463 | + ]); |
|
| 464 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * @param array $parameters |
| 476 | 476 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 477 | 477 | */ |
| 478 | - public function getDeferred($url, $responseElement = "", $parameters = [ ]) { |
|
| 479 | - $parameters ["immediatly"] = false; |
|
| 480 | - return $this->_get ( $url, $responseElement, $parameters ); |
|
| 478 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 479 | + $parameters ["immediatly"]=false; |
|
| 480 | + return $this->_get($url, $responseElement, $parameters); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -495,13 +495,13 @@ discard block |
||
| 495 | 495 | * @param array $parameters |
| 496 | 496 | * 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) |
| 497 | 497 | */ |
| 498 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array ()) { |
|
| 499 | - $this->setDefaultParameters ( $parameters, [ |
|
| 498 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 499 | + $this->setDefaultParameters($parameters, [ |
|
| 500 | 500 | "preventDefault" => true, |
| 501 | 501 | "stopPropagation" => true, |
| 502 | 502 | "immediatly" => true |
| 503 | - ] ); |
|
| 504 | - return $this->_add_event ( $element, $this->getDeferred ( $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 503 | + ]); |
|
| 504 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -519,14 +519,14 @@ discard block |
||
| 519 | 519 | * @param array $parameters |
| 520 | 520 | * 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) |
| 521 | 521 | */ |
| 522 | - public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array ()) { |
|
| 523 | - $this->setDefaultParameters ( $parameters, [ |
|
| 522 | + public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 523 | + $this->setDefaultParameters($parameters, [ |
|
| 524 | 524 | "preventDefault" => true, |
| 525 | 525 | "stopPropagation" => true, |
| 526 | 526 | "immediatly" => true, |
| 527 | 527 | "method" => "get" |
| 528 | - ] ); |
|
| 529 | - return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ["method"], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 528 | + ]); |
|
| 529 | + return $this->_add_event($element, $this->ajaxDeferred($parameters ["method"], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -542,8 +542,8 @@ discard block |
||
| 542 | 542 | * @param array $parameters |
| 543 | 543 | * 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) |
| 544 | 544 | */ |
| 545 | - public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array ()) { |
|
| 546 | - return $this->ajaxOn ( "click", $element, $url, $responseElement, $parameters ); |
|
| 545 | + public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 546 | + return $this->ajaxOn("click", $element, $url, $responseElement, $parameters); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @param array $parameters |
| 560 | 560 | * 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) |
| 561 | 561 | */ |
| 562 | - public function getOnClick($element, $url, $responseElement = "", $parameters = array ()) { |
|
| 563 | - return $this->getOn ( "click", $element, $url, $responseElement, $parameters ); |
|
| 562 | + public function getOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 563 | + return $this->getOn("click", $element, $url, $responseElement, $parameters); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -574,17 +574,17 @@ discard block |
||
| 574 | 574 | * 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) |
| 575 | 575 | * @return $this |
| 576 | 576 | */ |
| 577 | - public function getHref($element, $responseElement = "", $parameters = array ()) { |
|
| 578 | - $parameters ["attr"] = "href"; |
|
| 579 | - if (JString::isNull ( $responseElement )) { |
|
| 580 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 577 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 578 | + $parameters ["attr"]="href"; |
|
| 579 | + if (JString::isNull($responseElement)) { |
|
| 580 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 581 | 581 | } else { |
| 582 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 582 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 583 | 583 | } |
| 584 | - if (! isset ( $parameters ["historize"] )) { |
|
| 585 | - $parameters ["historize"] = true; |
|
| 584 | + if (!isset ($parameters ["historize"])) { |
|
| 585 | + $parameters ["historize"]=true; |
|
| 586 | 586 | } |
| 587 | - return $this->getOnClick ( $element, "", $responseElement, $parameters ); |
|
| 587 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -598,21 +598,21 @@ discard block |
||
| 598 | 598 | * 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) |
| 599 | 599 | * @return $this |
| 600 | 600 | */ |
| 601 | - public function postHref($element, $responseElement = "", $parameters = array ()) { |
|
| 602 | - $parameters ["attr"] = "href"; |
|
| 603 | - if (JString::isNull ( $responseElement )) { |
|
| 604 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 601 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 602 | + $parameters ["attr"]="href"; |
|
| 603 | + if (JString::isNull($responseElement)) { |
|
| 604 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 605 | 605 | } else { |
| 606 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 606 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 607 | 607 | } |
| 608 | - if (! isset ( $parameters ["historize"] )) { |
|
| 609 | - $parameters ["historize"] = true; |
|
| 608 | + if (!isset ($parameters ["historize"])) { |
|
| 609 | + $parameters ["historize"]=true; |
|
| 610 | 610 | } |
| 611 | - return $this->postOnClick ( $element, "", "{}", $responseElement, $parameters ); |
|
| 611 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
| 612 | 612 | } |
| 613 | - private function _post($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
| 614 | - $parameters ["params"] = $params; |
|
| 615 | - return $this->_ajax ( "POST", $url, $responseElement, $parameters ); |
|
| 613 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 614 | + $parameters ["params"]=$params; |
|
| 615 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -627,9 +627,9 @@ discard block |
||
| 627 | 627 | * @param array $parameters |
| 628 | 628 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 629 | 629 | */ |
| 630 | - public function post($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
| 631 | - $parameters ['immediatly'] = true; |
|
| 632 | - return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
| 630 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 631 | + $parameters ['immediatly']=true; |
|
| 632 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -645,9 +645,9 @@ discard block |
||
| 645 | 645 | * @param array $parameters |
| 646 | 646 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 647 | 647 | */ |
| 648 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
| 649 | - $parameters ["immediatly"] = false; |
|
| 650 | - return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
| 648 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 649 | + $parameters ["immediatly"]=false; |
|
| 650 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
@@ -665,13 +665,13 @@ discard block |
||
| 665 | 665 | * @param array $parameters |
| 666 | 666 | * 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) |
| 667 | 667 | */ |
| 668 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
| 669 | - $this->setDefaultParameters ( $parameters, [ |
|
| 668 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 669 | + $this->setDefaultParameters($parameters, [ |
|
| 670 | 670 | "preventDefault" => true, |
| 671 | 671 | "stopPropagation" => true, |
| 672 | 672 | "immediatly" => true |
| 673 | - ] ); |
|
| 674 | - return $this->_add_event ( $element, $this->postDeferred ( $url, $params, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 673 | + ]); |
|
| 674 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -688,65 +688,65 @@ discard block |
||
| 688 | 688 | * @param array $parameters |
| 689 | 689 | * 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) |
| 690 | 690 | */ |
| 691 | - public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
| 692 | - return $this->postOn ( "click", $element, $url, $params, $responseElement, $parameters ); |
|
| 693 | - } |
|
| 694 | - private function _postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
| 695 | - if (isset ( $this->params ["ajax"] )) { |
|
| 696 | - extract ( $this->params ["ajax"] ); |
|
| 697 | - } |
|
| 698 | - $params = "{}"; |
|
| 699 | - $validation = false; |
|
| 700 | - \extract ( $parameters ); |
|
| 701 | - $async = ($async) ? "true" : "false"; |
|
| 702 | - $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
| 703 | - $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
| 704 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
| 705 | - if (! isset ( $contentType ) || $contentType != 'false') { |
|
| 706 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
| 707 | - if (isset ( $params )) { |
|
| 708 | - $retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n"; |
|
| 691 | + public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 692 | + return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
|
| 693 | + } |
|
| 694 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 695 | + if (isset ($this->params ["ajax"])) { |
|
| 696 | + extract($this->params ["ajax"]); |
|
| 697 | + } |
|
| 698 | + $params="{}"; |
|
| 699 | + $validation=false; |
|
| 700 | + \extract($parameters); |
|
| 701 | + $async=($async) ? "true" : "false"; |
|
| 702 | + $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
| 703 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 704 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
| 705 | + if (!isset ($contentType) || $contentType!='false') { |
|
| 706 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
| 707 | + if (isset ($params)) { |
|
| 708 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 709 | 709 | } |
| 710 | 710 | } else { |
| 711 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
| 712 | - } |
|
| 713 | - $responseElement = $this->_getResponseElement ( $responseElement ); |
|
| 714 | - $retour .= "var self=this;\n"; |
|
| 715 | - $before = isset ( $before ) ? $before : ""; |
|
| 716 | - $retour .= $before; |
|
| 717 | - if ($hasLoader === true) { |
|
| 718 | - $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 719 | - } elseif ($hasLoader === 'response') { |
|
| 720 | - $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
| 721 | - } elseif ($hasLoader === 'internal') { |
|
| 722 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 723 | - } |
|
| 724 | - $ajaxParameters = [ |
|
| 711 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
| 712 | + } |
|
| 713 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 714 | + $retour.="var self=this;\n"; |
|
| 715 | + $before=isset ($before) ? $before : ""; |
|
| 716 | + $retour.=$before; |
|
| 717 | + if ($hasLoader===true) { |
|
| 718 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 719 | + } elseif ($hasLoader==='response') { |
|
| 720 | + $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
| 721 | + } elseif ($hasLoader==='internal') { |
|
| 722 | + $retour.="\n$(this).addClass('loading');"; |
|
| 723 | + } |
|
| 724 | + $ajaxParameters=[ |
|
| 725 | 725 | "url" => "url", |
| 726 | 726 | "method" => "'POST'", |
| 727 | 727 | "data" => "params", |
| 728 | 728 | "async" => $async |
| 729 | 729 | ]; |
| 730 | - if (isset ( $headers )) { |
|
| 731 | - $ajaxParameters ["headers"] = $headers; |
|
| 730 | + if (isset ($headers)) { |
|
| 731 | + $ajaxParameters ["headers"]=$headers; |
|
| 732 | 732 | } |
| 733 | - if (isset ( $partial )) { |
|
| 734 | - $ajaxParameters ["xhr"] = "xhrProvider"; |
|
| 735 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 733 | + if (isset ($partial)) { |
|
| 734 | + $ajaxParameters ["xhr"]="xhrProvider"; |
|
| 735 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 736 | 736 | } |
| 737 | - $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
| 738 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n"; |
|
| 739 | - $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n"; |
|
| 737 | + $this->createAjaxParameters($ajaxParameters, $parameters); |
|
| 738 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 739 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 740 | 740 | |
| 741 | 741 | if ($validation) { |
| 742 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
| 743 | - " . $retour . " |
|
| 742 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
| 743 | + " . $retour." |
|
| 744 | 744 | }});\n"; |
| 745 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
| 745 | + $retour.="$('#".$form."').submit();\n"; |
|
| 746 | 746 | } |
| 747 | - $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
| 747 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 748 | 748 | if ($immediatly) |
| 749 | - $this->jquery_code_for_compile [] = $retour; |
|
| 749 | + $this->jquery_code_for_compile []=$retour; |
|
| 750 | 750 | return $retour; |
| 751 | 751 | } |
| 752 | 752 | |
@@ -762,9 +762,9 @@ discard block |
||
| 762 | 762 | * @param array $parameters |
| 763 | 763 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 764 | 764 | */ |
| 765 | - public function postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
| 766 | - $parameters ["immediatly"] = true; |
|
| 767 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
| 765 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 766 | + $parameters ["immediatly"]=true; |
|
| 767 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -780,9 +780,9 @@ discard block |
||
| 780 | 780 | * @param array $parameters |
| 781 | 781 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 782 | 782 | */ |
| 783 | - public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) { |
|
| 784 | - $parameters ["immediatly"] = false; |
|
| 785 | - return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
| 783 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 784 | + $parameters ["immediatly"]=false; |
|
| 785 | + return $this->_postForm($url, $form, $responseElement, $parameters); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | /** |
@@ -798,13 +798,13 @@ discard block |
||
| 798 | 798 | * @param array $parameters |
| 799 | 799 | * 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) |
| 800 | 800 | */ |
| 801 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
| 802 | - $this->setDefaultParameters ( $parameters, [ |
|
| 801 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 802 | + $this->setDefaultParameters($parameters, [ |
|
| 803 | 803 | "preventDefault" => true, |
| 804 | 804 | "stopPropagation" => true, |
| 805 | 805 | "immediatly" => true |
| 806 | - ] ); |
|
| 807 | - return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ); |
|
| 806 | + ]); |
|
| 807 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"]); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | * @param array $parameters |
| 820 | 820 | * 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) |
| 821 | 821 | */ |
| 822 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
| 823 | - return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters ); |
|
| 822 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 823 | + return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
|
| 824 | 824 | } |
| 825 | 825 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @property array $jquery_code_for_compile_at_last |
| 12 | 12 | */ |
| 13 | 13 | trait JsUtilsActionsTrait { |
| 14 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
| 14 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * show or hide with effect |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | * defers the execution if set to false |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - protected function _showHideWithEffect($action, $element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 31 | - $element = Javascript::prep_element ( $element ); |
|
| 32 | - $speed = $this->_validate_speed ( $speed ); |
|
| 33 | - if ($callback != '') { |
|
| 34 | - $callback = ", function(){\n{$callback}\n}"; |
|
| 30 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
| 31 | + $element=Javascript::prep_element($element); |
|
| 32 | + $speed=$this->_validate_speed($speed); |
|
| 33 | + if ($callback!='') { |
|
| 34 | + $callback=", function(){\n{$callback}\n}"; |
|
| 35 | 35 | } |
| 36 | - $str = "$({$element}).{$action}({$speed}{$callback});"; |
|
| 36 | + $str="$({$element}).{$action}({$speed}{$callback});"; |
|
| 37 | 37 | if ($immediatly) |
| 38 | - $this->jquery_code_for_compile [] = $str; |
|
| 38 | + $this->jquery_code_for_compile []=$str; |
|
| 39 | 39 | return $str; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | 48 | private function _validate_speed($speed) { |
| 49 | - if (in_array ( $speed, array ( |
|
| 49 | + if (in_array($speed, array( |
|
| 50 | 50 | 'slow', |
| 51 | 51 | 'normal', |
| 52 | 52 | 'fast' |
| 53 | - ) )) { |
|
| 54 | - $speed = '"' . $speed . '"'; |
|
| 55 | - } elseif (preg_match ( "/[^0-9]/", $speed )) { |
|
| 56 | - $speed = ''; |
|
| 53 | + ))) { |
|
| 54 | + $speed='"'.$speed.'"'; |
|
| 55 | + } elseif (preg_match("/[^0-9]/", $speed)) { |
|
| 56 | + $speed=''; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | return $speed; |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * @param boolean $immediatly |
| 69 | 69 | * delayed if false |
| 70 | 70 | */ |
| 71 | - public function _genericCallValue($jQueryCall, $element = 'this', $param = "", $immediatly = false) { |
|
| 72 | - $element = Javascript::prep_element ( $element ); |
|
| 73 | - if (isset ( $param )) { |
|
| 74 | - $param = Javascript::prep_value ( $param ); |
|
| 75 | - $str = "$({$element}).{$jQueryCall}({$param});"; |
|
| 71 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
| 72 | + $element=Javascript::prep_element($element); |
|
| 73 | + if (isset ($param)) { |
|
| 74 | + $param=Javascript::prep_value($param); |
|
| 75 | + $str="$({$element}).{$jQueryCall}({$param});"; |
|
| 76 | 76 | } else |
| 77 | - $str = "$({$element}).{$jQueryCall}();"; |
|
| 77 | + $str="$({$element}).{$jQueryCall}();"; |
|
| 78 | 78 | if ($immediatly) |
| 79 | - $this->jquery_code_for_compile [] = $str; |
|
| 79 | + $this->jquery_code_for_compile []=$str; |
|
| 80 | 80 | return $str; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | * delayed if false |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function _genericCallElement($jQueryCall, $to = 'this', $element = '', $immediatly = false) { |
|
| 94 | - $to = Javascript::prep_element ( $to ); |
|
| 95 | - $element = Javascript::prep_element ( $element ); |
|
| 96 | - $str = "$({$to}).{$jQueryCall}({$element});"; |
|
| 93 | + public function _genericCallElement($jQueryCall, $to='this', $element='', $immediatly=false) { |
|
| 94 | + $to=Javascript::prep_element($to); |
|
| 95 | + $element=Javascript::prep_element($element); |
|
| 96 | + $str="$({$to}).{$jQueryCall}({$element});"; |
|
| 97 | 97 | if ($immediatly) |
| 98 | - $this->jquery_code_for_compile [] = $str; |
|
| 98 | + $this->jquery_code_for_compile []=$str; |
|
| 99 | 99 | return $str; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * defers the execution if set to false |
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | - public function addClass($element = 'this', $class = '', $immediatly = false) { |
|
| 113 | - return $this->_genericCallValue ( 'addClass', $element, $class, $immediatly ); |
|
| 112 | + public function addClass($element='this', $class='', $immediatly=false) { |
|
| 113 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * defers the execution if set to false |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - public function after($to, $element, $immediatly = false) { |
|
| 126 | - return $this->_genericCallElement ( 'after', $to, $element, $immediatly ); |
|
| 125 | + public function after($to, $element, $immediatly=false) { |
|
| 126 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * defers the execution if set to false |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - public function before($to, $element, $immediatly = false) { |
|
| 139 | - return $this->_genericCallElement ( 'before', $to, $element, $immediatly ); |
|
| 138 | + public function before($to, $element, $immediatly=false) { |
|
| 139 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | * @param boolean $immediatly |
| 149 | 149 | * delayed if false |
| 150 | 150 | */ |
| 151 | - public function attr($element = 'this', $attributeName = 'id', $value = "", $immediatly = false) { |
|
| 152 | - $element = Javascript::prep_element ( $element ); |
|
| 153 | - if (isset ( $value )) { |
|
| 154 | - $value = Javascript::prep_value ( $value ); |
|
| 155 | - $str = "$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 151 | + public function attr($element='this', $attributeName='id', $value="", $immediatly=false) { |
|
| 152 | + $element=Javascript::prep_element($element); |
|
| 153 | + if (isset ($value)) { |
|
| 154 | + $value=Javascript::prep_value($value); |
|
| 155 | + $str="$({$element}).attr(\"$attributeName\",{$value});"; |
|
| 156 | 156 | } else |
| 157 | - $str = "$({$element}).attr(\"$attributeName\");"; |
|
| 157 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
| 158 | 158 | if ($immediatly) |
| 159 | - $this->jquery_code_for_compile [] = $str; |
|
| 159 | + $this->jquery_code_for_compile []=$str; |
|
| 160 | 160 | return $str; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | * @param boolean $immediatly |
| 169 | 169 | * defers the execution if set to false |
| 170 | 170 | */ |
| 171 | - public function val($element = 'this', $value = '', $immediatly = false) { |
|
| 172 | - return $this->_genericCallValue ( 'val', $element, $value, $immediatly ); |
|
| 171 | + public function val($element='this', $value='', $immediatly=false) { |
|
| 172 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | * @param boolean $immediatly |
| 181 | 181 | * defers the execution if set to false |
| 182 | 182 | */ |
| 183 | - public function html($element = 'this', $value = '', $immediatly = false) { |
|
| 184 | - return $this->_genericCallValue ( 'html', $element, $value, $immediatly ); |
|
| 183 | + public function html($element='this', $value='', $immediatly=false) { |
|
| 184 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -197,30 +197,30 @@ discard block |
||
| 197 | 197 | * defers the execution if set to false |
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | - public function animate($element = 'this', $params = array (), $speed = '', $extra = '', $immediatly = false) { |
|
| 201 | - $element = Javascript::prep_element ( $element ); |
|
| 202 | - $speed = $this->_validate_speed ( $speed ); |
|
| 200 | + public function animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
|
| 201 | + $element=Javascript::prep_element($element); |
|
| 202 | + $speed=$this->_validate_speed($speed); |
|
| 203 | 203 | |
| 204 | - $animations = "\t\t\t"; |
|
| 205 | - if (\is_array ( $params )) { |
|
| 206 | - foreach ( $params as $param => $value ) { |
|
| 207 | - $animations .= $param . ': \'' . $value . '\', '; |
|
| 204 | + $animations="\t\t\t"; |
|
| 205 | + if (\is_array($params)) { |
|
| 206 | + foreach ($params as $param => $value) { |
|
| 207 | + $animations.=$param.': \''.$value.'\', '; |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | - $animations = substr ( $animations, 0, - 2 ); // remove the last ", " |
|
| 210 | + $animations=substr($animations, 0, - 2); // remove the last ", " |
|
| 211 | 211 | |
| 212 | - if ($speed != '') { |
|
| 213 | - $speed = ', ' . $speed; |
|
| 212 | + if ($speed!='') { |
|
| 213 | + $speed=', '.$speed; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ($extra != '') { |
|
| 217 | - $extra = ', ' . $extra; |
|
| 216 | + if ($extra!='') { |
|
| 217 | + $extra=', '.$extra; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - $str = "$({$element}).animate({\n$animations\n\t\t}" . $speed . $extra . ");"; |
|
| 220 | + $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
|
| 221 | 221 | |
| 222 | 222 | if ($immediatly) |
| 223 | - $this->jquery_code_for_compile [] = $str; |
|
| 223 | + $this->jquery_code_for_compile []=$str; |
|
| 224 | 224 | return $str; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * defers the execution if set to false |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - public function append($to, $element, $immediatly = false) { |
|
| 237 | - return $this->_genericCallElement ( 'append', $to, $element, $immediatly ); |
|
| 236 | + public function append($to, $element, $immediatly=false) { |
|
| 237 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * defers the execution if set to false |
| 247 | 247 | * @return string |
| 248 | 248 | */ |
| 249 | - public function prepend($to, $element, $immediatly = false) { |
|
| 250 | - return $this->_genericCallElement ( 'prepend', $to, $element, $immediatly ); |
|
| 249 | + public function prepend($to, $element, $immediatly=false) { |
|
| 250 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * defers the execution if set to false |
| 264 | 264 | * @return string |
| 265 | 265 | */ |
| 266 | - public function fadeIn($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 267 | - return $this->_showHideWithEffect ( "fadeIn", $element, $speed, $callback, $immediatly ); |
|
| 266 | + public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 267 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | * defers the execution if set to false |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - public function fadeOut($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 284 | - return $this->_showHideWithEffect ( "fadeOut", $element, $speed, $callback, $immediatly ); |
|
| 283 | + public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 284 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | * defers the execution if set to false |
| 298 | 298 | * @return string |
| 299 | 299 | */ |
| 300 | - public function slideUp($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 301 | - return $this->_showHideWithEffect ( "slideUp", $element, $speed, $callback, $immediatly ); |
|
| 300 | + public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 301 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * defers the execution if set to false |
| 313 | 313 | * @return string |
| 314 | 314 | */ |
| 315 | - public function removeClass($element = 'this', $class = '', $immediatly = false) { |
|
| 316 | - return $this->_genericCallValue ( 'removeClass', $element, $class, $immediatly ); |
|
| 315 | + public function removeClass($element='this', $class='', $immediatly=false) { |
|
| 316 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | * defers the execution if set to false |
| 330 | 330 | * @return string |
| 331 | 331 | */ |
| 332 | - public function slideDown($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 333 | - return $this->_showHideWithEffect ( "slideDown", $element, $speed, $callback, $immediatly ); |
|
| 332 | + public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 333 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | * defers the execution if set to false |
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | - public function slideToggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 350 | - return $this->_showHideWithEffect ( "slideToggle", $element, $speed, $callback, $immediatly ); |
|
| 349 | + public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 350 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * defers the execution if set to false |
| 364 | 364 | * @return string |
| 365 | 365 | */ |
| 366 | - public function hide($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 367 | - return $this->_showHideWithEffect ( "hide", $element, $speed, $callback, $immediatly ); |
|
| 366 | + public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 367 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | * defers the execution if set to false |
| 381 | 381 | * @return string |
| 382 | 382 | */ |
| 383 | - public function toggle($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 384 | - return $this->_showHideWithEffect ( "toggle", $element, $speed, $callback, $immediatly ); |
|
| 383 | + public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 384 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | * defers the execution if set to false |
| 395 | 395 | * @return string |
| 396 | 396 | */ |
| 397 | - public function toggleClass($element = 'this', $class = '', $immediatly = false) { |
|
| 398 | - return $this->_genericCallValue ( 'toggleClass', $element, $class, $immediatly ); |
|
| 397 | + public function toggleClass($element='this', $class='', $immediatly=false) { |
|
| 398 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -406,12 +406,12 @@ discard block |
||
| 406 | 406 | * @param boolean $immediatly |
| 407 | 407 | * defers the execution if set to false |
| 408 | 408 | */ |
| 409 | - public function trigger($element = 'this', $event = 'click', $immediatly = false) { |
|
| 410 | - $element = Javascript::prep_element ( $element ); |
|
| 411 | - $str = "$({$element}).trigger(\"$event\");"; |
|
| 409 | + public function trigger($element='this', $event='click', $immediatly=false) { |
|
| 410 | + $element=Javascript::prep_element($element); |
|
| 411 | + $str="$({$element}).trigger(\"$event\");"; |
|
| 412 | 412 | |
| 413 | 413 | if ($immediatly) |
| 414 | - $this->jquery_code_for_compile [] = $str; |
|
| 414 | + $this->jquery_code_for_compile []=$str; |
|
| 415 | 415 | return $str; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -428,8 +428,8 @@ discard block |
||
| 428 | 428 | * defers the execution if set to false |
| 429 | 429 | * @return string |
| 430 | 430 | */ |
| 431 | - public function show($element = 'this', $speed = '', $callback = '', $immediatly = false) { |
|
| 432 | - return $this->_showHideWithEffect ( "show", $element, $speed, $callback, $immediatly ); |
|
| 431 | + public function show($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 432 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -439,18 +439,18 @@ discard block |
||
| 439 | 439 | * @param array $options |
| 440 | 440 | * @return string |
| 441 | 441 | */ |
| 442 | - public function sortable($element, $options = array ()) { |
|
| 443 | - if (count ( $options ) > 0) { |
|
| 444 | - $sort_options = array (); |
|
| 445 | - foreach ( $options as $k => $v ) { |
|
| 446 | - $sort_options [] = "\n\t\t" . $k . ': ' . $v . ""; |
|
| 442 | + public function sortable($element, $options=array()) { |
|
| 443 | + if (count($options)>0) { |
|
| 444 | + $sort_options=array(); |
|
| 445 | + foreach ($options as $k => $v) { |
|
| 446 | + $sort_options []="\n\t\t".$k.': '.$v.""; |
|
| 447 | 447 | } |
| 448 | - $sort_options = implode ( ",", $sort_options ); |
|
| 448 | + $sort_options=implode(",", $sort_options); |
|
| 449 | 449 | } else { |
| 450 | - $sort_options = ''; |
|
| 450 | + $sort_options=''; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - return "$(" . Javascript::prep_element ( $element ) . ").sortable({" . $sort_options . "\n\t});"; |
|
| 453 | + return "$(".Javascript::prep_element($element).").sortable({".$sort_options."\n\t});"; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | * plugin location |
| 463 | 463 | * @return string |
| 464 | 464 | */ |
| 465 | - public function tablesorter($table = '', $options = '') { |
|
| 466 | - $this->jquery_code_for_compile [] = "\t$(" . Javascript::prep_element ( $table ) . ").tablesorter($options);\n"; |
|
| 465 | + public function tablesorter($table='', $options='') { |
|
| 466 | + $this->jquery_code_for_compile []="\t$(".Javascript::prep_element($table).").tablesorter($options);\n"; |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -475,14 +475,14 @@ discard block |
||
| 475 | 475 | * @param boolean $immediatly |
| 476 | 476 | * defers the execution if set to false |
| 477 | 477 | */ |
| 478 | - public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse = null, $immediatly = false) { |
|
| 479 | - $str = "if(" . $condition . "){" . $jsCodeIfTrue . "}"; |
|
| 480 | - if (isset ( $jsCodeIfFalse )) { |
|
| 481 | - $str .= "else{" . $jsCodeIfFalse . "}"; |
|
| 478 | + public function condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
|
| 479 | + $str="if(".$condition."){".$jsCodeIfTrue."}"; |
|
| 480 | + if (isset ($jsCodeIfFalse)) { |
|
| 481 | + $str.="else{".$jsCodeIfFalse."}"; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | if ($immediatly) |
| 485 | - $this->jquery_code_for_compile [] = $str; |
|
| 485 | + $this->jquery_code_for_compile []=$str; |
|
| 486 | 486 | return $str; |
| 487 | 487 | } |
| 488 | 488 | |
@@ -497,14 +497,14 @@ discard block |
||
| 497 | 497 | * @param boolean $immediatly |
| 498 | 498 | * @return string |
| 499 | 499 | */ |
| 500 | - private function _doJQuery($element, $jqueryCall, $param = "", $jsCallback = "", $immediatly = false) { |
|
| 501 | - $param = Javascript::prep_value ( $param ); |
|
| 502 | - $callback = ""; |
|
| 503 | - if ($jsCallback != "") |
|
| 504 | - $callback = ", function(event){\n{$jsCallback}\n}"; |
|
| 505 | - $script = "$(" . Javascript::prep_element ( $element ) . ")." . $jqueryCall . "(" . $param . $callback . ");\n"; |
|
| 500 | + private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
|
| 501 | + $param=Javascript::prep_value($param); |
|
| 502 | + $callback=""; |
|
| 503 | + if ($jsCallback!="") |
|
| 504 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
| 505 | + $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
|
| 506 | 506 | if ($immediatly) |
| 507 | - $this->jquery_code_for_compile [] = $script; |
|
| 507 | + $this->jquery_code_for_compile []=$script; |
|
| 508 | 508 | return $script; |
| 509 | 509 | } |
| 510 | 510 | |
@@ -521,8 +521,8 @@ discard block |
||
| 521 | 521 | * javascript code to execute after the jquery call |
| 522 | 522 | * @return mixed |
| 523 | 523 | */ |
| 524 | - public function doJQuery($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 525 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, true ); |
|
| 524 | + public function doJQuery($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 525 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, true); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -538,8 +538,8 @@ discard block |
||
| 538 | 538 | * javascript code to execute after the jquery call |
| 539 | 539 | * @return mixed |
| 540 | 540 | */ |
| 541 | - public function doJQueryDeferred($element, $jqueryCall, $param = "", $jsCallback = "") { |
|
| 542 | - return $this->_doJQuery ( $element, $jqueryCall, $param, $jsCallback, false ); |
|
| 541 | + public function doJQueryDeferred($element, $jqueryCall, $param="", $jsCallback="") { |
|
| 542 | + return $this->_doJQuery($element, $jqueryCall, $param, $jsCallback, false); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -556,8 +556,8 @@ discard block |
||
| 556 | 556 | * @param boolean $immediatly |
| 557 | 557 | * @return string |
| 558 | 558 | */ |
| 559 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $preventDefault = false, $stopPropagation = false, $jsCallback = "", $immediatly = true) { |
|
| 560 | - return $this->_add_event ( $element, $this->_doJQuery ( $elementToModify, $jqueryCall, $param, $jsCallback ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 559 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
| 560 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -571,13 +571,13 @@ discard block |
||
| 571 | 571 | * @param array $parameters |
| 572 | 572 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"jsCallback"=>'',"immediatly"=>true) |
| 573 | 573 | */ |
| 574 | - public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param = "", $parameters = array ()) { |
|
| 575 | - $jsCallback = ""; |
|
| 576 | - $stopPropagation = false; |
|
| 577 | - $preventDefault = false; |
|
| 578 | - $immediatly = true; |
|
| 579 | - extract ( $parameters ); |
|
| 580 | - return $this->_doJQueryOn ( $event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly ); |
|
| 574 | + public function doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $parameters=array()) { |
|
| 575 | + $jsCallback=""; |
|
| 576 | + $stopPropagation=false; |
|
| 577 | + $preventDefault=false; |
|
| 578 | + $immediatly=true; |
|
| 579 | + extract($parameters); |
|
| 580 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -589,10 +589,10 @@ discard block |
||
| 589 | 589 | * delayed if false |
| 590 | 590 | * @return String |
| 591 | 591 | */ |
| 592 | - public function exec($js, $immediatly = false) { |
|
| 593 | - $script = $js . "\n"; |
|
| 592 | + public function exec($js, $immediatly=false) { |
|
| 593 | + $script=$js."\n"; |
|
| 594 | 594 | if ($immediatly) |
| 595 | - $this->jquery_code_for_compile [] = $script; |
|
| 595 | + $this->jquery_code_for_compile []=$script; |
|
| 596 | 596 | return $script; |
| 597 | 597 | } |
| 598 | 598 | |
@@ -606,8 +606,8 @@ discard block |
||
| 606 | 606 | * @return String |
| 607 | 607 | */ |
| 608 | 608 | public function execAtLast($js) { |
| 609 | - $script = $js . "\n"; |
|
| 610 | - $this->jquery_code_for_compile_at_last [] = $script; |
|
| 609 | + $script=$js."\n"; |
|
| 610 | + $this->jquery_code_for_compile_at_last []=$script; |
|
| 611 | 611 | return $script; |
| 612 | 612 | } |
| 613 | 613 | |
@@ -622,18 +622,18 @@ discard block |
||
| 622 | 622 | * default : array("preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 623 | 623 | * @return String |
| 624 | 624 | */ |
| 625 | - public function execOn($event, $element, $js, $parameters = array ()) { |
|
| 626 | - $stopPropagation = false; |
|
| 627 | - $preventDefault = false; |
|
| 628 | - $immediatly = true; |
|
| 629 | - extract ( $parameters ); |
|
| 630 | - $script = $this->_add_event ( $element, $this->exec ( $js ), $event, $preventDefault, $stopPropagation, $immediatly ); |
|
| 625 | + public function execOn($event, $element, $js, $parameters=array()) { |
|
| 626 | + $stopPropagation=false; |
|
| 627 | + $preventDefault=false; |
|
| 628 | + $immediatly=true; |
|
| 629 | + extract($parameters); |
|
| 630 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 631 | 631 | return $script; |
| 632 | 632 | } |
| 633 | - public function setJsonToElement($json, $elementClass = "_element", $immediatly = true) { |
|
| 634 | - $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"; |
|
| 635 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 636 | - return $this->exec ( $retour, $immediatly ); |
|
| 633 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
| 634 | + $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"; |
|
| 635 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 636 | + return $this->exec($retour, $immediatly); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -644,13 +644,13 @@ discard block |
||
| 644 | 644 | * @param array $parameters |
| 645 | 645 | * default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
| 646 | 646 | */ |
| 647 | - public function setDraggable($element, $parameters = [ ]) { |
|
| 648 | - $attr = "id"; |
|
| 649 | - $preventDefault = false; |
|
| 650 | - $stopPropagation = false; |
|
| 651 | - $immediatly = true; |
|
| 652 | - extract ( $parameters ); |
|
| 653 | - $script = $this->_add_event ( $element, Javascript::draggable ( $attr ), "dragstart", $preventDefault, $stopPropagation, $immediatly ); |
|
| 647 | + public function setDraggable($element, $parameters=[]) { |
|
| 648 | + $attr="id"; |
|
| 649 | + $preventDefault=false; |
|
| 650 | + $stopPropagation=false; |
|
| 651 | + $immediatly=true; |
|
| 652 | + extract($parameters); |
|
| 653 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $preventDefault, $stopPropagation, $immediatly); |
|
| 654 | 654 | return $script; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | * @param string $jsCallback |
| 665 | 665 | * the js script to call when element is dropped |
| 666 | 666 | */ |
| 667 | - public function asDropZone($element, $jsCallback = "", $parameters = [ ]) { |
|
| 668 | - $stopPropagation = false; |
|
| 669 | - $immediatly = true; |
|
| 670 | - $jqueryDone = "append"; |
|
| 671 | - $script = $this->_add_event ( $element, '', "dragover", true, $stopPropagation, $immediatly ); |
|
| 672 | - extract ( $parameters ); |
|
| 673 | - $script .= $this->_add_event ( $element, Javascript::dropZone ( $jqueryDone, $jsCallback ), "drop", true, $stopPropagation, $immediatly ); |
|
| 667 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
| 668 | + $stopPropagation=false; |
|
| 669 | + $immediatly=true; |
|
| 670 | + $jqueryDone="append"; |
|
| 671 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
| 672 | + extract($parameters); |
|
| 673 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
| 674 | 674 | return $script; |
| 675 | 675 | } |
| 676 | 676 | |
@@ -687,16 +687,16 @@ discard block |
||
| 687 | 687 | * delayed if false |
| 688 | 688 | * @return string |
| 689 | 689 | */ |
| 690 | - public function interval($jsCode, $time, $globalName = null, $immediatly = true) { |
|
| 691 | - if (! Javascript::isFunction ( $jsCode )) { |
|
| 692 | - $jsCode = "function(){\n" . $jsCode . "\n}"; |
|
| 690 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
| 691 | + if (!Javascript::isFunction($jsCode)) { |
|
| 692 | + $jsCode="function(){\n".$jsCode."\n}"; |
|
| 693 | 693 | } |
| 694 | - if (isset ( $globalName )) { |
|
| 695 | - $script = "if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 694 | + if (isset ($globalName)) { |
|
| 695 | + $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
|
| 696 | 696 | } else { |
| 697 | - $script = "setInterval({$jsCode},{$time});"; |
|
| 697 | + $script="setInterval({$jsCode},{$time});"; |
|
| 698 | 698 | } |
| 699 | - return $this->exec ( $script, $immediatly ); |
|
| 699 | + return $this->exec($script, $immediatly); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -708,8 +708,8 @@ discard block |
||
| 708 | 708 | * delayed if false |
| 709 | 709 | * @return string |
| 710 | 710 | */ |
| 711 | - public function clearInterval($globalName, $immediatly = true) { |
|
| 712 | - return $this->exec ( "if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly ); |
|
| 711 | + public function clearInterval($globalName, $immediatly=true) { |
|
| 712 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -730,20 +730,20 @@ discard block |
||
| 730 | 730 | * delayed if false |
| 731 | 731 | * @return string |
| 732 | 732 | */ |
| 733 | - public function counter($counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true, $immediatly = true) { |
|
| 734 | - $stop = ""; |
|
| 733 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
| 734 | + $stop=""; |
|
| 735 | 735 | if ($countDown) { |
| 736 | - $stop = "if (--timer < " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 736 | + $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 737 | 737 | } else { |
| 738 | - if ($limit != 0) { |
|
| 739 | - $stop = "if (++timer > " . $limit . ") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:" . $limit . "});}"; |
|
| 738 | + if ($limit!=0) { |
|
| 739 | + $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
|
| 740 | 740 | } |
| 741 | 741 | } |
| 742 | - $global = ""; |
|
| 743 | - if (isset ( $globalName )) { |
|
| 744 | - $global = "\nwindow.{$globalName}=interval;"; |
|
| 742 | + $global=""; |
|
| 743 | + if (isset ($globalName)) { |
|
| 744 | + $global="\nwindow.{$globalName}=interval;"; |
|
| 745 | 745 | } |
| 746 | - $timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 746 | + $timer="var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds; |
|
| 747 | 747 | var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};}; |
| 748 | 748 | 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);}}; |
| 749 | 749 | var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';}; |
@@ -759,12 +759,12 @@ discard block |
||
| 759 | 759 | minutes = d0(parseInt((timer%3600) / 60, 10)); |
| 760 | 760 | seconds = d0(parseInt(timer%60, 10)); |
| 761 | 761 | mainSh(days,hours,minutes,seconds); |
| 762 | - " . $stop . " |
|
| 762 | + " . $stop." |
|
| 763 | 763 | }, 1000); |
| 764 | - " . $global . " |
|
| 764 | + " . $global." |
|
| 765 | 765 | }"; |
| 766 | - $element = '$("' . $counterSelector . '")'; |
|
| 767 | - return $this->exec ( $timer . "\nstartTimer(" . $value . "," . $element . ");", $immediatly ); |
|
| 766 | + $element='$("'.$counterSelector.'")'; |
|
| 767 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -786,8 +786,8 @@ discard block |
||
| 786 | 786 | * count down if true or elapse if false |
| 787 | 787 | * @return string |
| 788 | 788 | */ |
| 789 | - public function counterOn($element, $event, $counterSelector, $value = 0, $limit = 0, $globalName = null, $countDown = true) { |
|
| 790 | - return $this->execOn ( $event, $element, $this->counter ( $counterSelector, $value, $limit, $globalName, $countDown, false ) ); |
|
| 789 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
| 790 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -801,8 +801,8 @@ discard block |
||
| 801 | 801 | * the active href (if null, window.location.href is used) |
| 802 | 802 | * @return string |
| 803 | 803 | */ |
| 804 | - public function activateLink($target, $property = 'href', $href = null) { |
|
| 805 | - return $this->execAtLast ( $this->_activateLink ( $target, $property, $href ) ); |
|
| 804 | + public function activateLink($target, $property='href', $href=null) { |
|
| 805 | + return $this->execAtLast($this->_activateLink($target, $property, $href)); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | /** |
@@ -816,14 +816,14 @@ discard block |
||
| 816 | 816 | * the active href (if null, window.location.href is used) |
| 817 | 817 | * @return string |
| 818 | 818 | */ |
| 819 | - public function _activateLink($target, $property = 'href', $href = null) { |
|
| 820 | - $js = '$("' . $target . ' [' . $property . ']").removeClass("active");'; |
|
| 821 | - if (isset ( $href )) { |
|
| 822 | - $js .= 'var href="' . $href . '";'; |
|
| 819 | + public function _activateLink($target, $property='href', $href=null) { |
|
| 820 | + $js='$("'.$target.' ['.$property.']").removeClass("active");'; |
|
| 821 | + if (isset ($href)) { |
|
| 822 | + $js.='var href="'.$href.'";'; |
|
| 823 | 823 | } else { |
| 824 | - $js .= 'var href=window.location.href;'; |
|
| 824 | + $js.='var href=window.location.href;'; |
|
| 825 | 825 | } |
| 826 | - $js .= '$("' . $target . ' [' . $property . ']").each(function(){if(href.includes($(this).attr("' . $property . '"))) $(this).addClass("active");});'; |
|
| 826 | + $js.='$("'.$target.' ['.$property.']").each(function(){if(href.includes($(this).attr("'.$property.'"))) $(this).addClass("active");});'; |
|
| 827 | 827 | return $js; |
| 828 | 828 | } |
| 829 | 829 | } |