Display an error message when a multiaction call fails server-side #29878

This commit is contained in:
Nicolas Demonte 2019-03-04 10:36:03 +01:00
parent 1e75af8347
commit f2553157a0
4 changed files with 148 additions and 21 deletions

View File

@ -1,7 +1,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: pfwbged.collection\n" "Project-Id-Version: pfwbged.collection\n"
"POT-Creation-Date: 2014-06-10 13:26+0000\n" "POT-Creation-Date: 2019-03-04 08:45+0000\n"
"PO-Revision-Date: 2014-04-28 09:24+0200\n" "PO-Revision-Date: 2014-04-28 09:24+0200\n"
"Last-Translator: Frederic Peters <fpeters@entrouvert.com>\n" "Last-Translator: Frederic Peters <fpeters@entrouvert.com>\n"
"Language-Team: French\n" "Language-Team: French\n"
@ -14,15 +14,15 @@ msgstr ""
"Preferred-Encodings: utf-8 latin1\n" "Preferred-Encodings: utf-8 latin1\n"
"Domain: pfwbged.collection\n" "Domain: pfwbged.collection\n"
#: ../portlet.py:167 #: ../portlet.py:170
msgid "Add Collection Portlet" msgid "Add Collection Portlet"
msgstr "Ajouter un portlet de collection" msgstr "Ajouter un portlet de collection"
#: ../searchview.py:324 #: ../searchview.py:372
msgid "Creation Date" msgid "Creation Date"
msgstr "Date de création" msgstr "Date de création"
#: ../portlet.py:180 #: ../portlet.py:183
msgid "Edit Collection Portlet" msgid "Edit Collection Portlet"
msgstr "Modifier le portlet de collection" msgstr "Modifier le portlet de collection"
@ -30,7 +30,7 @@ msgstr "Modifier le portlet de collection"
msgid "Find the collection which provides the items to list" msgid "Find the collection which provides the items to list"
msgstr "Chercher la collection qui fournit les éléments à énumérer; un élément de son titre par exemple." msgstr "Chercher la collection qui fournit les éléments à énumérer; un élément de son titre par exemple."
#: ../searchview.py:175 #: ../searchview.py:180
msgid "Internal Number" msgid "Internal Number"
msgstr "Référence interne" msgstr "Référence interne"
@ -38,19 +38,23 @@ msgstr "Référence interne"
msgid "Limit" msgid "Limit"
msgstr "Limite" msgstr "Limite"
#: ../configure.zcml:29
msgid "PFWB Collection"
msgstr ""
#: ../portlet.py:33 #: ../portlet.py:33
msgid "Portlet header" msgid "Portlet header"
msgstr "Titre" msgstr "Titre"
#: ../searchview.py:344 #: ../searchview.py:392
msgid "Position" msgid "Position"
msgstr "Position" msgstr "Position"
#: ../searchview.py:179 #: ../searchview.py:184
msgid "Recipient(s)" msgid "Recipient(s)"
msgstr "Destinataire(s)" msgstr "Destinataire(s)"
#: ../searchview.py:68 #: ../searchview.py:70
#: ../templates/collection.pt:29 #: ../templates/collection.pt:29
msgid "Save" msgid "Save"
msgstr "Enregistrer" msgstr "Enregistrer"
@ -59,7 +63,7 @@ msgstr "Enregistrer"
msgid "Search Parameters" msgid "Search Parameters"
msgstr "Paramètres de la recherche" msgstr "Paramètres de la recherche"
#: ../searchview.py:177 #: ../searchview.py:182
msgid "Sender" msgid "Sender"
msgstr "Expéditeur" msgstr "Expéditeur"
@ -71,12 +75,12 @@ msgstr "Spécifier le nombre maximum d'éléments à afficher dans ce portlet. L
msgid "Target collection" msgid "Target collection"
msgstr "Collection à utiliser" msgstr "Collection à utiliser"
#: ../portlet.py:168 #: ../portlet.py:171
msgid "This portlet displays a listing of items from a Collection." msgid "This portlet displays a listing of items from a Collection."
msgstr "Ce portlet affiche les éléments d'une collection." msgstr "Ce portlet affiche les éléments d'une collection."
#: ../collection.py:50 #: ../collection.py:50
#: ../searchview.py:58 #: ../searchview.py:60
msgid "Title" msgid "Title"
msgstr "Titre" msgstr "Titre"
@ -84,7 +88,10 @@ msgstr "Titre"
msgid "Title of the rendered portlet" msgid "Title of the rendered portlet"
msgstr "Titre du portlet" msgstr "Titre du portlet"
#: ../searchview.py:360 #: ../searchview.py:408
msgid "Unfile" msgid "Unfile"
msgstr "Retirer du dossier" msgstr "Retirer du dossier"
#: ../multiactions.py:27
msgid "You don't have the right to change the state of these objects:"
msgstr "Vous ne disposez pas des droits pour changer l'état de ces éléments:"

View File

@ -0,0 +1,100 @@
# --- PLEASE EDIT THE LINES BELOW CORRECTLY ---
# SOME DESCRIPTIVE TITLE.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-03-04 08:45+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"
"Language-Code: en\n"
"Language-Name: English\n"
"Preferred-Encodings: utf-8 latin1\n"
"Domain: pfwbged.collection\n"
#: ../portlet.py:170
msgid "Add Collection Portlet"
msgstr ""
#: ../searchview.py:372
msgid "Creation Date"
msgstr ""
#: ../portlet.py:183
msgid "Edit Collection Portlet"
msgstr ""
#: ../portlet.py:39
msgid "Find the collection which provides the items to list"
msgstr ""
#: ../searchview.py:180
msgid "Internal Number"
msgstr ""
#: ../portlet.py:46
msgid "Limit"
msgstr ""
#: ../configure.zcml:29
msgid "PFWB Collection"
msgstr ""
#: ../portlet.py:33
msgid "Portlet header"
msgstr ""
#: ../searchview.py:392
msgid "Position"
msgstr ""
#: ../searchview.py:184
msgid "Recipient(s)"
msgstr ""
#: ../searchview.py:70
#: ../templates/collection.pt:29
msgid "Save"
msgstr ""
#: ../templates/search_view.pt:13
msgid "Search Parameters"
msgstr ""
#: ../searchview.py:182
msgid "Sender"
msgstr ""
#: ../portlet.py:47
msgid "Specify the maximum number of items to show in the portlet. Leave this blank to show the default numer of items."
msgstr ""
#: ../portlet.py:38
msgid "Target collection"
msgstr ""
#: ../portlet.py:171
msgid "This portlet displays a listing of items from a Collection."
msgstr ""
#: ../collection.py:50
#: ../searchview.py:60
msgid "Title"
msgstr ""
#: ../portlet.py:34
msgid "Title of the rendered portlet"
msgstr ""
#: ../searchview.py:408
msgid "Unfile"
msgstr ""
#: ../multiactions.py:27
msgid "You don't have the right to change the state of these objects:"
msgstr ""

View File

@ -1,5 +1,9 @@
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
from pfwbged.collection import _
from plone import api from plone import api
from plone.api.exc import InvalidParameterError
from zope.i18n import translate
class MultiActionsView(BrowserView): class MultiActionsView(BrowserView):
def __call__(self): def __call__(self):
@ -7,12 +11,27 @@ class MultiActionsView(BrowserView):
documents = self.request.form['documents[]'] documents = self.request.form['documents[]']
if isinstance(documents, basestring): if isinstance(documents, basestring):
documents = [documents] documents = [documents]
failures = []
for document_id in documents: for document_id in documents:
document = api.content.get(document_id) document = api.content.get(document_id)
api.content.transition(document, action) try:
document.reindexObject(idxs=['review_state']) api.content.transition(document, action)
if action == 'to_process' and document.portal_type == 'dmsincomingmail': except InvalidParameterError:
from pfwbged.policy.subscribers.mail import incoming_mail_attributed failures.append(document)
incoming_mail_attributed(document, u'') else:
document.reindexObject(idxs=['review_state'])
return 'OK' if action == 'to_process' and document.portal_type == 'dmsincomingmail':
from pfwbged.policy.subscribers.mail import incoming_mail_attributed
incoming_mail_attributed(document, u'')
if failures:
self.request.response.setStatus(403)
header = translate(
_(u'You don\'t have the right to change the state of these objects:'),
context=self.request
)
return u'{}\n{}'.format(
header,
u'\n'.join(['- {}'.format(failure.Title()) for failure in failures]),
)
else:
return 'OK'

View File

@ -337,10 +337,11 @@
$.post(url, {'action': action, 'documents': documents } $.post(url, {'action': action, 'documents': documents }
).done(function() { ).done(function() {
console.log('success'); console.log('success');
$.querywidget.updateSearch(true); }).fail(function(data) {
}).fail(function() {
console.log('fail'); console.log('fail');
alert(data.responseText);
}).always(function() { }).always(function() {
$.querywidget.updateSearch(true);
$div.find('button').prop('disabled', false); $div.find('button').prop('disabled', false);
}); });
} }