Use gettext for server error messages in modals

This avoids the need to pass them in jsonData (which was broken in a few cases anyhow, since we were forgetting to pass jsonData to the ajaxify function)
pull/7897/head
Matt Westcott 2022-05-11 16:17:48 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 48d397f74f
commit d311a40e27
6 zmienionych plików z 17 dodań i 22 usunięć

Wyświetl plik

@ -1,7 +1,8 @@
import $ from 'jquery';
import { initTabs } from '../../includes/tabs';
import { gettext } from '../../utils/gettext';
const ajaxifyTaskCreateTab = (modal, jsonData) => {
const ajaxifyTaskCreateTab = (modal) => {
$(
'#tab-new a.task-type-choice, #tab-new a.choose-different-task-type',
modal.body,
@ -24,7 +25,9 @@ const ajaxifyTaskCreateTab = (modal, jsonData) => {
success: modal.loadResponseText,
error(response, textStatus, errorThrown) {
const message =
jsonData.error_message +
gettext(
'Report this error to your website administrator with the following information:',
) +
'<br />' +
errorThrown +
' - ' +
@ -32,7 +35,7 @@ const ajaxifyTaskCreateTab = (modal, jsonData) => {
$('#tab-new', modal.body).append(
'<div class="help-block help-critical">' +
'<strong>' +
jsonData.error_label +
gettext('Server Error') +
': </strong>' +
message +
'</div>',

Wyświetl plik

@ -1,5 +1,6 @@
import $ from 'jquery';
import { initTabs } from '../../includes/tabs';
import { gettext } from '../../utils/gettext';
function ajaxifyDocumentUploadForm(modal) {
$('form.document-upload', modal.body).on('submit', function () {
@ -15,7 +16,9 @@ function ajaxifyDocumentUploadForm(modal) {
success: modal.loadResponseText,
error: function (response, textStatus, errorThrown) {
var message =
jsonData.error_message +
gettext(
'Report this error to your website administrator with the following information:',
) +
'<br />' +
errorThrown +
' - ' +
@ -23,7 +26,7 @@ function ajaxifyDocumentUploadForm(modal) {
$('#tab-upload', modal.body).append(
'<div class="help-block help-critical">' +
'<strong>' +
jsonData.error_label +
gettext('Server Error') +
': </strong>' +
message +
'</div>',

Wyświetl plik

@ -1,5 +1,6 @@
import $ from 'jquery';
import { initTabs } from '../../includes/tabs';
import { gettext } from '../../utils/gettext';
function ajaxifyImageUploadForm(modal) {
$('form.image-upload', modal.body).on('submit', function () {
@ -27,7 +28,9 @@ function ajaxifyImageUploadForm(modal) {
success: modal.loadResponseText,
error: function (response, textStatus, errorThrown) {
var message =
jsonData.error_message +
gettext(
'Report this error to your website administrator with the following information:',
) +
'<br />' +
errorThrown +
' - ' +
@ -35,7 +38,7 @@ function ajaxifyImageUploadForm(modal) {
$('#tab-upload').append(
'<div class="help-block help-critical">' +
'<strong>' +
jsonData.error_label +
gettext('Server Error') +
': </strong>' +
message +
'</div>',

Wyświetl plik

@ -655,12 +655,7 @@ class BaseTaskChooserView(TemplateView):
return task_type_choices
def get_form_js_context(self):
return {
"error_label": _("Server Error"),
"error_message": _(
"Report this error to your website administrator with the following information:"
),
}
return {}
def get_task_listing_context_data(self):
search_form = TaskChooserSearchForm(

Wyświetl plik

@ -145,10 +145,6 @@ class ChooseView(BaseChooseView):
self.get_context_data(),
json_data={
"step": "chooser",
"error_label": _("Server Error"),
"error_message": _(
"Report this error to your website administrator with the following information:"
),
"tag_autocomplete_url": reverse("wagtailadmin_tag_autocomplete"),
},
)

Wyświetl plik

@ -5,7 +5,6 @@ from django.template.loader import render_to_string
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.translation import gettext as _
from django.views.generic.base import View
from wagtail import hooks
@ -130,10 +129,6 @@ class ChooseView(BaseChooseView):
self.get_context_data(),
json_data={
"step": "chooser",
"error_label": _("Server Error"),
"error_message": _(
"Report this error to your website administrator with the following information:"
),
"tag_autocomplete_url": reverse("wagtailadmin_tag_autocomplete"),
},
)