1313trait 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 );
0 commit comments