From 44ea94520b10fa1bde45416c7842545d49adc493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 22 Aug 2016 16:29:12 +0200 Subject: [PATCH] Meilleure gestion des erreurs lors d'un ajout de majoration --- kfet/templates/kfet/kpsul.html | 16 ++++++++++++---- kfet/views.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 2d7a1238..8b8a335a 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -378,6 +378,14 @@ $(document).ready(function() { } if ('negative' in data['errors']) content += 'Autorisation de négatif requise'; + if ('addcost' in data['errors']) { + content += ''; + } return content; } @@ -1082,16 +1090,16 @@ $(document).ready(function() { }); break; case 400: - displayErrors(getErrorsHtml(data)); + askAddcost(getErrorsHtml(data)); break; } }); } - function askAddcost() { + function askAddcost(errors = '') { $.confirm({ title: 'Majoration', - content: '', + content: errors + '', backgroundDismiss: true, animation:'top', closeAnimation:'bottom', @@ -1108,7 +1116,7 @@ $(document).ready(function() { that.$confirmButton.click(); }); }, - onClose: function() { this._lastFocused = articleSelect; } + onClose: function() { this._lastFocused = triInput; } }); } diff --git a/kfet/views.py b/kfet/views.py index 4702f614..7e5f38d3 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -535,8 +535,8 @@ def kpsul_update_addcost(request): addcost_form = AddcostForm(request.POST) if not addcost_form.is_valid(): - print(addcost_form.errors) - return JsonResponse({}, status=400) + data = { 'errors': { 'addcost': list(addcost_form.errors) } } + return JsonResponse(data, status=400) required_perms = ['kfet.manage_addcosts'] if not request.user.has_perms(required_perms): data = {