From a7e0650821d49ee9d95b8bd470a3782b84d1f8e8 Mon Sep 17 00:00:00 2001 From: equada <81673782+equada@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:03:14 +0200 Subject: [PATCH] add errorhandling to cardrefresh plugin (#3555) Co-authored-by: REJack Co-authored-by: Daniel <50356015+danny007in@users.noreply.github.com> --- .bundlewatch.config.json | 2 +- build/js/CardRefresh.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json index 7ba790125..4ad1c6de6 100644 --- a/.bundlewatch.config.json +++ b/.bundlewatch.config.json @@ -58,7 +58,7 @@ }, { "path": "./dist/js/adminlte.js", - "maxSize": "15.7 kB" + "maxSize": "16.1 kB" }, { "path": "./dist/js/adminlte.min.js", diff --git a/build/js/CardRefresh.js b/build/js/CardRefresh.js index 734116430..2dfc5eac3 100644 --- a/build/js/CardRefresh.js +++ b/build/js/CardRefresh.js @@ -34,12 +34,15 @@ const Default = { content: '.card-body', loadInContent: true, loadOnInit: true, + loadErrorTemplate: true, responseType: '', overlayTemplate: '
', + errorTemplate: '', 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)) }