Skip to content

Commit 2c24bb2

Browse files
committed
add ajaxLoader in ajax attributes
1 parent afb7ea3 commit 2c24bb2

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
trait JsUtilsAjaxTrait {
1414

1515
protected $ajaxTransition;
16-
protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>';
16+
protected $ajaxLoader='Loading...';
1717

1818
abstract public function getUrl($url);
1919
abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true);
@@ -29,14 +29,15 @@ protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
2929
$params=null;
3030
$headers=null;
3131
$jsCondition=null;
32+
$ajaxLoader=null;
3233
extract($parameters);
3334

3435
$jsCallback=isset($jsCallback) ? $jsCallback : "";
3536
$retour=$this->_getAjaxUrl($url, $attr);
3637
$responseElement=$this->_getResponseElement($responseElement);
3738
$retour.="var self=this;\n";
3839
if($hasLoader===true && JString::isNotNull($responseElement)){
39-
$this->addLoading($retour, $responseElement);
40+
$this->addLoading($retour, $responseElement,$ajaxLoader);
4041
}
4142
$ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"];
4243
if(!$async){
@@ -152,14 +153,11 @@ public static function _implodeParams($parameters){
152153
return \implode("+'&'+", $allParameters);
153154
}
154155

155-
protected function addLoading(&$retour, $responseElement) {
156-
$loading_notifier='<div class="ajax-loader">';
157-
if ($this->ajaxLoader==='') {
158-
$loading_notifier.="Loading...";
159-
} else {
160-
$loading_notifier.=$this->ajaxLoader;
156+
protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) {
157+
if(!isset($ajaxLoader)){
158+
$ajaxLoader=$this->ajaxLoader;
161159
}
162-
$loading_notifier.='</div>';
160+
$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
163161
$retour.="{$responseElement}.empty();\n";
164162
$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
165163
}
@@ -198,7 +196,7 @@ private function _get($url, $responseElement="",$parameters=[]) {
198196
* Performs an ajax GET request
199197
* @param string $url The url of the request
200198
* @param string $responseElement selector of the HTML element displaying the answer
201-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
199+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
202200
*/
203201
public function get($url, $responseElement="",$parameters=[]) {
204202
$parameters["immediatly"]=true;
@@ -210,7 +208,7 @@ public function get($url, $responseElement="",$parameters=[]) {
210208
* @param string $method The http method (get, post, delete, put, head)
211209
* @param string $url The url of the request
212210
* @param string $responseElement selector of the HTML element displaying the answer
213-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
211+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
214212
*/
215213
public function ajax($method,$url, $responseElement="", $parameters=[]) {
216214
$parameters["immediatly"]=true;
@@ -222,7 +220,7 @@ public function ajax($method,$url, $responseElement="", $parameters=[]) {
222220
* @param string $method The http method (get, post, delete, put, head)
223221
* @param string $url The url of the request
224222
* @param string $responseElement selector of the HTML element displaying the answer
225-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
223+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
226224
*/
227225
public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) {
228226
$parameters["immediatly"]=false;
@@ -351,7 +349,7 @@ public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$p
351349
* To use on an event
352350
* @param string $url The url of the request
353351
* @param string $responseElement selector of the HTML element displaying the answer
354-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
352+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
355353
*/
356354
public function getDeferred($url, $responseElement="", $parameters=[]) {
357355
$parameters["immediatly"]=false;
@@ -365,7 +363,7 @@ public function getDeferred($url, $responseElement="", $parameters=[]) {
365363
* @param string $element
366364
* @param string $url The url of the request
367365
* @param string $responseElement The selector of the HTML element displaying the answer
368-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null)
366+
* @param array $parameters 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)
369367
*/
370368
public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
371369
$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
@@ -379,7 +377,7 @@ public function getOn($event, $element, $url, $responseElement="", $parameters=a
379377
* @param string $element
380378
* @param string $url The url of the request
381379
* @param string $responseElement The selector of the HTML element displaying the answer
382-
* @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null)
380+
* @param array $parameters 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)
383381
*/
384382
public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) {
385383
$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]);
@@ -392,7 +390,7 @@ public function ajaxOn($event, $element, $url, $responseElement="", $parameters=
392390
* @param string $element
393391
* @param string $url The url of the request
394392
* @param string $responseElement The selector of the HTML element displaying the answer
395-
* @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null)
393+
* @param array $parameters 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)
396394
*/
397395
public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) {
398396
return $this->ajaxOn("click", $element, $url, $responseElement, $parameters);
@@ -404,7 +402,7 @@ public function ajaxOnClick($element, $url, $responseElement="", $parameters=arr
404402
* @param string $element
405403
* @param string $url The url of the request
406404
* @param string $responseElement The selector of the HTML element displaying the answer
407-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null)
405+
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null)
408406
*/
409407
public function getOnClick($element, $url, $responseElement="", $parameters=array()) {
410408
return $this->getOn("click", $element, $url, $responseElement, $parameters);
@@ -420,7 +418,7 @@ private function _post($url, $params="{}",$responseElement="", $parameters=[]) {
420418
* @param string $url the request url
421419
* @param string $responseElement selector of the HTML element displaying the answer
422420
* @param string $params JSON parameters
423-
* @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
421+
* @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
424422
*/
425423
public function post($url, $params="{}",$responseElement="", $parameters=[]) {
426424
return $this->_post($url, $params,$responseElement, $parameters);
@@ -432,7 +430,7 @@ public function post($url, $params="{}",$responseElement="", $parameters=[]) {
432430
* @param string $url the request url
433431
* @param string $params JSON parameters
434432
* @param string $responseElement selector of the HTML element displaying the answer
435-
* @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
433+
* @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
436434
*/
437435
public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) {
438436
$parameters["immediatly"]=false;
@@ -447,7 +445,7 @@ public function postDeferred($url, $params="{}",$responseElement="", $parameters
447445
* @param string $url The url of the request
448446
* @param string $params The parameters to send
449447
* @param string $responseElement selector of the HTML element displaying the answer
450-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
448+
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
451449
*/
452450
public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
453451
$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
@@ -461,14 +459,14 @@ public function postOn($event, $element, $url, $params="{}", $responseElement=""
461459
* @param string $url The url of the request
462460
* @param string $params The parameters to send
463461
* @param string $responseElement selector of the HTML element displaying the answer
464-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
462+
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
465463
*/
466464
public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) {
467465
return $this->postOn("click", $element, $url, $params, $responseElement, $parameters);
468466
}
469467

470468
private function _postForm($url, $form, $responseElement, $parameters=[]) {
471-
$params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;$async=true;
469+
$params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$ajaxLoader=null;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;$async=true;
472470
\extract($parameters);
473471
$async=($async)?"true":"false";
474472
$jsCallback=isset($jsCallback) ? $jsCallback : "";
@@ -480,7 +478,7 @@ private function _postForm($url, $form, $responseElement, $parameters=[]) {
480478
$responseElement=$this->_getResponseElement($responseElement);
481479
$retour.="var self=this;\n";
482480
if($hasLoader===true){
483-
$this->addLoading($retour, $responseElement);
481+
$this->addLoading($retour, $responseElement,$ajaxLoader);
484482
}
485483
$ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async];
486484
if(isset($headers)){
@@ -507,7 +505,7 @@ private function _postForm($url, $form, $responseElement, $parameters=[]) {
507505
* @param string $url The url of the request
508506
* @param string $form The form HTML id
509507
* @param string $responseElement selector of the HTML element displaying the answer
510-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
508+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
511509
*/
512510
public function postForm($url, $form, $responseElement, $parameters=[]) {
513511
$parameters["immediatly"]=true;
@@ -520,7 +518,7 @@ public function postForm($url, $form, $responseElement, $parameters=[]) {
520518
* @param string $url The url of the request
521519
* @param string $form The form HTML id
522520
* @param string $responseElement selector of the HTML element displaying the answer
523-
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
521+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
524522
*/
525523
public function postFormDeferred($url, $form, $responseElement, $parameters=[]) {
526524
$parameters["immediatly"]=false;
@@ -535,7 +533,7 @@ public function postFormDeferred($url, $form, $responseElement, $parameters=[])
535533
* @param string $url
536534
* @param string $form
537535
* @param string $responseElement selector of the HTML element displaying the answer
538-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null)
536+
* @param array $parameters 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)
539537
*/
540538
public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
541539
$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
@@ -549,7 +547,7 @@ public function postFormOn($event, $element, $url, $form, $responseElement="", $
549547
* @param string $url
550548
* @param string $form
551549
* @param string $responseElement selector of the HTML element displaying the answer
552-
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null)
550+
* @param array $parameters 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)
553551
*/
554552
public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) {
555553
return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters);

Ajax/semantic/components/jsTemplates/tplCheckedList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
else {
3636
$parentCheckbox.checkbox("set indeterminate");
3737
}
38+
%onChange%
3839
}
3940
})
4041
;';

Ajax/semantic/html/elements/HtmlList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class HtmlList extends HtmlSemCollection {
1212
protected $_hasCheckedList;
1313
protected $_fireOnInit=true;
14+
protected $_ckItemChange="";
1415

1516
public function __construct($identifier, $items=array()) {
1617
parent::__construct($identifier, "div", "ui list");
@@ -73,10 +74,15 @@ public function run(JsUtils $js) {
7374
$jsCode=include dirname(__FILE__) . '/../../components/jsTemplates/tplCheckedList.php';
7475
$jsCode=\str_replace("%identifier%", "#" . $this->identifier, $jsCode);
7576
$jsCode=\str_replace("%fireOnInit%", $this->_fireOnInit, $jsCode);
77+
$jsCode=\str_replace("%onChange%", $this->_ckItemChange, $jsCode);
7678
$this->executeOnRun($jsCode);
7779
}
7880
return parent::run($js);
7981
}
82+
83+
public function onCkItemChange($jsCode){
84+
$this->_ckItemChange=$jsCode;
85+
}
8086

8187
/**
8288
* @param boolean $fireOnInit

Ajax/semantic/html/modules/checkbox/AbstractCheckbox.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct($identifier, $name=NULL, $label=NULL, $value=NULL, $
1616
$field->setProperty("name", $name);
1717
$this->setField($field);
1818
if (isset($label))
19-
$this->setLabel($label);
19+
$this->setLabel($label,$value);
2020
}
2121

2222
public function setChecked($value=true){
@@ -32,12 +32,14 @@ public function setType($checkboxType) {
3232
return $this->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
3333
}
3434

35-
public function setLabel($label) {
35+
public function setLabel($label,$value=null) {
3636
$labelO=$label;
3737
if (\is_string($label)) {
3838
$labelO=new HtmlSemDoubleElement("", "label", "");
3939
$labelO->setContent($label);
4040
$labelO->setProperty("for", $this->getField()->getIdentifier());
41+
if(isset($value))
42+
$labelO->setProperty("data-value", $value);
4143
}
4244
$this->content["label"]=$labelO;
4345
}

0 commit comments

Comments
 (0)