@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
6 | 6 | use Ajax\JsUtils; |
7 | - |
|
8 | 7 | use Ajax\common\html\html5\HtmlSelect; |
9 | 8 | use Ajax\service\JString; |
10 | 9 |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | public function __construct($identifier) { |
17 | 17 | parent::__construct($identifier, "form"); |
18 | 18 | $this->_template='<form id="%identifier%" name="%identifier%" %properties%>%content%</form>'; |
19 | - $this->futureElements=array (); |
|
20 | - $this->formGroups=array (); |
|
19 | + $this->futureElements=array(); |
|
20 | + $this->formGroups=array(); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /* |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
28 | 28 | if (isset($js)) { |
29 | 29 | $this->formElementsPrefix=$js->config()->getVar("formElementsPrefix"); |
30 | - foreach ( $this->futureElements as $futureElement ) { |
|
30 | + foreach ($this->futureElements as $futureElement) { |
|
31 | 31 | $futureElementValue=$this->getPrefix($futureElement); |
32 | 32 | $futureElementValues=explode("_", $futureElementValue); |
33 | - switch($futureElementValues [0]) { |
|
33 | + switch ($futureElementValues [0]) { |
|
34 | 34 | case "input": |
35 | 35 | $control=new HtmlInput($futureElement); |
36 | 36 | $control->setClass("form-control"); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $control->setLabel($label, false); |
49 | 49 | break; |
50 | 50 | case "select": |
51 | - $control=new HtmlSelect($futureElement,""); |
|
51 | + $control=new HtmlSelect($futureElement, ""); |
|
52 | 52 | $control->setProperty("size", $futureElementValues [1]); |
53 | 53 | $control->setClass("form-control"); |
54 | 54 | //$control->setLabel($this->getPart($futureElement)); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->addElement($control); |
64 | 64 | } |
65 | 65 | } |
66 | - foreach ( $this->formGroups as $group ) { |
|
66 | + foreach ($this->formGroups as $group) { |
|
67 | 67 | $this->addContent($group); |
68 | 68 | } |
69 | 69 | return parent::compile($js, $view); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | private function getPrefix($element) { |
93 | 93 | $result="input_text"; |
94 | - foreach ( $this->formElementsPrefix as $k => $v ) { |
|
94 | + foreach ($this->formElementsPrefix as $k => $v) { |
|
95 | 95 | if (JString::startswith($element, $k)) { |
96 | 96 | $result=$v; |
97 | 97 | break; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | public function getElement($name) { |
123 | 123 | $element=null; |
124 | - foreach ( $this->formGroups as $group ) { |
|
124 | + foreach ($this->formGroups as $group) { |
|
125 | 125 | } |
126 | 126 | return $element; |
127 | 127 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @see \Ajax\bootstrap\html\base\HtmlSingleElement::fromArray() |
132 | 132 | */ |
133 | 133 | public function fromArray($array) { |
134 | - foreach ( $array as $value ) { |
|
134 | + foreach ($array as $value) { |
|
135 | 135 | if (is_string($value)) { |
136 | 136 | $this->futureElements []=$value; |
137 | 137 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | /** |
26 | 26 | * Define the html attribute for each element url in ajax |
27 | 27 | * @param string $attr html attribute |
28 | - * @return HtmlNavElement |
|
28 | + * @return NavElementTrait |
|
29 | 29 | */ |
30 | 30 | public function setAttr($attr) { |
31 | 31 | $this->attr = $attr; |
@@ -2,20 +2,20 @@ discard block |
||
2 | 2 | namespace Ajax\common\html\traits; |
3 | 3 | use Ajax\JsUtils; |
4 | 4 | |
5 | -trait NavElementTrait{ |
|
5 | +trait NavElementTrait { |
|
6 | 6 | /** |
7 | 7 | * Generate the jquery script to set the elements to the HtmlNavElement |
8 | 8 | * @param JsUtils $jsUtils |
9 | 9 | */ |
10 | - public function jsSetContent(JsUtils $jsUtils){ |
|
11 | - $jsUtils->html("#".$this->identifier,str_replace("\"","'", $this->contentAsString()),true); |
|
10 | + public function jsSetContent(JsUtils $jsUtils) { |
|
11 | + $jsUtils->html("#".$this->identifier, str_replace("\"", "'", $this->contentAsString()), true); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function getRoot() { |
15 | 15 | return $this->root; |
16 | 16 | } |
17 | 17 | public function setRoot($root) { |
18 | - $this->root = $root; |
|
18 | + $this->root=$root; |
|
19 | 19 | return $this; |
20 | 20 | } |
21 | 21 | public function getAttr() { |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | * @return HtmlNavElement |
29 | 29 | */ |
30 | 30 | public function setAttr($attr) { |
31 | - $this->attr = $attr; |
|
31 | + $this->attr=$attr; |
|
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 | |
35 | 35 | public function __call($method, $args) { |
36 | - if(isset($this->$method) && is_callable($this->$method)) { |
|
36 | + if (isset($this->$method) && is_callable($this->$method)) { |
|
37 | 37 | return call_user_func_array( |
38 | 38 | $this->$method, |
39 | 39 | $args |
@@ -41,5 +41,5 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - abstract public function fromDispatcher(JsUtils $js,$dispatcher,$startIndex=0); |
|
44 | + abstract public function fromDispatcher(JsUtils $js, $dispatcher, $startIndex=0); |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | protected $_contentSeparator=""; |
27 | 27 | |
28 | 28 | |
29 | - public function __construct($identifier,$tagName,$baseClass){ |
|
30 | - parent::__construct($identifier,$tagName,$baseClass); |
|
29 | + public function __construct($identifier, $tagName, $baseClass) { |
|
30 | + parent::__construct($identifier, $tagName, $baseClass); |
|
31 | 31 | $this->root=""; |
32 | 32 | $this->attr="data-ajax"; |
33 | 33 | } |
@@ -37,37 +37,37 @@ discard block |
||
37 | 37 | * @param string $targetSelector the target of the get |
38 | 38 | * @return HtmlNavElement |
39 | 39 | */ |
40 | - public function autoGetOnClick($targetSelector){ |
|
41 | - return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr)); |
|
40 | + public function autoGetOnClick($targetSelector) { |
|
41 | + return $this->getOnClick($this->root, $targetSelector, array("attr"=>$this->attr)); |
|
42 | 42 | } |
43 | 43 | |
44 | - public function contentAsString(){ |
|
44 | + public function contentAsString() { |
|
45 | 45 | return JArray::implode($this->_contentSeparator, $this->content); |
46 | 46 | } |
47 | 47 | |
48 | - public function setContentDivider($divider,$index=NULL) { |
|
48 | + public function setContentDivider($divider, $index=NULL) { |
|
49 | 49 | $divider="<div class='divider'> {$divider} </div>"; |
50 | 50 | return $this->setDivider($divider, $index); |
51 | 51 | } |
52 | 52 | |
53 | - public function setIconContentDivider($iconContentDivider,$index=NULL) { |
|
53 | + public function setIconContentDivider($iconContentDivider, $index=NULL) { |
|
54 | 54 | $contentDivider="<i class='".$iconContentDivider." icon divider'></i>"; |
55 | 55 | return $this->setDivider($contentDivider, $index); |
56 | 56 | } |
57 | 57 | |
58 | - protected function setDivider($divider,$index){ |
|
59 | - if(isset($index)){ |
|
60 | - if(!\is_array($this->_contentSeparator)) |
|
61 | - $this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator); |
|
58 | + protected function setDivider($divider, $index) { |
|
59 | + if (isset($index)) { |
|
60 | + if (!\is_array($this->_contentSeparator)) |
|
61 | + $this->_contentSeparator=array_fill(0, $this->count()-1, $this->_contentSeparator); |
|
62 | 62 | $this->_contentSeparator[$index]=$divider; |
63 | - }else{ |
|
63 | + } else { |
|
64 | 64 | $this->_contentSeparator=$divider; |
65 | 65 | } |
66 | 66 | return $this; |
67 | 67 | } |
68 | 68 | |
69 | - protected function getContentDivider($index){ |
|
70 | - if(\is_array($this->_contentSeparator)){ |
|
69 | + protected function getContentDivider($index) { |
|
70 | + if (\is_array($this->_contentSeparator)) { |
|
71 | 71 | return @$this->_contentSeparator[$index]; |
72 | 72 | } |
73 | 73 | return $this->_contentSeparator; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected $ajaxTransition; |
18 | 18 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
19 | 19 | |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | protected function addLoading(&$retour, $responseElement) { |
22 | 22 | $loading_notifier='<div class="ajax-loader">'; |
23 | 23 | if ($this->ajaxLoader=='') { |
@@ -30,66 +30,66 @@ discard block |
||
30 | 30 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
31 | 31 | } |
32 | 32 | |
33 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
34 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
33 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
34 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
35 | 35 | } |
36 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
37 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
36 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
37 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
38 | 38 | } |
39 | 39 | |
40 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
41 | - if(JString::isNull($params)){$params="{}";} |
|
40 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
41 | + if (JString::isNull($params)) {$params="{}"; } |
|
42 | 42 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
43 | 43 | $retour=$this->_getAjaxUrl($url, $attr); |
44 | 44 | $responseElement=$this->_getResponseElement($responseElement); |
45 | 45 | $retour.="var self=this;\n"; |
46 | - if($hasLoader===true){ |
|
46 | + if ($hasLoader===true) { |
|
47 | 47 | $this->addLoading($retour, $responseElement); |
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
51 | 51 | if ($immediatly) |
52 | 52 | $this->jquery_code_for_compile[]=$retour; |
53 | 53 | return $retour; |
54 | 54 | } |
55 | 55 | |
56 | - protected function setAjaxDataCall($params){ |
|
56 | + protected function setAjaxDataCall($params) { |
|
57 | 57 | $result=null; |
58 | - if(!\is_callable($params)){ |
|
59 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
60 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
58 | + if (!\is_callable($params)) { |
|
59 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
60 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
61 | 61 | }; |
62 | 62 | } |
63 | 63 | return $result; |
64 | 64 | } |
65 | 65 | |
66 | - protected function _getAjaxUrl($url,$attr){ |
|
66 | + protected function _getAjaxUrl($url, $attr) { |
|
67 | 67 | $url=$this->_correctAjaxUrl($url); |
68 | 68 | $retour="url='".$url."';"; |
69 | 69 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
70 | + if (JString::endswith($url, "/")===true) |
|
71 | 71 | $slash=""; |
72 | - if(JString::isNotNull($attr)){ |
|
72 | + if (JString::isNotNull($attr)) { |
|
73 | 73 | if ($attr==="value") |
74 | 74 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
75 | 75 | elseif ($attr==="html") |
76 | 76 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
77 | - elseif($attr!==null && $attr!=="") |
|
77 | + elseif ($attr!==null && $attr!=="") |
|
78 | 78 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
79 | 79 | } |
80 | 80 | return $retour; |
81 | 81 | } |
82 | 82 | |
83 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
84 | - $retour="";$call=null; |
|
83 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
84 | + $retour=""; $call=null; |
|
85 | 85 | if ($responseElement!=="") { |
86 | - if(isset($ajaxTransition)){ |
|
86 | + if (isset($ajaxTransition)) { |
|
87 | 87 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
88 | + }elseif (isset($this->ajaxTransition)) { |
|
89 | 89 | $call=$this->ajaxTransition; |
90 | 90 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
91 | + if (\is_callable($call)) |
|
92 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
93 | 93 | else |
94 | 94 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
95 | 95 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return $retour; |
98 | 98 | } |
99 | 99 | |
100 | - protected function _getResponseElement($responseElement){ |
|
100 | + protected function _getResponseElement($responseElement) { |
|
101 | 101 | if ($responseElement!=="") { |
102 | 102 | $responseElement=Javascript::prep_value($responseElement); |
103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | protected function _correctAjaxUrl($url) { |
108 | 108 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
109 | 109 | $url=substr($url, 0, strlen($url)-1); |
110 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
110 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
111 | 111 | $url=$this->jsUtils->getUrl($url); |
112 | 112 | } |
113 | 113 | return $url; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param string $jsCallback javascript code to execute after the request |
122 | 122 | * @param boolean $immediatly |
123 | 123 | */ |
124 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
124 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
125 | 125 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
126 | 126 | $retour=$this->_getAjaxUrl($url, $attr); |
127 | 127 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $url the request address |
143 | 143 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
144 | 144 | */ |
145 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
145 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
146 | 146 | $preventDefault=true; |
147 | 147 | $stopPropagation=true; |
148 | 148 | $jsCallback=null; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $params="{}"; |
153 | 153 | $immediatly=true; |
154 | 154 | extract($parameters); |
155 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
155 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -165,22 +165,22 @@ discard block |
||
165 | 165 | * @param string $rowClass the css class for the new element |
166 | 166 | * @param boolean $immediatly |
167 | 167 | */ |
168 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$rowClass="_json",$immediatly=false) { |
|
168 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $rowClass="_json", $immediatly=false) { |
|
169 | 169 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
170 | 170 | $retour=$this->_getAjaxUrl($url, $attr); |
171 | - if($context===null){ |
|
171 | + if ($context===null) { |
|
172 | 172 | $parent="$('".$maskSelector."').parent()"; |
173 | - $newElm = "$('#'+newId)"; |
|
174 | - }else{ |
|
173 | + $newElm="$('#'+newId)"; |
|
174 | + } else { |
|
175 | 175 | $parent=$context; |
176 | - $newElm = $context.".find('#'+newId)"; |
|
176 | + $newElm=$context.".find('#'+newId)"; |
|
177 | 177 | } |
178 | 178 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
179 | 179 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
180 | 180 | $retour.=$parent.".find('._json').remove();"; |
181 | 181 | $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(); |
182 | 182 | 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"; |
183 | - $retour.= $appendTo; |
|
183 | + $retour.=$appendTo; |
|
184 | 184 | $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"; |
185 | 185 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
186 | 186 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -195,30 +195,30 @@ discard block |
||
195 | 195 | * @param string $url the request address |
196 | 196 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
197 | 197 | */ |
198 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
198 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
199 | 199 | $preventDefault=true; |
200 | 200 | $stopPropagation=true; |
201 | 201 | $jsCallback=null; |
202 | 202 | $attr="id"; |
203 | 203 | $method="get"; |
204 | - $context = null; |
|
204 | + $context=null; |
|
205 | 205 | $params="{}"; |
206 | 206 | $immediatly=true; |
207 | 207 | extract($parameters); |
208 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
208 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
209 | 209 | } |
210 | 210 | |
211 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
211 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
212 | 212 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
213 | 213 | $retour=$this->_getAjaxUrl($url, $attr); |
214 | 214 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
215 | 215 | $responseElement=$this->_getResponseElement($responseElement); |
216 | 216 | $retour.="var self=this;\n"; |
217 | - if($hasLoader===true){ |
|
217 | + if ($hasLoader===true) { |
|
218 | 218 | $this->addLoading($retour, $responseElement); |
219 | 219 | } |
220 | 220 | $retour.="$.post(url,params).done(function( data ) {\n"; |
221 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
221 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
222 | 222 | |
223 | 223 | if ($validation) { |
224 | 224 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $responseElement |
242 | 242 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"jqueryDone"=>"html") |
243 | 243 | */ |
244 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
244 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
245 | 245 | $preventDefault=true; |
246 | 246 | $stopPropagation=true; |
247 | 247 | $jsCallback=null; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $jqueryDone="html"; |
252 | 252 | $ajaxTransition=null; |
253 | 253 | extract($parameters); |
254 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
254 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param string $responseElement |
265 | 265 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null) |
266 | 266 | */ |
267 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
267 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
268 | 268 | $preventDefault=true; |
269 | 269 | $stopPropagation=true; |
270 | 270 | $jsCallback=null; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $jqueryDone="html"; |
275 | 275 | $ajaxTransition=null; |
276 | 276 | extract($parameters); |
277 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
277 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @param string $responseElement |
288 | 288 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxTransition"=>null,"immediatly"=>true) |
289 | 289 | */ |
290 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
290 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
291 | 291 | $preventDefault=true; |
292 | 292 | $stopPropagation=true; |
293 | 293 | $validation=false; |
@@ -298,6 +298,6 @@ discard block |
||
298 | 298 | $jqueryDone="html"; |
299 | 299 | $ajaxTransition=null; |
300 | 300 | extract($parameters); |
301 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
301 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | \ No newline at end of file |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | } |
49 | 49 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
50 | 50 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
51 | - if ($immediatly) |
|
52 | - $this->jquery_code_for_compile[]=$retour; |
|
51 | + if ($immediatly) { |
|
52 | + $this->jquery_code_for_compile[]=$retour; |
|
53 | + } |
|
53 | 54 | return $retour; |
54 | 55 | } |
55 | 56 | |
@@ -67,15 +68,17 @@ discard block |
||
67 | 68 | $url=$this->_correctAjaxUrl($url); |
68 | 69 | $retour="url='".$url."';"; |
69 | 70 | $slash="/"; |
70 | - if(JString::endswith($url, "/")===true) |
|
71 | - $slash=""; |
|
71 | + if(JString::endswith($url, "/")===true) { |
|
72 | + $slash=""; |
|
73 | + } |
|
72 | 74 | if(JString::isNotNull($attr)){ |
73 | - if ($attr==="value") |
|
74 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
75 | - elseif ($attr==="html") |
|
76 | - $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
77 | - elseif($attr!==null && $attr!=="") |
|
78 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
75 | + if ($attr==="value") { |
|
76 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
77 | + } elseif ($attr==="html") { |
|
78 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
79 | + } elseif($attr!==null && $attr!=="") { |
|
80 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
81 | + } |
|
79 | 82 | } |
80 | 83 | return $retour; |
81 | 84 | } |
@@ -85,13 +88,14 @@ discard block |
||
85 | 88 | if ($responseElement!=="") { |
86 | 89 | if(isset($ajaxTransition)){ |
87 | 90 | $call=$this->setAjaxDataCall($ajaxTransition); |
88 | - }elseif(isset($this->ajaxTransition)){ |
|
91 | + } elseif(isset($this->ajaxTransition)){ |
|
89 | 92 | $call=$this->ajaxTransition; |
90 | 93 | } |
91 | - if(\is_callable($call)) |
|
92 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
93 | - else |
|
94 | - $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
94 | + if(\is_callable($call)) { |
|
95 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
96 | + } else { |
|
97 | + $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
|
98 | + } |
|
95 | 99 | } |
96 | 100 | $retour.="\t".$jsCallback."\n"; |
97 | 101 | return $retour; |
@@ -105,8 +109,9 @@ discard block |
||
105 | 109 | } |
106 | 110 | |
107 | 111 | protected function _correctAjaxUrl($url) { |
108 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
109 | - $url=substr($url, 0, strlen($url)-1); |
|
112 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
113 | + $url=substr($url, 0, strlen($url)-1); |
|
114 | + } |
|
110 | 115 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
111 | 116 | $url=$this->jsUtils->getUrl($url); |
112 | 117 | } |
@@ -130,8 +135,9 @@ discard block |
||
130 | 135 | $retour.="\t".$jsCallback."\n". |
131 | 136 | "\t$(document).trigger('jsonReady',[data]);\n". |
132 | 137 | "});\n"; |
133 | - if ($immediatly) |
|
134 | - $this->jquery_code_for_compile[]=$retour; |
|
138 | + if ($immediatly) { |
|
139 | + $this->jquery_code_for_compile[]=$retour; |
|
140 | + } |
|
135 | 141 | return $retour; |
136 | 142 | } |
137 | 143 | |
@@ -171,7 +177,7 @@ discard block |
||
171 | 177 | if($context===null){ |
172 | 178 | $parent="$('".$maskSelector."').parent()"; |
173 | 179 | $newElm = "$('#'+newId)"; |
174 | - }else{ |
|
180 | + } else{ |
|
175 | 181 | $parent=$context; |
176 | 182 | $newElm = $context.".find('#'+newId)"; |
177 | 183 | } |
@@ -184,8 +190,9 @@ discard block |
||
184 | 190 | $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"; |
185 | 191 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
186 | 192 | $retour.="\t".$jsCallback."\n"."});\n"; |
187 | - if ($immediatly) |
|
188 | - $this->jquery_code_for_compile[]=$retour; |
|
193 | + if ($immediatly) { |
|
194 | + $this->jquery_code_for_compile[]=$retour; |
|
195 | + } |
|
189 | 196 | return $retour; |
190 | 197 | } |
191 | 198 | /** |
@@ -226,8 +233,9 @@ discard block |
||
226 | 233 | }});\n"; |
227 | 234 | $retour.="$('#".$form."').submit();\n"; |
228 | 235 | } |
229 | - if ($immediatly) |
|
230 | - $this->jquery_code_for_compile[]=$retour; |
|
236 | + if ($immediatly) { |
|
237 | + $this->jquery_code_for_compile[]=$retour; |
|
238 | + } |
|
231 | 239 | return $retour; |
232 | 240 | } |
233 | 241 |
@@ -79,15 +79,15 @@ |
||
79 | 79 | $element=null; |
80 | 80 | $i=0; |
81 | 81 | if (is_int($index)) { |
82 | - $elements=array (); |
|
83 | - foreach ( $this->elements as $group ) { |
|
82 | + $elements=array(); |
|
83 | + foreach ($this->elements as $group) { |
|
84 | 84 | $elements=array_merge($elements, $group->getElements()); |
85 | 85 | } |
86 | 86 | if ($index<sizeof($elements)) { |
87 | 87 | $element=$elements [$index]; |
88 | 88 | } |
89 | 89 | } else { |
90 | - while ( $element===null && $i<sizeof($this->elements) ) { |
|
90 | + while ($element===null && $i<sizeof($this->elements)) { |
|
91 | 91 | $element=$this->elements [$i]->getElement($index); |
92 | 92 | $i++; |
93 | 93 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | protected $attr; |
22 | 22 | |
23 | 23 | |
24 | - public function __construct($identifier,$tagName){ |
|
25 | - parent::__construct($identifier,$tagName); |
|
24 | + public function __construct($identifier, $tagName) { |
|
25 | + parent::__construct($identifier, $tagName); |
|
26 | 26 | $this->root=""; |
27 | 27 | $this->attr="data-ajax"; |
28 | 28 | } |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * @param string $targetSelector the target of the get |
34 | 34 | * @return HtmlNavElement |
35 | 35 | */ |
36 | - public function autoGetOnClick($targetSelector){ |
|
37 | - return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr)); |
|
36 | + public function autoGetOnClick($targetSelector) { |
|
37 | + return $this->getOnClick($this->root, $targetSelector, array("attr"=>$this->attr)); |
|
38 | 38 | } |
39 | 39 | |
40 | - public function contentAsString(){ |
|
40 | + public function contentAsString() { |
|
41 | 41 | return implode("", $this->content); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -14,8 +14,9 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function compile(JsUtils $js=null) { |
17 | - if ($js===null) |
|
18 | - return; |
|
17 | + if ($js===null) { |
|
18 | + return; |
|
19 | + } |
|
19 | 20 | $params="{}"; |
20 | 21 | $jsCallback=NULL; |
21 | 22 | $attr="id"; |