cell: display error message on ajax call failure (#29124)

This commit is contained in:
Lauréline Guérin 2019-10-21 14:38:29 +02:00
parent de7f5dbb15
commit be7053850f
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@
<div class="cell {{ cell.css_class_names }} {% if cell.slug %}{{cell.slug}}{% endif %}"
data-ajax-cell-url="{{ site_base }}{% url 'combo-public-ajax-page-cell' page_pk=cell.page.id cell_reference=cell.get_reference %}"
data-ajax-cell-loading-message="{{ cell.loading_message }}"
data-ajax-cell-error-message="{% trans "Loading error" %}"
{% if cell.ajax_refresh %}
data-ajax-cell-refresh="{{ cell.ajax_refresh }}"
{% endif %}><div>{% render_cell cell %}</div></div>

View File

@ -28,7 +28,11 @@ function combo_load_cell(elem) {
$(document).trigger('combo:cell-loaded', $elem);
},
error: function(error) {
$elem.find('.loading').addClass('error-loading');
var msg = $(elem).data('ajax-cell-error-message');
$elem
.find('.loading')
.addClass('error-loading')
.html('<span class="loading-message">' + msg + '</span>');
window.console && console.log(':(', error);
}
});

View File

@ -8,6 +8,7 @@
{% if cell.slug and cell.use_slug_as_id %}id="{{ cell.slug }}"{% endif %}
data-ajax-cell-url="{{ site_base }}{% url 'combo-public-ajax-page-cell' page_pk=cell.page.id cell_reference=cell.get_reference %}"
data-ajax-cell-loading-message="{{ cell.loading_message }}"
data-ajax-cell-error-message="{% trans "Loading error" %}"
{% if cell.ajax_refresh %}data-ajax-cell-refresh="{{ cell.ajax_refresh }}"{% endif %}
{% if request.extra_context_data %}data-extra-context="{{ request.extra_context_data|signed|urlencode }}"{% endif %}
><div>{% render_cell cell %}</div></div>