Skip to content

Commit 93b0d76

Browse files
committed
ajax async
1 parent 966ba4c commit 93b0d76

File tree

10 files changed

+59
-16
lines changed

10 files changed

+59
-16
lines changed

Ajax/common/html/HtmlCollection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Ajax\service\JArray;
77
use Ajax\JsUtils;
88
use Ajax\service\JReflection;
9+
use Ajax\service\JString;
910

1011
/**
1112
* Base class for Html collections
@@ -51,7 +52,7 @@ protected function getItemToAdd($item){
5152

5253
protected function setItemIdentifier($item,$classname,$index){
5354
if($item instanceof BaseWidget){
54-
if($item->getIdentifier()===""){
55+
if(JString::isNull($item->getIdentifier())){
5556
$item->setIdentifier($classname."-".$this->identifier."-".$index);
5657
}
5758
}

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
2525
$immediatly=false;
2626
$jqueryDone="html";
2727
$ajaxTransition=null;
28+
$async=true;
2829
$params=null;
2930
$headers=null;
3031
$jsCondition=null;
@@ -37,8 +38,8 @@ protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
3738
if($hasLoader===true && JString::isNotNull($responseElement)){
3839
$this->addLoading($retour, $responseElement);
3940
}
40-
41-
$ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"];
41+
$async=($async)?"true":"false";
42+
$ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'","async"=>$async];
4243
if(isset($params)){
4344
$ajaxParameters["data"]=self::_correctParams($params);
4445
}
@@ -98,7 +99,7 @@ protected function _getAjaxUrl($url,$attr){
9899

99100
protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){
100101
$retour="";$call=null;
101-
if ($responseElement!=="") {
102+
if (JString::isNotNull($responseElement)) {
102103
if(isset($ajaxTransition)){
103104
$call=$this->setAjaxDataCall($ajaxTransition);
104105
}elseif(isset($this->ajaxTransition)){
@@ -114,7 +115,7 @@ protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$
114115
}
115116

116117
protected function _getResponseElement($responseElement){
117-
if ($responseElement!=="") {
118+
if (JString::isNotNull($responseElement)) {
118119
$responseElement=Javascript::prep_value($responseElement);
119120
$responseElement=Javascript::prep_jquery_selector($responseElement);
120121
}
@@ -500,8 +501,9 @@ public function postOnClick($element, $url, $params="{}", $responseElement="", $
500501
}
501502

502503
private function _postForm($url, $form, $responseElement, $parameters=[]) {
503-
$params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;
504+
$params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;$async=true;
504505
\extract($parameters);
506+
$async=($async)?"true":"false";
505507
$jsCallback=isset($jsCallback) ? $jsCallback : "";
506508
$retour=$this->_getAjaxUrl($url, $attr);
507509
$retour.="\nvar params=$('#".$form."').serialize();\n";
@@ -513,7 +515,7 @@ private function _postForm($url, $form, $responseElement, $parameters=[]) {
513515
if($hasLoader===true){
514516
$this->addLoading($retour, $responseElement);
515517
}
516-
$ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params"];
518+
$ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async];
517519
if(isset($headers)){
518520
$ajaxParameters["headers"]=$headers;
519521
}

Ajax/common/traits/JsUtilsEventsTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public function blur($element='this', $js='') {
3333
*
3434
* @param string $element element to attach the event to
3535
* @param string $js code to execute
36+
* @param boolean $preventDefault
37+
* @param boolean $stopPropagation
3638
* @return string
3739
*/
38-
public function change($element='this', $js='') {
39-
return $this->_add_event($element, $js, 'change');
40+
public function change($element='this', $js='',$preventDefault=false,$stopPropagation=false) {
41+
return $this->_add_event($element, $js, 'change',$preventDefault,$stopPropagation);
4042
}
4143

4244
/**

Ajax/semantic/components/Dropdown.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public function setOn($event){
3333
public function setFullTextSearch($value){
3434
return $this->setParam("fullTextSearch", $value);
3535
}
36+
37+
public function setShowOnFocus($value){
38+
return $this->setParam("showOnFocus", $value);
39+
}
3640
}

Ajax/semantic/components/validation/FieldValidation.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,24 @@ public function getRules() {
4242
return $this->rules;
4343
}
4444

45+
/**
46+
* @param string $type
47+
* @param string $prompt
48+
* @param string $value
49+
* @return Rule
50+
*/
4551
public function addRule($type,$prompt=NULL,$value=NULL){
4652
if($type instanceof Rule)
47-
$this->rules[]=$type;
53+
$rule=$type;
4854
else if(\is_array($type)){
4955
$value=JArray::getValue($type, "value", 2);
5056
$prompt=JArray::getValue($type, "prompt", 1);
5157
$type=JArray::getValue($type, "type", 0);
52-
$this->rules[]=new Rule($type,$prompt,$value);
58+
$rule=new Rule($type,$prompt,$value);
5359
}else
54-
$this->rules[]=new Rule($type,$prompt,$value);
60+
$rule=new Rule($type,$prompt,$value);
61+
$this->rules[]=$rule;
62+
return $rule;
5563
}
5664

5765
public function jsonSerialize(){

Ajax/semantic/components/validation/Rule.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Ajax\semantic\components\validation;
3+
use Ajax\service\AjaxCall;
4+
use Ajax\JsUtils;
5+
36
/**
47
* @author jc
58
* @version 1.001
@@ -163,4 +166,10 @@ public static function custom($name,$jsFunction){
163166
return "$.fn.form.settings.rules.".$name." =".$jsFunction ;
164167
}
165168

169+
public static function ajax(JsUtils $js,$name,$url,$params,$jsCallback,$method="post",$parameters=[]){
170+
$parameters=\array_merge(["async"=>false,"url"=>$url,"params"=>$params,"hasLoader"=>false,"jsCallback"=>$jsCallback,"dataType"=>"json","stopPropagation"=>false,"preventDefault"=>false,"responseElement"=>null],$parameters);
171+
$ajax=new AjaxCall($method, $parameters);
172+
return self::custom($name, "function(value){var result=true;".$ajax->compile($js)."console.log(result);return result;}");
173+
}
174+
166175
}

Ajax/semantic/html/collections/form/HtmlForm.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function addDivider($caption=NULL){
7070
* Adds a group of fields
7171
* @param array $fields
7272
* @param string $label
73-
* @return string|\Ajax\semantic\html\collections\form\HtmlFormFields
73+
* @return HtmlFormFields
7474
*/
7575
public function addFields($fields=NULL, $label=NULL) {
7676
if (isset($fields)) {
@@ -87,8 +87,9 @@ public function addFields($fields=NULL, $label=NULL) {
8787
$this->_fields=\array_merge($this->_fields, $fields);
8888
$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count(), $fields);
8989
}
90-
if (isset($label))
91-
$fields=new HtmlFormField("", $fields, $label);
90+
if (isset($label)){
91+
$fields->wrap("<div class='field'><label>{$label}</label>","</div>");
92+
}
9293
} else {
9394
$fields=new HtmlFormFields("fields-" . $this->identifier . "-" . $this->count());
9495
}

Ajax/semantic/html/elements/HtmlButtonGroups.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ protected function createItem($value){
2626
return new HtmlButton("", $value);
2727
}
2828

29+
/**
30+
* @param array $items
31+
* @param boolean $asCombo
32+
* @return HtmlDropdown
33+
*/
2934
public function addDropdown($items,$asCombo=false){
3035
$dd= new HtmlDropdown("dd-".$this->identifier,null,$items);
3136
$dd->asButton();

Ajax/semantic/html/modules/HtmlDropdown.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HtmlDropdown extends HtmlSemDoubleElement {
1919
protected $mClass="menu";
2020
protected $mTagName="div";
2121
protected $items=array ();
22-
protected $_params=array("action"=>"nothing","on"=>"hover");
22+
protected $_params=array("action"=>"nothing","on"=>"hover","showOnFocus"=>false);
2323
protected $input;
2424
protected $value;
2525
protected $_associative;
@@ -349,6 +349,14 @@ public function setAction($action){
349349
$this->_params["action"]=$action;
350350
}
351351

352+
public function setOn($on){
353+
$this->_params["on"]=$on;
354+
}
355+
356+
public function setShowOnFocus($value){
357+
$this->_params["showOnFocus"]=$value;
358+
}
359+
352360
public function setFullTextSearch($value){
353361
$this->_params["fullTextSearch"]=$value;
354362
}

Ajax/service/AjaxCall.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function compile(JsUtils $js=null) {
4141
case "jsonArray":
4242
$result.=$js->jsonArrayDeferred($modelSelector, $url,$method,$params,$jsCallback,$rowClass);
4343
break;
44+
default:
45+
//$result.=$js->ajax($this->method, $url,$responseElement,$this->parameters);
46+
break;
4447
}
4548
return $result;
4649
}

0 commit comments

Comments
 (0)