@@ -38,8 +38,10 @@ protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
38
38
if ($ hasLoader ===true && JString::isNotNull ($ responseElement )){
39
39
$ this ->addLoading ($ retour , $ responseElement );
40
40
}
41
- $ async =($ async )?"true " :"false " ;
42
- $ ajaxParameters =["url " =>"url " ,"method " =>"' " .\strtoupper ($ method )."' " ,"async " =>$ async ];
41
+ $ ajaxParameters =["url " =>"url " ,"method " =>"' " .\strtoupper ($ method )."' " ];
42
+ if (!$ async ){
43
+ $ ajaxParameters ["async " ]="false " ;
44
+ }
43
45
if (isset ($ params )){
44
46
$ ajaxParameters ["data " ]=self ::_correctParams ($ params );
45
47
}
@@ -230,85 +232,66 @@ public function ajaxDeferred($method,$url, $responseElement="", $parameters=[])
230
232
/**
231
233
* Performs an ajax request and receives the JSON data types by assigning DOM elements with the same name
232
234
* @param string $url the request url
233
- * @param string $params JSON parameters
234
235
* @param string $method Method used
235
- * @param string $jsCallback javascript code to execute after the request
236
- * @param string $attr
237
- * @param string $context
238
- * @param boolean $immediatly
236
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
239
237
*/
240
- private function _json ($ url , $ method ="get " , $ params = " {} " , $ jsCallback = NULL , $ attr = " id " , $ context = " document " , $ immediatly = false ) {
241
- $ jsCallback = isset ( $ jsCallback ) ? $ jsCallback : "" ;
242
- $ retour = $ this -> _getAjaxUrl ( $ url , $ attr ) ;
243
- $ retour .= " $. { $ method } (url, " . $ params . " ).done(function( data ) { \n " ;
244
- $ retour. ="\tdata=$.parseJSON (data);for (var key in data){ "
238
+ private function _json ($ url , $ method ="get " ,$ parameters =[] ) {
239
+ $ parameters = \array_merge ( $ parameters ,[ " hasLoader " => false ]) ;
240
+ $ jsCallback = isset ( $ parameters [ ' jsCallback ' ]) ? $ parameters [ ' jsCallback ' ] : "" ;
241
+ $ context = isset ( $ parameters [ ' context ' ]) ? $ parameters [ ' context ' ] : " document " ;
242
+ $ retour ="\tdata=($.isPlainObject (data))?data:JSON.parse(data); \t" . $ jsCallback . " ; \n\t for (var key in data){ "
245
243
."if($('#'+key, " .$ context .").length){ if($('#'+key, " .$ context .").is('[value]')) { $('#'+key, " .$ context .").val(data[key]);} else { $('#'+key, " .$ context .").html(data[key]); }}}; \n" ;
246
- $ retour .="\t" .$ jsCallback ."\n" .
247
- "\t$(document).trigger('jsonReady',[data]); \n" .
248
- "}); \n" ;
249
- if ($ immediatly )
250
- $ this ->jquery_code_for_compile []=$ retour ;
251
- return $ retour ;
244
+ $ retour .="\t$(document).trigger('jsonReady',[data]); \n" ;
245
+ $ parameters ["jsCallback " ]=$ retour ;
246
+ return $ this ->_ajax ($ method , $ url ,null ,$ parameters );
252
247
}
253
248
254
249
/**
255
250
* Performs an ajax request and receives the JSON data types by assigning DOM elements with the same name
256
251
* @param string $url the request url
257
- * @param string $params JSON parameters
258
252
* @param string $method Method used
259
- * @param string $jsCallback javascript code to execute after the request
260
- * @param string $context
261
- * @param boolean $immediatly
253
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
262
254
*/
263
- public function json ($ url , $ method ="get " , $ params = " {} " , $ jsCallback = NULL , $ context = " document " , $ immediatly = false ) {
264
- return $ this ->_json ($ url ,$ method ,$ params , $ jsCallback , NULL , $ context , $ immediatly );
255
+ public function json ($ url , $ method ="get " , $ parameters =[] ) {
256
+ return $ this ->_json ($ url ,$ method ,$ parameters );
265
257
}
266
258
267
259
/**
268
260
* Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name when $event fired on $element
269
261
* @param string $element
270
262
* @param string $event
271
263
* @param string $url the request address
264
+ * @param string $method default get
272
265
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true)
273
266
*/
274
- public function jsonOn ($ event ,$ element , $ url ,$ parameters =array ()) {
275
- $ preventDefault =true ;
276
- $ stopPropagation =true ;
277
- $ jsCallback =null ;
278
- $ attr ="id " ;
279
- $ method ="get " ;
280
- $ context ="document " ;
281
- $ params ="{} " ;
282
- $ immediatly =true ;
283
- extract ($ parameters );
284
- return $ this ->_add_event ($ element , $ this ->_json ($ url ,$ method , $ params ,$ jsCallback , $ attr ,$ context ), $ event , $ preventDefault , $ stopPropagation ,$ immediatly );
267
+ public function jsonOn ($ event ,$ element , $ url ,$ method ="get " ,$ parameters =array ()) {
268
+ $ this ->setDefaultParameters ($ parameters , ["preventDefault " =>true ,"stopPropagation " =>true ,"immediatly " =>true ]);
269
+ return $ this ->_add_event ($ element , $ this ->jsonDeferred ($ url ,$ method , $ parameters ), $ event , $ parameters ["preventDefault " ], $ parameters ["stopPropagation " ],$ parameters ["immediatly " ]);
285
270
}
286
271
287
272
/**
288
273
* Prepares an ajax request delayed and receives the JSON data types by assigning DOM elements with the same name
289
274
* @param string $url the request url
290
- * @param string $params Paramètres passés au format JSON
291
275
* @param string $method Method used
292
- * @param string $jsCallback javascript code to execute after the request
293
- * @param string $context jquery DOM element, array container.
276
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
294
277
*/
295
- public function jsonDeferred ($ url , $ method ="get " , $ params ="{} " , $ jsCallback =NULL ,$ context =NULL ) {
296
- return $ this ->json ($ url , $ method , $ params , $ jsCallback , $ context ,false );
278
+ public function jsonDeferred ($ url , $ method ="get " , $ parameters =[]) {
279
+ $ parameters ["immediatly " ]=false ;
280
+ return $ this ->_json ($ url ,$ method ,$ parameters );
297
281
}
298
282
299
283
/**
300
284
* Performs an ajax request and receives the JSON array data types by assigning DOM elements with the same name
285
+ * @param string $maskSelector
301
286
* @param string $url the request url
302
- * @param string $params The JSON parameters
303
- * @param string $method Method used
304
- * @param string $jsCallback javascript code to execute after the request
305
- * @param string $context jquery DOM element, array container.
306
- * @param string $rowClass the css class for the new element
307
- * @param boolean $immediatly
287
+ * @param string $method Method used, default : get
288
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
308
289
*/
309
- private function _jsonArray ($ maskSelector , $ url , $ method ="get " , $ params ="{} " , $ jsCallback =NULL ,$ rowClass ="_json " ,$ context =NULL ,$ attr ="id " ,$ immediatly =false ) {
310
- $ jsCallback =isset ($ jsCallback ) ? $ jsCallback : "" ;
311
- $ retour =$ this ->_getAjaxUrl ($ url , $ attr );
290
+ private function _jsonArray ($ maskSelector , $ url , $ method ="get " , $ parameters =[]) {
291
+ $ parameters =\array_merge ($ parameters ,["hasLoader " =>false ]);
292
+ $ rowClass =isset ($ parameters ['rowClass ' ]) ? $ parameters ['rowClass ' ] : "_json " ;
293
+ $ jsCallback =isset ($ parameters ['jsCallback ' ]) ? $ parameters ['jsCallback ' ] : "" ;
294
+ $ context =isset ($ parameters ['context ' ]) ? $ parameters ['context ' ] : null ;
312
295
if ($ context ===null ){
313
296
$ parent ="$(' " .$ maskSelector ."').parent() " ;
314
297
$ newElm = "$('#'+newId) " ;
@@ -317,66 +300,50 @@ private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $j
317
300
$ newElm = $ context .".find('#'+newId) " ;
318
301
}
319
302
$ appendTo ="\t\tnewElm.appendTo( " .$ parent ."); \n" ;
320
- $ retour .="var self = $(this); \n$. {$ method }(url, " .$ params .").done(function( data ) { \n" ;
321
- $ retour .=$ parent .".find('._json').remove(); " ;
322
- $ retour .="\tdata=$.parseJSON(data);$.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();
303
+ $ retour =$ parent .".find('. {$ rowClass }').remove(); " ;
304
+ $ retour .="\tdata=($.isPlainObject(data))?data:JSON.parse(data); \t" .$ jsCallback ."; \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();
323
305
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" ;
324
306
$ retour .= $ appendTo ;
325
307
$ 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" ;
326
308
$ retour .="\t$(document).trigger('jsonReady',[data]); \n" ;
327
- $ retour .="\t" .$ jsCallback ."\n" ."}); \n" ;
328
- if ($ immediatly )
329
- $ this ->jquery_code_for_compile []=$ retour ;
330
- return $ retour ;
309
+ $ parameters ["jsCallback " ]=$ retour ;
310
+ return $ this ->_ajax ($ method , $ url ,null ,$ parameters );
331
311
}
332
312
333
313
/**
334
314
* Performs an ajax request and receives the JSON array data types by assigning DOM elements with the same name
315
+ * @param string $maskSelector
335
316
* @param string $url the request url
336
- * @param string $params The JSON parameters
337
- * @param string $method Method used
338
- * @param string $jsCallback javascript code to execute after the request
339
- * @param string $rowClass the css class for the new element
340
- * @param string $context jquery DOM element, array container.
341
- * @param boolean $immediatly
317
+ * @param string $method Method used, default : get
318
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
342
319
*/
343
- public function jsonArray ($ maskSelector , $ url , $ method ="get " , $ params = " {} " , $ jsCallback = NULL , $ rowClass = " _json " , $ context = NULL , $ immediatly = false ) {
344
- return $ this ->_jsonArray ($ maskSelector , $ url ,$ method ,$ params , $ jsCallback , $ rowClass , $ context , NULL , $ immediatly );
320
+ public function jsonArray ($ maskSelector , $ url , $ method ="get " , $ parameters =[] ) {
321
+ return $ this ->_jsonArray ($ maskSelector , $ url ,$ method ,$ parameters );
345
322
}
346
323
347
324
/**
348
325
* Peforms an ajax request delayed and receives a JSON array data types by copying and assigning them to the DOM elements with the same name
349
- * @param string $maskSelector the selector of the element to clone
326
+ * @param string $maskSelector
350
327
* @param string $url the request url
351
- * @param string $params JSON parameters
352
- * @param string $method Method used
353
- * @param string $jsCallback javascript code to execute after the request
354
- * @param string $rowClass the css class for the new element
355
- * @param string $context jquery DOM element, array container.
328
+ * @param string $method Method used, default : get
329
+ * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json")
356
330
*/
357
- public function jsonArrayDeferred ($ maskSelector , $ url , $ method ="get " , $ params ="{} " , $ jsCallback =NULL ,$ rowClass ="_json " ,$ context =NULL ) {
358
- return $ this ->jsonArray ($ maskSelector , $ url , $ method , $ params , $ jsCallback ,$ rowClass ,$ context ,false );
331
+ public function jsonArrayDeferred ($ maskSelector , $ url , $ method ="get " , $ parameters ) {
332
+ $ parameters ["immediatly " ]=false ;
333
+ return $ this ->jsonArray ($ maskSelector , $ url , $ method , $ parameters );
359
334
}
360
335
361
336
/**
362
337
* Performs an ajax request and receives the JSON array data types by assigning DOM elements with the same name when $event fired on $element
363
338
* @param string $element
364
339
* @param string $event
365
340
* @param string $url the request url
341
+ * @param string $method Method used, default : get
366
342
* @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true)
367
343
*/
368
- public function jsonArrayOn ($ event ,$ element ,$ maskSelector , $ url ,$ parameters =array ()) {
369
- $ preventDefault =true ;
370
- $ stopPropagation =true ;
371
- $ jsCallback =null ;
372
- $ attr ="id " ;
373
- $ method ="get " ;
374
- $ context = null ;
375
- $ params ="{} " ;
376
- $ immediatly =true ;
377
- $ rowClass ="_json " ;
378
- extract ($ parameters );
379
- return $ this ->_add_event ($ element , $ this ->_jsonArray ($ maskSelector ,$ url ,$ method , $ params ,$ jsCallback , $ rowClass , $ context ,$ attr ), $ event , $ preventDefault , $ stopPropagation ,$ immediatly );
344
+ public function jsonArrayOn ($ event ,$ element ,$ maskSelector , $ url ,$ method ="get " ,$ parameters =array ()) {
345
+ $ this ->setDefaultParameters ($ parameters , ["preventDefault " =>true ,"stopPropagation " =>true ,"immediatly " =>true ]);
346
+ return $ this ->_add_event ($ element , $ this ->jsonArrayDeferred ($ maskSelector ,$ url ,$ method , $ parameters ), $ event , $ parameters ["preventDefault " ], $ parameters ["stopPropagation " ],$ parameters ["immediatly " ]);
380
347
}
381
348
382
349
/**
0 commit comments