add errorhandling to cardrefresh plugin (#3555)

Co-authored-by: REJack <info@rejack.de>
Co-authored-by: Daniel <50356015+danny007in@users.noreply.github.com>
This commit is contained in:
equada 2021-04-27 14:03:14 +02:00 committed by GitHub
parent bd372c0904
commit a7e0650821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -58,7 +58,7 @@
},
{
"path": "./dist/js/adminlte.js",
"maxSize": "15.7 kB"
"maxSize": "16.1 kB"
},
{
"path": "./dist/js/adminlte.min.js",

View file

@ -34,12 +34,15 @@ const Default = {
content: '.card-body',
loadInContent: true,
loadOnInit: true,
loadErrorTemplate: true,
responseType: '',
overlayTemplate: '<div class="overlay"><i class="fas fa-2x fa-sync-alt fa-spin"></i></div>',
errorTemplate: '<span class="text-danger"></span>',
onLoadStart() {},
onLoadDone(response) {
return response
}
},
onLoadFail(_jqXHR, _textStatus, _errorThrown) {}
}
class CardRefresh {
@ -74,6 +77,16 @@ class CardRefresh {
this._settings.onLoadDone.call($(this), response)
this._removeOverlay()
}, this._settings.responseType !== '' && this._settings.responseType)
.fail((jqXHR, textStatus, errorThrown) => {
this._removeOverlay()
if (this._settings.loadErrorTemplate) {
const msg = $(this._settings.errorTemplate).text(errorThrown)
this._parent.find(this._settings.content).empty().append(msg)
}
this._settings.onLoadFail.call($(this), jqXHR, textStatus, errorThrown)
})
$(this._element).trigger($.Event(EVENT_LOADED))
}