@@ -59,8 +59,9 @@ discard block |
||
| 59 | 59 | $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
| 60 | 60 | $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
| 61 | 61 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 62 | - if ($immediatly) |
|
| 63 | - $this->jquery_code_for_compile[] = $retour; |
|
| 62 | + if ($immediatly) { |
|
| 63 | + $this->jquery_code_for_compile[] = $retour; |
|
| 64 | + } |
|
| 64 | 65 | return $retour; |
| 65 | 66 | } |
| 66 | 67 | |
@@ -114,8 +115,9 @@ discard block |
||
| 114 | 115 | $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
| 115 | 116 | } elseif (\substr($attr, 0, 3) === "js:") { |
| 116 | 117 | $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
| 117 | - } elseif ($attr !== null && $attr !== "") |
|
| 118 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 118 | + } elseif ($attr !== null && $attr !== "") { |
|
| 119 | + $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 120 | + } |
|
| 119 | 121 | } |
| 120 | 122 | return $retour; |
| 121 | 123 | } |
@@ -139,10 +141,11 @@ discard block |
||
| 139 | 141 | } elseif (isset($this->ajaxTransition)) { |
| 140 | 142 | $call = $this->ajaxTransition; |
| 141 | 143 | } |
| 142 | - if (\is_callable($call)) |
|
| 143 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 144 | - else |
|
| 145 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 144 | + if (\is_callable($call)) { |
|
| 145 | + $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 146 | + } else { |
|
| 147 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 148 | + } |
|
| 146 | 149 | } |
| 147 | 150 | if (isset($history)) { |
| 148 | 151 | if ($this->params["autoActiveLinks"]) { |
@@ -165,8 +168,9 @@ discard block |
||
| 165 | 168 | } |
| 166 | 169 | |
| 167 | 170 | protected function _correctAjaxUrl($url) { |
| 168 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 169 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 171 | + if ($url !== "/" && JString::endsWith($url, "/") === true) { |
|
| 172 | + $url = substr($url, 0, strlen($url) - 1); |
|
| 173 | + } |
|
| 170 | 174 | if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
| 171 | 175 | $url = $this->getUrl($url); |
| 172 | 176 | } |
@@ -190,8 +194,9 @@ discard block |
||
| 190 | 194 | public static function _implodeParams($parameters) { |
| 191 | 195 | $allParameters = []; |
| 192 | 196 | foreach ($parameters as $params) { |
| 193 | - if (isset($params)) |
|
| 194 | - $allParameters[] = self::_correctParams($params); |
|
| 197 | + if (isset($params)) { |
|
| 198 | + $allParameters[] = self::_correctParams($params); |
|
| 199 | + } |
|
| 195 | 200 | } |
| 196 | 201 | return \implode("+'&'+", $allParameters); |
| 197 | 202 | } |
@@ -217,8 +222,9 @@ discard block |
||
| 217 | 222 | |
| 218 | 223 | protected function setDefaultParameters(&$parameters, $default) { |
| 219 | 224 | foreach ($default as $k => $v) { |
| 220 | - if (! isset($parameters[$k])) |
|
| 221 | - $parameters[$k] = $v; |
|
| 225 | + if (! isset($parameters[$k])) { |
|
| 226 | + $parameters[$k] = $v; |
|
| 227 | + } |
|
| 222 | 228 | } |
| 223 | 229 | } |
| 224 | 230 | |
@@ -746,8 +752,9 @@ discard block |
||
| 746 | 752 | $retour .= "$('#" . $form . "').submit();\n"; |
| 747 | 753 | } |
| 748 | 754 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 749 | - if ($immediatly) |
|
| 750 | - $this->jquery_code_for_compile[] = $retour; |
|
| 755 | + if ($immediatly) { |
|
| 756 | + $this->jquery_code_for_compile[] = $retour; |
|
| 757 | + } |
|
| 751 | 758 | return $retour; |
| 752 | 759 | } |
| 753 | 760 | |
@@ -15,56 +15,56 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | protected $ajaxTransition; |
| 17 | 17 | |
| 18 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 18 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 19 | 19 | |
| 20 | 20 | abstract public function getUrl($url); |
| 21 | 21 | |
| 22 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 23 | 23 | |
| 24 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 24 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 25 | 25 | |
| 26 | - protected function _ajax($method, $url, $responseElement = "", $parameters = []) { |
|
| 26 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 27 | 27 | if (isset($this->params["ajax"])) { |
| 28 | 28 | extract($this->params["ajax"]); |
| 29 | 29 | } |
| 30 | 30 | extract($parameters); |
| 31 | 31 | |
| 32 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 33 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 34 | - $originalSelector = $responseElement; |
|
| 35 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 36 | - $retour .= "var self=this;\n"; |
|
| 37 | - $before = isset($before) ? $before : ""; |
|
| 38 | - $retour .= $before; |
|
| 39 | - if ($hasLoader === true && JString::isNotNull($responseElement)) { |
|
| 32 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 33 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 34 | + $originalSelector=$responseElement; |
|
| 35 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 36 | + $retour.="var self=this;\n"; |
|
| 37 | + $before=isset($before) ? $before : ""; |
|
| 38 | + $retour.=$before; |
|
| 39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 40 | 40 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 41 | - } elseif ($hasLoader === "internal") { |
|
| 42 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 41 | + } elseif ($hasLoader==="internal") { |
|
| 42 | + $retour.="\n$(this).addClass('loading');"; |
|
| 43 | 43 | } |
| 44 | - $ajaxParameters = [ |
|
| 44 | + $ajaxParameters=[ |
|
| 45 | 45 | "url" => "url", |
| 46 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 46 | + "method" => "'".\strtoupper($method)."'" |
|
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 49 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 50 | 50 | |
| 51 | 51 | if (isset($params)) { |
| 52 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 52 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 53 | 53 | } |
| 54 | 54 | if (isset($headers)) { |
| 55 | - $ajaxParameters["headers"] = $headers; |
|
| 55 | + $ajaxParameters["headers"]=$headers; |
|
| 56 | 56 | } |
| 57 | 57 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 58 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 59 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
| 60 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 58 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 59 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 60 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 61 | 61 | if ($immediatly) |
| 62 | - $this->jquery_code_for_compile[] = $retour; |
|
| 62 | + $this->jquery_code_for_compile[]=$retour; |
|
| 63 | 63 | return $retour; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | protected function createAjaxParameters(&$original, $parameters) { |
| 67 | - $validParameters = [ |
|
| 67 | + $validParameters=[ |
|
| 68 | 68 | "contentType" => "%value%", |
| 69 | 69 | "dataType" => "'%value%'", |
| 70 | 70 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -73,21 +73,21 @@ discard block |
||
| 73 | 73 | ]; |
| 74 | 74 | foreach ($validParameters as $param => $mask) { |
| 75 | 75 | if (isset($parameters[$param])) { |
| 76 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 76 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | protected function implodeAjaxParameters($ajaxParameters) { |
| 82 | - $s = ''; |
|
| 82 | + $s=''; |
|
| 83 | 83 | foreach ($ajaxParameters as $k => $v) { |
| 84 | - if ($s !== '') { |
|
| 85 | - $s .= ','; |
|
| 84 | + if ($s!=='') { |
|
| 85 | + $s.=','; |
|
| 86 | 86 | } |
| 87 | 87 | if (is_array($v)) { |
| 88 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 88 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 89 | 89 | } else { |
| 90 | - $s .= "'{$k}':{$v}"; |
|
| 90 | + $s.="'{$k}':{$v}"; |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | return $s; |
@@ -95,27 +95,27 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 97 | 97 | if (isset($jsCondition)) { |
| 98 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 98 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 99 | 99 | } |
| 100 | 100 | return $jsSource; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | protected function _getAjaxUrl($url, $attr) { |
| 104 | - $url = $this->_correctAjaxUrl($url); |
|
| 105 | - $retour = "url='" . $url . "';"; |
|
| 106 | - $slash = "/"; |
|
| 107 | - if (JString::endswith($url, "/") === true) { |
|
| 108 | - $slash = ""; |
|
| 104 | + $url=$this->_correctAjaxUrl($url); |
|
| 105 | + $retour="url='".$url."';"; |
|
| 106 | + $slash="/"; |
|
| 107 | + if (JString::endswith($url, "/")===true) { |
|
| 108 | + $slash=""; |
|
| 109 | 109 | } |
| 110 | 110 | if (JString::isNotNull($attr)) { |
| 111 | - if ($attr === "value") { |
|
| 112 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 113 | - } elseif ($attr === "html") { |
|
| 114 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 115 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 116 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 117 | - } elseif ($attr !== null && $attr !== "") |
|
| 118 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 111 | + if ($attr==="value") { |
|
| 112 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 113 | + } elseif ($attr==="html") { |
|
| 114 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 115 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 116 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 117 | + } elseif ($attr!==null && $attr!=="") |
|
| 118 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 119 | 119 | } |
| 120 | 120 | return $retour; |
| 121 | 121 | } |
@@ -124,91 +124,91 @@ discard block |
||
| 124 | 124 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 128 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 129 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 127 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 128 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 129 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 130 | 130 | return $result; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 134 | - $retour = ""; |
|
| 135 | - $call = null; |
|
| 133 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 134 | + $retour=""; |
|
| 135 | + $call=null; |
|
| 136 | 136 | if (JString::isNotNull($responseElement)) { |
| 137 | 137 | if (isset($ajaxTransition)) { |
| 138 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 138 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 139 | 139 | } elseif (isset($this->ajaxTransition)) { |
| 140 | - $call = $this->ajaxTransition; |
|
| 140 | + $call=$this->ajaxTransition; |
|
| 141 | 141 | } |
| 142 | 142 | if (\is_callable($call)) |
| 143 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 143 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 144 | 144 | else |
| 145 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 145 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 146 | 146 | } |
| 147 | 147 | if (isset($history)) { |
| 148 | 148 | if ($this->params["autoActiveLinks"]) { |
| 149 | - $retour .= $this->autoActiveLinks("url"); |
|
| 149 | + $retour.=$this->autoActiveLinks("url"); |
|
| 150 | 150 | } |
| 151 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 151 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 152 | 152 | } |
| 153 | - if ($hasLoader === "internal") { |
|
| 154 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 153 | + if ($hasLoader==="internal") { |
|
| 154 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 155 | 155 | } |
| 156 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 156 | + $retour.="\t".$jsCallback."\n"; |
|
| 157 | 157 | return $retour; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | protected function _getResponseElement($responseElement) { |
| 161 | 161 | if (JString::isNotNull($responseElement)) { |
| 162 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 162 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 163 | 163 | } |
| 164 | 164 | return $responseElement; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | protected function _correctAjaxUrl($url) { |
| 168 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 169 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 170 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 171 | - $url = $this->getUrl($url); |
|
| 168 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 169 | + $url=substr($url, 0, strlen($url)-1); |
|
| 170 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 171 | + $url=$this->getUrl($url); |
|
| 172 | 172 | } |
| 173 | 173 | return $url; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 176 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 177 | 177 | if (JString::isNull($params)) { |
| 178 | 178 | return ""; |
| 179 | 179 | } |
| 180 | 180 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 181 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 182 | - return '$.param(' . $params . ')'; |
|
| 181 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 182 | + return '$.param('.$params.')'; |
|
| 183 | 183 | } else { |
| 184 | - return 'JSON.stringify(' . $params . ')'; |
|
| 184 | + return 'JSON.stringify('.$params.')'; |
|
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | return $params; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | public static function _implodeParams($parameters) { |
| 191 | - $allParameters = []; |
|
| 191 | + $allParameters=[]; |
|
| 192 | 192 | foreach ($parameters as $params) { |
| 193 | 193 | if (isset($params)) |
| 194 | - $allParameters[] = self::_correctParams($params); |
|
| 194 | + $allParameters[]=self::_correctParams($params); |
|
| 195 | 195 | } |
| 196 | 196 | return \implode("+'&'+", $allParameters); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 200 | - if (! isset($ajaxLoader)) { |
|
| 201 | - $ajaxLoader = $this->ajaxLoader; |
|
| 199 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 200 | + if (!isset($ajaxLoader)) { |
|
| 201 | + $ajaxLoader=$this->ajaxLoader; |
|
| 202 | 202 | } |
| 203 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 204 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 205 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 203 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 204 | + $retour.="{$responseElement}.empty();\n"; |
|
| 205 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | protected function setAjaxDataCall($params) { |
| 209 | - $result = null; |
|
| 210 | - if (! \is_callable($params)) { |
|
| 211 | - $result = function ($responseElement, $jqueryDone = "html") use ($params) { |
|
| 209 | + $result=null; |
|
| 210 | + if (!\is_callable($params)) { |
|
| 211 | + $result=function($responseElement, $jqueryDone="html") use ($params) { |
|
| 212 | 212 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 213 | 213 | }; |
| 214 | 214 | } |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | protected function setDefaultParameters(&$parameters, $default) { |
| 219 | 219 | foreach ($default as $k => $v) { |
| 220 | - if (! isset($parameters[$k])) |
|
| 221 | - $parameters[$k] = $v; |
|
| 220 | + if (!isset($parameters[$k])) |
|
| 221 | + $parameters[$k]=$v; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | public function setAjaxLoader($loader) { |
| 226 | - $this->ajaxLoader = $loader; |
|
| 226 | + $this->ajaxLoader=$loader; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @param string $responseElement |
| 235 | 235 | * selector of the HTML element displaying the answer |
| 236 | 236 | */ |
| 237 | - private function _get($url, $responseElement = "", $parameters = []) { |
|
| 237 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 238 | 238 | return $this->_ajax("get", $url, $responseElement, $parameters); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | * @param array $parameters |
| 249 | 249 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 250 | 250 | */ |
| 251 | - public function get($url, $responseElement = "", $parameters = []) { |
|
| 252 | - $parameters["immediatly"] = true; |
|
| 251 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 252 | + $parameters["immediatly"]=true; |
|
| 253 | 253 | return $this->_get($url, $responseElement, $parameters); |
| 254 | 254 | } |
| 255 | 255 | |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | * @param array $parameters |
| 266 | 266 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 267 | 267 | */ |
| 268 | - public function ajax($method, $url, $responseElement = "", $parameters = []) { |
|
| 269 | - $parameters["immediatly"] = true; |
|
| 268 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 269 | + $parameters["immediatly"]=true; |
|
| 270 | 270 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * $immediatly |
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [], $immediatly = true) { |
|
| 291 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) { |
|
| 292 | 292 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 293 | 293 | } |
| 294 | 294 | |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | * @param array $parameters |
| 305 | 305 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 306 | 306 | */ |
| 307 | - public function ajaxDeferred($method, $url, $responseElement = "", $parameters = []) { |
|
| 308 | - $parameters["immediatly"] = false; |
|
| 307 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 308 | + $parameters["immediatly"]=false; |
|
| 309 | 309 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 310 | 310 | } |
| 311 | 311 | |
@@ -319,15 +319,15 @@ discard block |
||
| 319 | 319 | * @param array $parameters |
| 320 | 320 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 321 | 321 | */ |
| 322 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 323 | - $parameters = \array_merge($parameters, [ |
|
| 322 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 323 | + $parameters=\array_merge($parameters, [ |
|
| 324 | 324 | "hasLoader" => false |
| 325 | 325 | ]); |
| 326 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 327 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 328 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
| 329 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 330 | - $parameters["jsCallback"] = $retour; |
|
| 326 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 327 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 328 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
| 329 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 330 | + $parameters["jsCallback"]=$retour; |
|
| 331 | 331 | return $this->_ajax($method, $url, null, $parameters); |
| 332 | 332 | } |
| 333 | 333 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @param array $parameters |
| 342 | 342 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 343 | 343 | */ |
| 344 | - public function json($url, $method = "get", $parameters = []) { |
|
| 344 | + public function json($url, $method="get", $parameters=[]) { |
|
| 345 | 345 | return $this->_json($url, $method, $parameters); |
| 346 | 346 | } |
| 347 | 347 | |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | * @param array $parameters |
| 358 | 358 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null) |
| 359 | 359 | */ |
| 360 | - public function jsonOn($event, $element, $url, $method = "get", $parameters = array()) { |
|
| 360 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
| 361 | 361 | $this->setDefaultParameters($parameters, [ |
| 362 | 362 | "preventDefault" => true, |
| 363 | 363 | "stopPropagation" => true, |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param array $parameters |
| 377 | 377 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 378 | 378 | */ |
| 379 | - public function jsonDeferred($url, $method = "get", $parameters = []) { |
|
| 380 | - $parameters["immediatly"] = false; |
|
| 379 | + public function jsonDeferred($url, $method="get", $parameters=[]) { |
|
| 380 | + $parameters["immediatly"]=false; |
|
| 381 | 381 | return $this->_json($url, $method, $parameters); |
| 382 | 382 | } |
| 383 | 383 | |
@@ -392,29 +392,29 @@ discard block |
||
| 392 | 392 | * @param array $parameters |
| 393 | 393 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 394 | 394 | */ |
| 395 | - private function _jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
| 396 | - $parameters = \array_merge($parameters, [ |
|
| 395 | + private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 396 | + $parameters=\array_merge($parameters, [ |
|
| 397 | 397 | "hasLoader" => false |
| 398 | 398 | ]); |
| 399 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 400 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 401 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 402 | - if ($context === null) { |
|
| 403 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 404 | - $newElm = "$('#'+newId)"; |
|
| 399 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 400 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 401 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 402 | + if ($context===null) { |
|
| 403 | + $parent="$('".$maskSelector."').parent()"; |
|
| 404 | + $newElm="$('#'+newId)"; |
|
| 405 | 405 | } else { |
| 406 | - $parent = $context; |
|
| 407 | - $newElm = $context . ".find('#'+newId)"; |
|
| 406 | + $parent=$context; |
|
| 407 | + $newElm=$context.".find('#'+newId)"; |
|
| 408 | 408 | } |
| 409 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 410 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 411 | - $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\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(); |
|
| 409 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 410 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 411 | + $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\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(); |
|
| 412 | 412 | 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"; |
| 413 | - $retour .= $appendTo; |
|
| 414 | - $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"; |
|
| 415 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 416 | - $retour .= "\t" . $jsCallback; |
|
| 417 | - $parameters["jsCallback"] = $retour; |
|
| 413 | + $retour.=$appendTo; |
|
| 414 | + $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"; |
|
| 415 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 416 | + $retour.="\t".$jsCallback; |
|
| 417 | + $parameters["jsCallback"]=$retour; |
|
| 418 | 418 | return $this->_ajax($method, $url, null, $parameters); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @param array $parameters |
| 430 | 430 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 431 | 431 | */ |
| 432 | - public function jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
| 432 | + public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 433 | 433 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 434 | 434 | } |
| 435 | 435 | |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | * @param array $parameters |
| 445 | 445 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 446 | 446 | */ |
| 447 | - public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters) { |
|
| 448 | - $parameters["immediatly"] = false; |
|
| 447 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters) { |
|
| 448 | + $parameters["immediatly"]=false; |
|
| 449 | 449 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 450 | 450 | } |
| 451 | 451 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @param array $parameters |
| 462 | 462 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null) |
| 463 | 463 | */ |
| 464 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array()) { |
|
| 464 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
| 465 | 465 | $this->setDefaultParameters($parameters, [ |
| 466 | 466 | "preventDefault" => true, |
| 467 | 467 | "stopPropagation" => true, |
@@ -481,8 +481,8 @@ discard block |
||
| 481 | 481 | * @param array $parameters |
| 482 | 482 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 483 | 483 | */ |
| 484 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 485 | - $parameters["immediatly"] = false; |
|
| 484 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 485 | + $parameters["immediatly"]=false; |
|
| 486 | 486 | return $this->_get($url, $responseElement, $parameters); |
| 487 | 487 | } |
| 488 | 488 | |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * @param array $parameters |
| 502 | 502 | * 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,"historize"=>false,"before"=>null) |
| 503 | 503 | */ |
| 504 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 504 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 505 | 505 | $this->setDefaultParameters($parameters, [ |
| 506 | 506 | "preventDefault" => true, |
| 507 | 507 | "stopPropagation" => true, |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @param array $parameters |
| 526 | 526 | * 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,"historize"=>false,"before"=>null) |
| 527 | 527 | */ |
| 528 | - public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 528 | + public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 529 | 529 | $this->setDefaultParameters($parameters, [ |
| 530 | 530 | "preventDefault" => true, |
| 531 | 531 | "stopPropagation" => true, |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | * @param array $parameters |
| 549 | 549 | * 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,"historize"=>false,"before"=>null) |
| 550 | 550 | */ |
| 551 | - public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
| 551 | + public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 552 | 552 | return $this->ajaxOn("click", $element, $url, $responseElement, $parameters); |
| 553 | 553 | } |
| 554 | 554 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * @param array $parameters |
| 566 | 566 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 567 | 567 | */ |
| 568 | - public function getOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
| 568 | + public function getOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 569 | 569 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
| 570 | 570 | } |
| 571 | 571 | |
@@ -580,15 +580,15 @@ discard block |
||
| 580 | 580 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null) |
| 581 | 581 | * @return $this |
| 582 | 582 | */ |
| 583 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 584 | - $parameters["attr"] = "href"; |
|
| 583 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 584 | + $parameters["attr"]="href"; |
|
| 585 | 585 | if (JString::isNull($responseElement)) { |
| 586 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 586 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 587 | 587 | } else { |
| 588 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 588 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 589 | 589 | } |
| 590 | - if (! isset($parameters["historize"])) { |
|
| 591 | - $parameters["historize"] = true; |
|
| 590 | + if (!isset($parameters["historize"])) { |
|
| 591 | + $parameters["historize"]=true; |
|
| 592 | 592 | } |
| 593 | 593 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 594 | 594 | } |
@@ -604,21 +604,21 @@ discard block |
||
| 604 | 604 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true,"before"=>null) |
| 605 | 605 | * @return $this |
| 606 | 606 | */ |
| 607 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 608 | - $parameters["attr"] = "href"; |
|
| 607 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 608 | + $parameters["attr"]="href"; |
|
| 609 | 609 | if (JString::isNull($responseElement)) { |
| 610 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 610 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 611 | 611 | } else { |
| 612 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 612 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 613 | 613 | } |
| 614 | - if (! isset($parameters["historize"])) { |
|
| 615 | - $parameters["historize"] = true; |
|
| 614 | + if (!isset($parameters["historize"])) { |
|
| 615 | + $parameters["historize"]=true; |
|
| 616 | 616 | } |
| 617 | 617 | return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - private function _post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 621 | - $parameters["params"] = $params; |
|
| 620 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 621 | + $parameters["params"]=$params; |
|
| 622 | 622 | return $this->_ajax("POST", $url, $responseElement, $parameters); |
| 623 | 623 | } |
| 624 | 624 | |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | * @param array $parameters |
| 635 | 635 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 636 | 636 | */ |
| 637 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 637 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 638 | 638 | return $this->_post($url, $params, $responseElement, $parameters); |
| 639 | 639 | } |
| 640 | 640 | |
@@ -651,8 +651,8 @@ discard block |
||
| 651 | 651 | * @param array $parameters |
| 652 | 652 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 653 | 653 | */ |
| 654 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 655 | - $parameters["immediatly"] = false; |
|
| 654 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 655 | + $parameters["immediatly"]=false; |
|
| 656 | 656 | return $this->_post($url, $params, $responseElement, $parameters); |
| 657 | 657 | } |
| 658 | 658 | |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | * @param array $parameters |
| 672 | 672 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 673 | 673 | */ |
| 674 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 674 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 675 | 675 | $this->setDefaultParameters($parameters, [ |
| 676 | 676 | "preventDefault" => true, |
| 677 | 677 | "stopPropagation" => true, |
@@ -694,60 +694,60 @@ discard block |
||
| 694 | 694 | * @param array $parameters |
| 695 | 695 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null,"before"=>null) |
| 696 | 696 | */ |
| 697 | - public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 697 | + public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 698 | 698 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 701 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 702 | 702 | if (isset($this->params["ajax"])) { |
| 703 | 703 | extract($this->params["ajax"]); |
| 704 | 704 | } |
| 705 | - $params = "{}"; |
|
| 706 | - $validation = false; |
|
| 705 | + $params="{}"; |
|
| 706 | + $validation=false; |
|
| 707 | 707 | \extract($parameters); |
| 708 | - $async = ($async) ? "true" : "false"; |
|
| 709 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 710 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 711 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
| 712 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 713 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
| 708 | + $async=($async) ? "true" : "false"; |
|
| 709 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 710 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 711 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
| 712 | + if (!isset($contentType) || $contentType!='false') { |
|
| 713 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
| 714 | 714 | if (isset($params)) { |
| 715 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 715 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 716 | 716 | } |
| 717 | 717 | } else { |
| 718 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
| 718 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
| 719 | 719 | } |
| 720 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 721 | - $retour .= "var self=this;\n"; |
|
| 722 | - $before = isset($before) ? $before : ""; |
|
| 723 | - $retour .= $before; |
|
| 724 | - if ($hasLoader === true) { |
|
| 720 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 721 | + $retour.="var self=this;\n"; |
|
| 722 | + $before=isset($before) ? $before : ""; |
|
| 723 | + $retour.=$before; |
|
| 724 | + if ($hasLoader===true) { |
|
| 725 | 725 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 726 | - } elseif ($hasLoader === "internal") { |
|
| 727 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 726 | + } elseif ($hasLoader==="internal") { |
|
| 727 | + $retour.="\n$(this).addClass('loading');"; |
|
| 728 | 728 | } |
| 729 | - $ajaxParameters = [ |
|
| 729 | + $ajaxParameters=[ |
|
| 730 | 730 | "url" => "url", |
| 731 | 731 | "method" => "'POST'", |
| 732 | 732 | "data" => "params", |
| 733 | 733 | "async" => $async |
| 734 | 734 | ]; |
| 735 | 735 | if (isset($headers)) { |
| 736 | - $ajaxParameters["headers"] = $headers; |
|
| 736 | + $ajaxParameters["headers"]=$headers; |
|
| 737 | 737 | } |
| 738 | 738 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 739 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 740 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
| 739 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 740 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 741 | 741 | |
| 742 | 742 | if ($validation) { |
| 743 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
| 744 | - " . $retour . " |
|
| 743 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
| 744 | + " . $retour." |
|
| 745 | 745 | }});\n"; |
| 746 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
| 746 | + $retour.="$('#".$form."').submit();\n"; |
|
| 747 | 747 | } |
| 748 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 748 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 749 | 749 | if ($immediatly) |
| 750 | - $this->jquery_code_for_compile[] = $retour; |
|
| 750 | + $this->jquery_code_for_compile[]=$retour; |
|
| 751 | 751 | return $retour; |
| 752 | 752 | } |
| 753 | 753 | |
@@ -763,8 +763,8 @@ discard block |
||
| 763 | 763 | * @param array $parameters |
| 764 | 764 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 765 | 765 | */ |
| 766 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 767 | - $parameters["immediatly"] = true; |
|
| 766 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 767 | + $parameters["immediatly"]=true; |
|
| 768 | 768 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 769 | 769 | } |
| 770 | 770 | |
@@ -781,8 +781,8 @@ discard block |
||
| 781 | 781 | * @param array $parameters |
| 782 | 782 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 783 | 783 | */ |
| 784 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 785 | - $parameters["immediatly"] = false; |
|
| 784 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 785 | + $parameters["immediatly"]=false; |
|
| 786 | 786 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 787 | 787 | } |
| 788 | 788 | |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | * @param array $parameters |
| 800 | 800 | * 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,"historize"=>false,"before"=>null) |
| 801 | 801 | */ |
| 802 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 802 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 803 | 803 | $this->setDefaultParameters($parameters, [ |
| 804 | 804 | "preventDefault" => true, |
| 805 | 805 | "stopPropagation" => true, |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | * @param array $parameters |
| 821 | 821 | * 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,"historize"=>false,"before"=>null) |
| 822 | 822 | */ |
| 823 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 823 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 824 | 824 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 825 | 825 | } |
| 826 | 826 | } |