@@ -70,10 +70,11 @@ protected function _ajax($method, $url, $responseElement = '', $parameters = [])
70
70
}
71
71
$ this ->createAjaxParameters ($ ajaxParameters , $ parameters );
72
72
$ retour .= "$.ajax({ " . $ this ->implodeAjaxParameters ($ ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) { \n" ;
73
- $ retour .= $ this ->_getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback , $ hasLoader , ($ historize ? $ originalSelector : null )) . "}) " ;
73
+ $ retour .= $ this ->_getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback , ($ historize ? $ originalSelector : null )) . "}) " ;
74
74
if (isset ($ error )) {
75
75
$ retour .= '.fail(function( jqXHR, textStatus, errorThrown ){ ' . $ error . '}) ' ;
76
76
}
77
+ $ retour .= '.always(function( data|jqXHR, textStatus, jqXHR|errorThrown ) { ' . ($ always ?? '' ) . $ this ->removeLoader ($ hasLoader ) . '}) ' ;
77
78
$ retour .= "; \n" ;
78
79
$ retour = $ this ->_addJsCondition ($ jsCondition , $ retour );
79
80
if ($ immediatly ) {
@@ -152,7 +153,7 @@ protected function autoActiveLinks($previousURL = "window.location.href") {
152
153
return $ result ;
153
154
}
154
155
155
- protected function _getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback , $ hasLoader = false , $ history = null ) {
156
+ protected function _getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback , $ history = null ) {
156
157
$ retour = "" ;
157
158
$ call = null ;
158
159
if (JString::isNotNull ($ responseElement )) {
@@ -172,17 +173,20 @@ protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition
172
173
}
173
174
$ retour .= "\nwindow.history.pushState({'html':data,'selector': " . Javascript::prep_value ($ history ) . ",'jqueryDone':' {$ jqueryDone }'},'', url); " ;
174
175
}
175
- if ($ hasLoader === 'internal ' ) {
176
- $ retour .= "\n$(self).removeClass('loading'); " ;
177
- } elseif ($ hasLoader === 'internal-x ' ) {
178
- $ retour .= "\n$(self).children('.ajax-loader').remove(); " ;
179
- } else {
180
- $ retour .= "\n$(self).find('.loading').removeClass('loading'); " ;
181
- }
182
176
$ retour .= "\t" . $ jsCallback . "\n" ;
183
177
return $ retour ;
184
178
}
185
179
180
+ protected function removeLoader ($ hasLoader ) {
181
+ if ($ hasLoader === 'internal ' ) {
182
+ return "\n$(self).removeClass('loading'); " ;
183
+ }
184
+ if ($ hasLoader === 'internal-x ' ) {
185
+ return "\n$(self).children('.ajax-loader').remove(); " ;
186
+ }
187
+ return "\n$(self).find('.loading').removeClass('loading'); " ;
188
+ }
189
+
186
190
protected function _getResponseElement ($ responseElement ) {
187
191
if (JString::isNotNull ($ responseElement )) {
188
192
$ responseElement = Javascript::prep_jquery_selector ($ responseElement );
@@ -821,10 +825,11 @@ private function _postForm($url, $form, $responseElement, $parameters = []) {
821
825
}
822
826
$ this ->createAjaxParameters ($ ajaxParameters , $ parameters );
823
827
$ retour .= "$.ajax({ " . $ this ->implodeAjaxParameters ($ ajaxParameters ) . "}).done(function( data ) { \n" ;
824
- $ retour .= $ this ->_getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback, $ hasLoader ) . "}) " ;
828
+ $ retour .= $ this ->_getOnAjaxDone ($ responseElement , $ jqueryDone , $ ajaxTransition , $ jsCallback ) . "}) " ;
825
829
if (isset ($ error )) {
826
830
$ retour .= '.fail(function( jqXHR, textStatus, errorThrown ){ ' . $ error . '}) ' ;
827
831
}
832
+ $ retour .= '.always(function( data|jqXHR, textStatus, jqXHR|errorThrown ) { ' . ($ always ?? '' ) . $ this ->removeLoader ($ hasLoader ) . '}) ' ;
828
833
$ retour .= "; \n" ;
829
834
if ($ validation ) {
830
835
$ retour = "$('#'+ " . $ form . ").validate({submitHandler: function(form) {
0 commit comments