@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @author jc |
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | -trait FormTrait{ |
|
| 18 | +trait FormTrait { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @return HtmlForm |
@@ -23,23 +23,23 @@ discard block |
||
| 23 | 23 | abstract protected function getForm(); |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - protected function addCompoValidation(Form $compo,HtmlFormField $field){ |
|
| 26 | + protected function addCompoValidation(Form $compo, HtmlFormField $field) { |
|
| 27 | 27 | $validation=$field->getValidation(); |
| 28 | - if(isset($validation)){ |
|
| 28 | + if (isset($validation)) { |
|
| 29 | 29 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
| 30 | 30 | $compo->addFieldValidation($validation); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - protected function addExtraCompoValidation(Form $compo,FieldValidation $validation){ |
|
| 34 | + protected function addExtraCompoValidation(Form $compo, FieldValidation $validation) { |
|
| 35 | 35 | $compo->addFieldValidation($validation); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){ |
|
| 38 | + protected function _runValidationParams(Form &$compo, JsUtils $js=NULL) { |
|
| 39 | 39 | $form=$this->getForm(); |
| 40 | 40 | $params=$form->getValidationParams(); |
| 41 | - if(isset($params["_ajaxSubmit"])){ |
|
| 42 | - $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"],$js); |
|
| 41 | + if (isset($params["_ajaxSubmit"])) { |
|
| 42 | + $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"], $js); |
|
| 43 | 43 | $this->onSuccess($compilation); |
| 44 | 44 | $form->removeValidationParam("_ajaxSubmit"); |
| 45 | 45 | } |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | $form->addEventsOnRun($js); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){ |
|
| 51 | + protected function _compileAjaxSubmit($ajaxSubmit, JsUtils $js=null) { |
|
| 52 | 52 | $compilation=""; |
| 53 | - if(\is_array($ajaxSubmit)){ |
|
| 54 | - foreach ($ajaxSubmit as $ajaxSubmitItem){ |
|
| 53 | + if (\is_array($ajaxSubmit)) { |
|
| 54 | + foreach ($ajaxSubmit as $ajaxSubmitItem) { |
|
| 55 | 55 | $compilation.=$ajaxSubmitItem->compile($js); |
| 56 | 56 | } |
| 57 | - }elseif($ajaxSubmit instanceof AjaxCall){ |
|
| 57 | + }elseif ($ajaxSubmit instanceof AjaxCall) { |
|
| 58 | 58 | $compilation=$ajaxSubmit->compile($js); |
| 59 | 59 | } |
| 60 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
| 60 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
| 61 | 61 | return $compilation; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | return $this; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function setAttached($value=true){ |
|
| 73 | + public function setAttached($value=true) { |
|
| 74 | 74 | $form=$this->getForm(); |
| 75 | - if($value) |
|
| 76 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 75 | + if ($value) |
|
| 76 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
| 77 | 77 | return $form; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function addErrorMessage(){ |
|
| 80 | + public function addErrorMessage() { |
|
| 81 | 81 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -93,48 +93,48 @@ discard block |
||
| 93 | 93 | * @param array $parameters |
| 94 | 94 | * @return HtmlForm |
| 95 | 95 | */ |
| 96 | - public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){ |
|
| 96 | + public function submitOn($event, $identifierOrElement, $url, $responseElement, $parameters=NULL) { |
|
| 97 | 97 | $form=$this->getForm(); |
| 98 | - if($identifierOrElement instanceof BaseHtml) |
|
| 98 | + if ($identifierOrElement instanceof BaseHtml) |
|
| 99 | 99 | $elem=$identifierOrElement; |
| 100 | 100 | else |
| 101 | 101 | $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
| 102 | - if(isset($elem)){ |
|
| 103 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters); |
|
| 102 | + if (isset($elem)) { |
|
| 103 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement, $parameters); |
|
| 104 | 104 | } |
| 105 | 105 | return $form; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){ |
|
| 109 | - return $this->submitOn("click", $identifier, $url, $responseElement,$parameters); |
|
| 108 | + public function submitOnClick($identifier, $url, $responseElement, $parameters=NULL) { |
|
| 109 | + return $this->submitOn("click", $identifier, $url, $responseElement, $parameters); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
| 113 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 114 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters); |
|
| 112 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 113 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 114 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement, $parameters); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
| 117 | + protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
| 118 | 118 | $form=$this->getForm(); |
| 119 | - if(isset($url) && isset($responseElement)){ |
|
| 120 | - $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
|
| 121 | - $this->setSubmitParams($url,$responseElement,$parameters); |
|
| 119 | + if (isset($url) && isset($responseElement)) { |
|
| 120 | + $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true); |
|
| 121 | + $this->setSubmitParams($url, $responseElement, $parameters); |
|
| 122 | 122 | } |
| 123 | 123 | return $button; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){ |
|
| 126 | + public function setSubmitParams($url, $responseElement=NULL, $parameters=NULL) { |
|
| 127 | 127 | $form=$this->getForm(); |
| 128 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
| 129 | - if(\is_array($parameters)){ |
|
| 130 | - $params=\array_merge($params,$parameters); |
|
| 128 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
| 129 | + if (\is_array($parameters)) { |
|
| 130 | + $params=\array_merge($params, $parameters); |
|
| 131 | 131 | } |
| 132 | 132 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
| 133 | 133 | return $this; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
| 137 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 136 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
| 137 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 138 | 138 | $bt->setProperty("type", "reset"); |
| 139 | 139 | return $bt; |
| 140 | 140 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $jsCode |
| 145 | 145 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 146 | 146 | */ |
| 147 | - public function onValid($jsCode){ |
|
| 147 | + public function onValid($jsCode) { |
|
| 148 | 148 | $form=$this->getForm(); |
| 149 | 149 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
| 150 | 150 | return $form; |
@@ -155,35 +155,35 @@ discard block |
||
| 155 | 155 | * @param string $jsCode can use event and fields parameters |
| 156 | 156 | * @return HtmlForm |
| 157 | 157 | */ |
| 158 | - public function onSuccess($jsCode){ |
|
| 158 | + public function onSuccess($jsCode) { |
|
| 159 | 159 | $form=$this->getForm(); |
| 160 | - $form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%"); |
|
| 160 | + $form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%"); |
|
| 161 | 161 | return $form; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - public function addExtraFieldRules($fieldname,$rules){ |
|
| 164 | + public function addExtraFieldRules($fieldname, $rules) { |
|
| 165 | 165 | $form=$this->getForm(); |
| 166 | 166 | $fv=$form->getExtraFieldValidation($fieldname); |
| 167 | - foreach ($rules as $rule){ |
|
| 167 | + foreach ($rules as $rule) { |
|
| 168 | 168 | $fv->addRule($rule); |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function addExtraFieldRule($fieldname,$type,$prompt=NULL,$value=NULL){ |
|
| 172 | + public function addExtraFieldRule($fieldname, $type, $prompt=NULL, $value=NULL) { |
|
| 173 | 173 | $form=$this->getForm(); |
| 174 | 174 | $fv=$form->getExtraFieldValidation($fieldname); |
| 175 | - $fv->addRule($type,$prompt,$value); |
|
| 175 | + $fv->addRule($type, $prompt, $value); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function setOptional($fieldname,$optional=true){ |
|
| 178 | + public function setOptional($fieldname, $optional=true) { |
|
| 179 | 179 | $form=$this->getForm(); |
| 180 | 180 | $fv=$form->getExtraFieldValidation($fieldname); |
| 181 | 181 | $fv->setOptional($optional); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function setActionTarget(string $action, string $target){ |
|
| 184 | + public function setActionTarget(string $action, string $target) { |
|
| 185 | 185 | $form=$this->getForm(); |
| 186 | - $form->setProperty('data-target',$target); |
|
| 187 | - $form->setProperty('action',$action); |
|
| 186 | + $form->setProperty('data-target', $target); |
|
| 187 | + $form->setProperty('action', $action); |
|
| 188 | 188 | } |
| 189 | 189 | } |
@@ -15,71 +15,71 @@ 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, $listenerOn = false); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 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 === 'response') { |
|
| 41 | + } elseif ($hasLoader==='response') { |
|
| 42 | 42 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 43 | - } elseif ($hasLoader === 'internal-x') { |
|
| 43 | + } elseif ($hasLoader==='internal-x') { |
|
| 44 | 44 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 45 | - } elseif ($hasLoader === 'internal') { |
|
| 46 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 45 | + } elseif ($hasLoader==='internal') { |
|
| 46 | + $retour.="\n$(this).addClass('loading');"; |
|
| 47 | 47 | } elseif (\is_string($hasLoader)) { |
| 48 | 48 | $this->addLoading($retour, $hasLoader, $ajaxLoader); |
| 49 | 49 | } |
| 50 | - $ajaxParameters = [ |
|
| 50 | + $ajaxParameters=[ |
|
| 51 | 51 | "url" => "url", |
| 52 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 52 | + "method" => "'".\strtoupper($method)."'" |
|
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 55 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 56 | 56 | |
| 57 | 57 | if (isset($params)) { |
| 58 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 58 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 59 | 59 | } |
| 60 | 60 | if (isset($headers)) { |
| 61 | - $ajaxParameters["headers"] = $headers; |
|
| 61 | + $ajaxParameters["headers"]=$headers; |
|
| 62 | 62 | } |
| 63 | 63 | if ($csrf) { |
| 64 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 64 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 66 | 66 | } |
| 67 | 67 | if (isset($partial)) { |
| 68 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 69 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 68 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 69 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 70 | 70 | } |
| 71 | 71 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 72 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
| 72 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 74 | 74 | |
| 75 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 75 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 76 | 76 | if ($immediatly) |
| 77 | - $this->jquery_code_for_compile[] = $retour; |
|
| 77 | + $this->jquery_code_for_compile[]=$retour; |
|
| 78 | 78 | return $retour; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | protected function createAjaxParameters(&$original, $parameters) { |
| 82 | - $validParameters = [ |
|
| 82 | + $validParameters=[ |
|
| 83 | 83 | "contentType" => "%value%", |
| 84 | 84 | "dataType" => "'%value%'", |
| 85 | 85 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -88,21 +88,21 @@ discard block |
||
| 88 | 88 | ]; |
| 89 | 89 | foreach ($validParameters as $param => $mask) { |
| 90 | 90 | if (isset($parameters[$param])) { |
| 91 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 91 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function implodeAjaxParameters($ajaxParameters) { |
| 97 | - $s = ''; |
|
| 97 | + $s=''; |
|
| 98 | 98 | foreach ($ajaxParameters as $k => $v) { |
| 99 | - if ($s !== '') { |
|
| 100 | - $s .= ','; |
|
| 99 | + if ($s!=='') { |
|
| 100 | + $s.=','; |
|
| 101 | 101 | } |
| 102 | 102 | if (is_array($v)) { |
| 103 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 103 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 104 | 104 | } else { |
| 105 | - $s .= "'{$k}':{$v}"; |
|
| 105 | + $s.="'{$k}':{$v}"; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | return $s; |
@@ -110,29 +110,29 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 112 | 112 | if (isset($jsCondition)) { |
| 113 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 113 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 114 | 114 | } |
| 115 | 115 | return $jsSource; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | protected function _getAjaxUrl($url, $attr) { |
| 119 | - $url = $this->_correctAjaxUrl($url); |
|
| 120 | - $retour = "url='" . $url . "';"; |
|
| 121 | - $slash = "/"; |
|
| 122 | - if (JString::endswith($url, "/") === true) { |
|
| 123 | - $slash = ""; |
|
| 119 | + $url=$this->_correctAjaxUrl($url); |
|
| 120 | + $retour="url='".$url."';"; |
|
| 121 | + $slash="/"; |
|
| 122 | + if (JString::endswith($url, "/")===true) { |
|
| 123 | + $slash=""; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if (JString::isNotNull($attr)) { |
| 127 | - if ($attr === "value") { |
|
| 128 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 129 | - } elseif ($attr === "html") { |
|
| 130 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 131 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 132 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 133 | - } elseif ($attr !== null && $attr !== "") { |
|
| 134 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
| 135 | - $retour .= "url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
| 127 | + if ($attr==="value") { |
|
| 128 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 129 | + } elseif ($attr==="html") { |
|
| 130 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 131 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 132 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 133 | + } elseif ($attr!==null && $attr!=="") { |
|
| 134 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
| 135 | + $retour.="url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | return $retour; |
@@ -142,110 +142,110 @@ discard block |
||
| 142 | 142 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 146 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 147 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 145 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 146 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 147 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 148 | 148 | return $result; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 152 | - $retour = ""; |
|
| 153 | - $call = null; |
|
| 151 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 152 | + $retour=""; |
|
| 153 | + $call=null; |
|
| 154 | 154 | if (JString::isNotNull($responseElement)) { |
| 155 | 155 | if (isset($ajaxTransition)) { |
| 156 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 156 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 157 | 157 | } elseif (isset($this->ajaxTransition)) { |
| 158 | - $call = $this->ajaxTransition; |
|
| 158 | + $call=$this->ajaxTransition; |
|
| 159 | 159 | } |
| 160 | 160 | if (\is_callable($call)) |
| 161 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 161 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 162 | 162 | else |
| 163 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 163 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 164 | 164 | } |
| 165 | 165 | if (isset($history)) { |
| 166 | 166 | if ($this->params["autoActiveLinks"]) { |
| 167 | - $retour .= $this->autoActiveLinks("url"); |
|
| 167 | + $retour.=$this->autoActiveLinks("url"); |
|
| 168 | 168 | } |
| 169 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 169 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 170 | 170 | } |
| 171 | - if ($hasLoader === 'internal') { |
|
| 172 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 173 | - } elseif ($hasLoader === 'internal-x') { |
|
| 174 | - $retour .= "\n$(self).children('.ajax-loader').remove();"; |
|
| 171 | + if ($hasLoader==='internal') { |
|
| 172 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 173 | + } elseif ($hasLoader==='internal-x') { |
|
| 174 | + $retour.="\n$(self).children('.ajax-loader').remove();"; |
|
| 175 | 175 | } else { |
| 176 | - $retour .= "\n$(self).find('.loading').removeClass('loading');"; |
|
| 176 | + $retour.="\n$(self).find('.loading').removeClass('loading');"; |
|
| 177 | 177 | } |
| 178 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 178 | + $retour.="\t".$jsCallback."\n"; |
|
| 179 | 179 | return $retour; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | protected function _getResponseElement($responseElement) { |
| 183 | 183 | if (JString::isNotNull($responseElement)) { |
| 184 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 184 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 185 | 185 | } |
| 186 | 186 | return $responseElement; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | protected function _getFormElement($formElement) { |
| 190 | 190 | if (JString::isNotNull($formElement)) { |
| 191 | - $formElement = Javascript::prep_value($formElement); |
|
| 191 | + $formElement=Javascript::prep_value($formElement); |
|
| 192 | 192 | } |
| 193 | 193 | return $formElement; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | protected function _correctAjaxUrl($url) { |
| 197 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 198 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 199 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 200 | - $url = $this->getUrl($url); |
|
| 197 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 198 | + $url=substr($url, 0, strlen($url)-1); |
|
| 199 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 200 | + $url=$this->getUrl($url); |
|
| 201 | 201 | } |
| 202 | 202 | return $url; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 205 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 206 | 206 | if (JString::isNull($params)) { |
| 207 | 207 | return ""; |
| 208 | 208 | } |
| 209 | 209 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 210 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 211 | - return '$.param(' . $params . ')'; |
|
| 210 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 211 | + return '$.param('.$params.')'; |
|
| 212 | 212 | } else { |
| 213 | - return 'JSON.stringify(' . $params . ')'; |
|
| 213 | + return 'JSON.stringify('.$params.')'; |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | return $params; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public static function _implodeParams($parameters) { |
| 220 | - $allParameters = []; |
|
| 220 | + $allParameters=[]; |
|
| 221 | 221 | foreach ($parameters as $params) { |
| 222 | 222 | if (isset($params)) |
| 223 | - $allParameters[] = self::_correctParams($params); |
|
| 223 | + $allParameters[]=self::_correctParams($params); |
|
| 224 | 224 | } |
| 225 | 225 | return \implode("+'&'+", $allParameters); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 229 | - if (! isset($ajaxLoader)) { |
|
| 230 | - $ajaxLoader = $this->ajaxLoader; |
|
| 228 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 229 | + if (!isset($ajaxLoader)) { |
|
| 230 | + $ajaxLoader=$this->ajaxLoader; |
|
| 231 | 231 | } |
| 232 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 233 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 232 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 233 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 237 | - if (! isset($ajaxLoader)) { |
|
| 238 | - $ajaxLoader = $this->ajaxLoader; |
|
| 236 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 237 | + if (!isset($ajaxLoader)) { |
|
| 238 | + $ajaxLoader=$this->ajaxLoader; |
|
| 239 | 239 | } |
| 240 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 241 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 242 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 240 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 241 | + $retour.="{$responseElement}.empty();\n"; |
|
| 242 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | protected function setAjaxDataCall($params) { |
| 246 | - $result = null; |
|
| 247 | - if (! \is_callable($params)) { |
|
| 248 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
| 246 | + $result=null; |
|
| 247 | + if (!\is_callable($params)) { |
|
| 248 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
| 249 | 249 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 250 | 250 | }; |
| 251 | 251 | } |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | protected function setDefaultParameters(&$parameters, $default) { |
| 256 | 256 | foreach ($default as $k => $v) { |
| 257 | - if (! isset($parameters[$k])) |
|
| 258 | - $parameters[$k] = $v; |
|
| 257 | + if (!isset($parameters[$k])) |
|
| 258 | + $parameters[$k]=$v; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | public function setAjaxLoader($loader) { |
| 263 | - $this->ajaxLoader = $loader; |
|
| 263 | + $this->ajaxLoader=$loader; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param string $responseElement |
| 272 | 272 | * selector of the HTML element displaying the answer |
| 273 | 273 | */ |
| 274 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
| 274 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
| 275 | 275 | return $this->_ajax('get', $url, $responseElement, $parameters); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * @param array $parameters |
| 286 | 286 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 287 | 287 | */ |
| 288 | - public function get($url, $responseElement = '', $parameters = []) { |
|
| 289 | - $parameters['immediatly'] = true; |
|
| 288 | + public function get($url, $responseElement='', $parameters=[]) { |
|
| 289 | + $parameters['immediatly']=true; |
|
| 290 | 290 | return $this->_get($url, $responseElement, $parameters); |
| 291 | 291 | } |
| 292 | 292 | |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | * @param array $parameters |
| 303 | 303 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 304 | 304 | */ |
| 305 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 306 | - $parameters['immediatly'] = true; |
|
| 305 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 306 | + $parameters['immediatly']=true; |
|
| 307 | 307 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * $immediatly |
| 326 | 326 | * @return string |
| 327 | 327 | */ |
| 328 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
| 328 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
| 329 | 329 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 330 | 330 | } |
| 331 | 331 | |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param array $parameters |
| 342 | 342 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 343 | 343 | */ |
| 344 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
| 345 | - $parameters['immediatly'] = false; |
|
| 344 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
| 345 | + $parameters['immediatly']=false; |
|
| 346 | 346 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -356,15 +356,15 @@ discard block |
||
| 356 | 356 | * @param array $parameters |
| 357 | 357 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 358 | 358 | */ |
| 359 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 360 | - $parameters = \array_merge($parameters, [ |
|
| 359 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 360 | + $parameters=\array_merge($parameters, [ |
|
| 361 | 361 | "hasLoader" => false |
| 362 | 362 | ]); |
| 363 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 364 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 365 | - $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"; |
|
| 366 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 367 | - $parameters["jsCallback"] = $retour; |
|
| 363 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 364 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 365 | + $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"; |
|
| 366 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 367 | + $parameters["jsCallback"]=$retour; |
|
| 368 | 368 | return $this->_ajax($method, $url, null, $parameters); |
| 369 | 369 | } |
| 370 | 370 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @param array $parameters |
| 379 | 379 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 380 | 380 | */ |
| 381 | - public function json($url, $method = "get", $parameters = []) { |
|
| 381 | + public function json($url, $method="get", $parameters=[]) { |
|
| 382 | 382 | return $this->_json($url, $method, $parameters); |
| 383 | 383 | } |
| 384 | 384 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | * @param array $parameters |
| 395 | 395 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 396 | 396 | */ |
| 397 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
| 397 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
| 398 | 398 | $this->setDefaultParameters($parameters, [ |
| 399 | 399 | 'preventDefault' => true, |
| 400 | 400 | 'stopPropagation' => true, |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | * @param array $parameters |
| 415 | 415 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 416 | 416 | */ |
| 417 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
| 418 | - $parameters['immediatly'] = false; |
|
| 417 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
| 418 | + $parameters['immediatly']=false; |
|
| 419 | 419 | return $this->_json($url, $method, $parameters); |
| 420 | 420 | } |
| 421 | 421 | |
@@ -430,29 +430,29 @@ discard block |
||
| 430 | 430 | * @param array $parameters |
| 431 | 431 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 432 | 432 | */ |
| 433 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 434 | - $parameters = \array_merge($parameters, [ |
|
| 433 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 434 | + $parameters=\array_merge($parameters, [ |
|
| 435 | 435 | "hasLoader" => false |
| 436 | 436 | ]); |
| 437 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 438 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 439 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 440 | - if ($context === null) { |
|
| 441 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 442 | - $newElm = "$('#'+newId)"; |
|
| 437 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 438 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 439 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 440 | + if ($context===null) { |
|
| 441 | + $parent="$('".$maskSelector."').parent()"; |
|
| 442 | + $newElm="$('#'+newId)"; |
|
| 443 | 443 | } else { |
| 444 | - $parent = $context; |
|
| 445 | - $newElm = $context . ".find('#'+newId)"; |
|
| 444 | + $parent=$context; |
|
| 445 | + $newElm=$context.".find('#'+newId)"; |
|
| 446 | 446 | } |
| 447 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 448 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 449 | - $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(); |
|
| 447 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 448 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 449 | + $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(); |
|
| 450 | 450 | 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"; |
| 451 | - $retour .= $appendTo; |
|
| 452 | - $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"; |
|
| 453 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 454 | - $retour .= "\t" . $jsCallback; |
|
| 455 | - $parameters["jsCallback"] = $retour; |
|
| 451 | + $retour.=$appendTo; |
|
| 452 | + $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"; |
|
| 453 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 454 | + $retour.="\t".$jsCallback; |
|
| 455 | + $parameters["jsCallback"]=$retour; |
|
| 456 | 456 | return $this->_ajax($method, $url, null, $parameters); |
| 457 | 457 | } |
| 458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @param array $parameters |
| 468 | 468 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 469 | 469 | */ |
| 470 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 470 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 471 | 471 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 472 | 472 | } |
| 473 | 473 | |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param array $parameters |
| 483 | 483 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 484 | 484 | */ |
| 485 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 486 | - $parameters['immediatly'] = false; |
|
| 485 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 486 | + $parameters['immediatly']=false; |
|
| 487 | 487 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 488 | 488 | } |
| 489 | 489 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * @param array $parameters |
| 500 | 500 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 501 | 501 | */ |
| 502 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
| 502 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
| 503 | 503 | $this->setDefaultParameters($parameters, [ |
| 504 | 504 | 'preventDefault' => true, |
| 505 | 505 | 'stopPropagation' => true, |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | * @param array $parameters |
| 521 | 521 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 522 | 522 | */ |
| 523 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 524 | - $parameters['immediatly'] = false; |
|
| 523 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 524 | + $parameters['immediatly']=false; |
|
| 525 | 525 | return $this->_get($url, $responseElement, $parameters); |
| 526 | 526 | } |
| 527 | 527 | |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | * @param array $parameters |
| 541 | 541 | * 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,"listenerOn"=>false) |
| 542 | 542 | */ |
| 543 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 544 | - $parameters['method'] = 'get'; |
|
| 543 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 544 | + $parameters['method']='get'; |
|
| 545 | 545 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 546 | 546 | } |
| 547 | 547 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @param array $parameters |
| 561 | 561 | * 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,"listenerOn"=>false) |
| 562 | 562 | */ |
| 563 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
| 563 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
| 564 | 564 | $this->setDefaultParameters($parameters, [ |
| 565 | 565 | 'preventDefault' => true, |
| 566 | 566 | 'stopPropagation' => true, |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * @param array $parameters |
| 585 | 585 | * 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,"listenerOn"=>false) |
| 586 | 586 | */ |
| 587 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 587 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 588 | 588 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
| 589 | 589 | } |
| 590 | 590 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * @param array $parameters |
| 602 | 602 | * 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,"listenerOn"=>false) |
| 603 | 603 | */ |
| 604 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 604 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 605 | 605 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
| 606 | 606 | } |
| 607 | 607 | |
@@ -616,15 +616,15 @@ discard block |
||
| 616 | 616 | * 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,"listenerOn"=>false) |
| 617 | 617 | * @return $this |
| 618 | 618 | */ |
| 619 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 620 | - $parameters['attr'] = 'href'; |
|
| 619 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 620 | + $parameters['attr']='href'; |
|
| 621 | 621 | if (JString::isNull($responseElement)) { |
| 622 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 622 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 623 | 623 | } else { |
| 624 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 624 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 625 | 625 | } |
| 626 | - if (! isset($parameters['historize'])) { |
|
| 627 | - $parameters['historize'] = true; |
|
| 626 | + if (!isset($parameters['historize'])) { |
|
| 627 | + $parameters['historize']=true; |
|
| 628 | 628 | } |
| 629 | 629 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 630 | 630 | } |
@@ -640,15 +640,15 @@ discard block |
||
| 640 | 640 | * 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,"listenerOn"=>false) |
| 641 | 641 | * @return $this |
| 642 | 642 | */ |
| 643 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 644 | - $parameters['attr'] = 'href'; |
|
| 643 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 644 | + $parameters['attr']='href'; |
|
| 645 | 645 | if (JString::isNull($responseElement)) { |
| 646 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 646 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 647 | 647 | } else { |
| 648 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 648 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 649 | 649 | } |
| 650 | - if (! isset($parameters['historize'])) { |
|
| 651 | - $parameters['historize'] = true; |
|
| 650 | + if (!isset($parameters['historize'])) { |
|
| 651 | + $parameters['historize']=true; |
|
| 652 | 652 | } |
| 653 | 653 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
| 654 | 654 | } |
@@ -664,26 +664,26 @@ discard block |
||
| 664 | 664 | * 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,"listenerOn"=>false) |
| 665 | 665 | * @return $this |
| 666 | 666 | */ |
| 667 | - public function postFormAction($element, $responseElement = "", $parameters = array()) { |
|
| 668 | - $parameters['attr'] = 'action'; |
|
| 667 | + public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
| 668 | + $parameters['attr']='action'; |
|
| 669 | 669 | if (JString::isNull($responseElement)) { |
| 670 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 670 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 671 | 671 | } else { |
| 672 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 672 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 673 | 673 | } |
| 674 | - $formId = '%$(this).attr("id")%'; |
|
| 675 | - if (! isset($parameters['historize'])) { |
|
| 676 | - $parameters['historize'] = true; |
|
| 674 | + $formId='%$(this).attr("id")%'; |
|
| 675 | + if (!isset($parameters['historize'])) { |
|
| 676 | + $parameters['historize']=true; |
|
| 677 | 677 | } |
| 678 | - $parameters['preventDefault'] = true; |
|
| 679 | - if (! isset($parameters['hasLoader'])) { |
|
| 680 | - $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 678 | + $parameters['preventDefault']=true; |
|
| 679 | + if (!isset($parameters['hasLoader'])) { |
|
| 680 | + $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 681 | 681 | } |
| 682 | 682 | return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
| 686 | - $parameters['params'] = $params; |
|
| 685 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
| 686 | + $parameters['params']=$params; |
|
| 687 | 687 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
| 688 | 688 | } |
| 689 | 689 | |
@@ -699,8 +699,8 @@ discard block |
||
| 699 | 699 | * @param array $parameters |
| 700 | 700 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 701 | 701 | */ |
| 702 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 703 | - $parameters['immediatly'] = true; |
|
| 702 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 703 | + $parameters['immediatly']=true; |
|
| 704 | 704 | return $this->_post($url, $params, $responseElement, $parameters); |
| 705 | 705 | } |
| 706 | 706 | |
@@ -717,8 +717,8 @@ discard block |
||
| 717 | 717 | * @param array $parameters |
| 718 | 718 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 719 | 719 | */ |
| 720 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 721 | - $parameters['immediatly'] = false; |
|
| 720 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 721 | + $parameters['immediatly']=false; |
|
| 722 | 722 | return $this->_post($url, $params, $responseElement, $parameters); |
| 723 | 723 | } |
| 724 | 724 | |
@@ -737,9 +737,9 @@ discard block |
||
| 737 | 737 | * @param array $parameters |
| 738 | 738 | * 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,"listenerOn"=>false) |
| 739 | 739 | */ |
| 740 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 741 | - $parameters['method'] = 'post'; |
|
| 742 | - $parameters['params'] = $params; |
|
| 740 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 741 | + $parameters['method']='post'; |
|
| 742 | + $parameters['params']=$params; |
|
| 743 | 743 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 744 | 744 | } |
| 745 | 745 | |
@@ -757,71 +757,71 @@ discard block |
||
| 757 | 757 | * @param array $parameters |
| 758 | 758 | * 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,"listenerOn"=>false) |
| 759 | 759 | */ |
| 760 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
| 760 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
| 761 | 761 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 764 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 765 | 765 | if (isset($this->params['ajax'])) { |
| 766 | 766 | extract($this->params['ajax']); |
| 767 | 767 | } |
| 768 | - $params = '{}'; |
|
| 769 | - $validation = false; |
|
| 768 | + $params='{}'; |
|
| 769 | + $validation=false; |
|
| 770 | 770 | \extract($parameters); |
| 771 | - $async = ($async) ? 'true' : 'false'; |
|
| 772 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 773 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 774 | - $form = $this->_getFormElement($form); |
|
| 775 | - $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
|
| 776 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 777 | - $retour .= "\nvar params=$('#'+" . $form . ").serialize();\n"; |
|
| 771 | + $async=($async) ? 'true' : 'false'; |
|
| 772 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 773 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 774 | + $form=$this->_getFormElement($form); |
|
| 775 | + $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
| 776 | + if (!isset($contentType) || $contentType!='false') { |
|
| 777 | + $retour.="\nvar params=$('#'+".$form.").serialize();\n"; |
|
| 778 | 778 | if (isset($params)) { |
| 779 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 779 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 780 | 780 | } |
| 781 | 781 | } else { |
| 782 | - $retour .= "\nvar params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
| 782 | + $retour.="\nvar params=new FormData($('#'+".$form.")[0]);\n"; |
|
| 783 | 783 | } |
| 784 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 785 | - $retour .= "var self=this;\n"; |
|
| 786 | - $before = isset($before) ? $before : ""; |
|
| 787 | - $retour .= $before; |
|
| 788 | - if ($hasLoader === true) { |
|
| 784 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 785 | + $retour.="var self=this;\n"; |
|
| 786 | + $before=isset($before) ? $before : ""; |
|
| 787 | + $retour.=$before; |
|
| 788 | + if ($hasLoader===true) { |
|
| 789 | 789 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 790 | - } elseif ($hasLoader === 'response') { |
|
| 790 | + } elseif ($hasLoader==='response') { |
|
| 791 | 791 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 792 | - } elseif ($hasLoader === 'internal-x') { |
|
| 792 | + } elseif ($hasLoader==='internal-x') { |
|
| 793 | 793 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 794 | - } elseif ($hasLoader === 'internal') { |
|
| 795 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 794 | + } elseif ($hasLoader==='internal') { |
|
| 795 | + $retour.="\n$(this).addClass('loading');"; |
|
| 796 | 796 | } elseif (\is_string($hasLoader)) { |
| 797 | - $retour .= "\n$hasLoader.addClass('loading');"; |
|
| 797 | + $retour.="\n$hasLoader.addClass('loading');"; |
|
| 798 | 798 | } |
| 799 | - $ajaxParameters = [ |
|
| 799 | + $ajaxParameters=[ |
|
| 800 | 800 | "url" => "url", |
| 801 | 801 | "method" => "'POST'", |
| 802 | 802 | "data" => "params", |
| 803 | 803 | "async" => $async |
| 804 | 804 | ]; |
| 805 | 805 | if (isset($headers)) { |
| 806 | - $ajaxParameters["headers"] = $headers; |
|
| 806 | + $ajaxParameters["headers"]=$headers; |
|
| 807 | 807 | } |
| 808 | 808 | if (isset($partial)) { |
| 809 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 810 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 809 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 810 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 811 | 811 | } |
| 812 | 812 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 813 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 814 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
| 813 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 814 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 815 | 815 | |
| 816 | 816 | if ($validation) { |
| 817 | - $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
|
| 818 | - " . $retour . " |
|
| 817 | + $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
| 818 | + " . $retour." |
|
| 819 | 819 | }});\n"; |
| 820 | - $retour .= "$('#'+" . $form . ").submit();\n"; |
|
| 820 | + $retour.="$('#'+".$form.").submit();\n"; |
|
| 821 | 821 | } |
| 822 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 822 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 823 | 823 | if ($immediatly) |
| 824 | - $this->jquery_code_for_compile[] = $retour; |
|
| 824 | + $this->jquery_code_for_compile[]=$retour; |
|
| 825 | 825 | return $retour; |
| 826 | 826 | } |
| 827 | 827 | |
@@ -837,8 +837,8 @@ discard block |
||
| 837 | 837 | * @param array $parameters |
| 838 | 838 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 839 | 839 | */ |
| 840 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 841 | - $parameters['immediatly'] = true; |
|
| 840 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 841 | + $parameters['immediatly']=true; |
|
| 842 | 842 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 843 | 843 | } |
| 844 | 844 | |
@@ -855,8 +855,8 @@ discard block |
||
| 855 | 855 | * @param array $parameters |
| 856 | 856 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 857 | 857 | */ |
| 858 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 859 | - $parameters['immediatly'] = false; |
|
| 858 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 859 | + $parameters['immediatly']=false; |
|
| 860 | 860 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 861 | 861 | } |
| 862 | 862 | |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * @param array $parameters |
| 874 | 874 | * 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,"listenerOn"=>false) |
| 875 | 875 | */ |
| 876 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 876 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 877 | 877 | $this->setDefaultParameters($parameters, [ |
| 878 | 878 | 'preventDefault' => true, |
| 879 | 879 | 'stopPropagation' => true, |
@@ -895,11 +895,11 @@ discard block |
||
| 895 | 895 | * @param array $parameters |
| 896 | 896 | * 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,"listenerOn"=>false) |
| 897 | 897 | */ |
| 898 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 898 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 899 | 899 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - public function addCsrf($name = 'csrf-token') { |
|
| 902 | + public function addCsrf($name='csrf-token') { |
|
| 903 | 903 | return " |
| 904 | 904 | $.ajaxSetup({ |
| 905 | 905 | beforeSend: function(xhr, settings) { |
@@ -73,8 +73,9 @@ discard block |
||
| 73 | 73 | $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
| 74 | 74 | |
| 75 | 75 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 76 | - if ($immediatly) |
|
| 77 | - $this->jquery_code_for_compile[] = $retour; |
|
| 76 | + if ($immediatly) { |
|
| 77 | + $this->jquery_code_for_compile[] = $retour; |
|
| 78 | + } |
|
| 78 | 79 | return $retour; |
| 79 | 80 | } |
| 80 | 81 | |
@@ -157,10 +158,11 @@ discard block |
||
| 157 | 158 | } elseif (isset($this->ajaxTransition)) { |
| 158 | 159 | $call = $this->ajaxTransition; |
| 159 | 160 | } |
| 160 | - if (\is_callable($call)) |
|
| 161 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 162 | - else |
|
| 163 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 161 | + if (\is_callable($call)) { |
|
| 162 | + $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 163 | + } else { |
|
| 164 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 165 | + } |
|
| 164 | 166 | } |
| 165 | 167 | if (isset($history)) { |
| 166 | 168 | if ($this->params["autoActiveLinks"]) { |
@@ -194,8 +196,9 @@ discard block |
||
| 194 | 196 | } |
| 195 | 197 | |
| 196 | 198 | protected function _correctAjaxUrl($url) { |
| 197 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 198 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 199 | + if ($url !== "/" && JString::endsWith($url, "/") === true) { |
|
| 200 | + $url = substr($url, 0, strlen($url) - 1); |
|
| 201 | + } |
|
| 199 | 202 | if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
| 200 | 203 | $url = $this->getUrl($url); |
| 201 | 204 | } |
@@ -219,8 +222,9 @@ discard block |
||
| 219 | 222 | public static function _implodeParams($parameters) { |
| 220 | 223 | $allParameters = []; |
| 221 | 224 | foreach ($parameters as $params) { |
| 222 | - if (isset($params)) |
|
| 223 | - $allParameters[] = self::_correctParams($params); |
|
| 225 | + if (isset($params)) { |
|
| 226 | + $allParameters[] = self::_correctParams($params); |
|
| 227 | + } |
|
| 224 | 228 | } |
| 225 | 229 | return \implode("+'&'+", $allParameters); |
| 226 | 230 | } |
@@ -254,8 +258,9 @@ discard block |
||
| 254 | 258 | |
| 255 | 259 | protected function setDefaultParameters(&$parameters, $default) { |
| 256 | 260 | foreach ($default as $k => $v) { |
| 257 | - if (! isset($parameters[$k])) |
|
| 258 | - $parameters[$k] = $v; |
|
| 261 | + if (! isset($parameters[$k])) { |
|
| 262 | + $parameters[$k] = $v; |
|
| 263 | + } |
|
| 259 | 264 | } |
| 260 | 265 | } |
| 261 | 266 | |
@@ -820,8 +825,9 @@ discard block |
||
| 820 | 825 | $retour .= "$('#'+" . $form . ").submit();\n"; |
| 821 | 826 | } |
| 822 | 827 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 823 | - if ($immediatly) |
|
| 824 | - $this->jquery_code_for_compile[] = $retour; |
|
| 828 | + if ($immediatly) { |
|
| 829 | + $this->jquery_code_for_compile[] = $retour; |
|
| 830 | + } |
|
| 825 | 831 | return $retour; |
| 826 | 832 | } |
| 827 | 833 | |