Meilleure gestion des erreurs lors d'un ajout de majoration

This commit is contained in:
Aurélien Delobelle 2016-08-22 16:29:12 +02:00
parent 4941b11f56
commit 44ea94520b
2 changed files with 14 additions and 6 deletions

View file

@ -378,6 +378,14 @@ $(document).ready(function() {
} }
if ('negative' in data['errors']) if ('negative' in data['errors'])
content += '<a class="btn btn-primary" href="/k-fet/accounts/'+account_data['trigramme']+'/edit" target="_blank">Autorisation de négatif requise</a>'; content += '<a class="btn btn-primary" href="/k-fet/accounts/'+account_data['trigramme']+'/edit" target="_blank">Autorisation de négatif requise</a>';
if ('addcost' in data['errors']) {
content += '<ul>';
if (data['errors']['addcost'].indexOf('__all__') != -1)
content += '<li>Compte invalide</li>';
if (data['errors']['addcost'].indexOf('amount') != -1)
content += '<li>Montant invalide</li>';
content += '</ul>';
}
return content; return content;
} }
@ -1082,16 +1090,16 @@ $(document).ready(function() {
}); });
break; break;
case 400: case 400:
displayErrors(getErrorsHtml(data)); askAddcost(getErrorsHtml(data));
break; break;
} }
}); });
} }
function askAddcost() { function askAddcost(errors = '') {
$.confirm({ $.confirm({
title: 'Majoration', title: 'Majoration',
content: '<input type="text" placeholder="Trigramme" autocomplete="off" name="trigramme" spellcheck="false" style="text-transform:uppercase" autofocus><input type="number" step="0.01" min="0.01" placeholder="€" name="amount">', content: errors + '<input type="text" placeholder="Trigramme" autocomplete="off" name="trigramme" spellcheck="false" style="text-transform:uppercase" autofocus><input type="number" step="0.01" min="0.01" placeholder="€" name="amount">',
backgroundDismiss: true, backgroundDismiss: true,
animation:'top', animation:'top',
closeAnimation:'bottom', closeAnimation:'bottom',
@ -1108,7 +1116,7 @@ $(document).ready(function() {
that.$confirmButton.click(); that.$confirmButton.click();
}); });
}, },
onClose: function() { this._lastFocused = articleSelect; } onClose: function() { this._lastFocused = triInput; }
}); });
} }

View file

@ -535,8 +535,8 @@ def kpsul_update_addcost(request):
addcost_form = AddcostForm(request.POST) addcost_form = AddcostForm(request.POST)
if not addcost_form.is_valid(): if not addcost_form.is_valid():
print(addcost_form.errors) data = { 'errors': { 'addcost': list(addcost_form.errors) } }
return JsonResponse({}, status=400) return JsonResponse(data, status=400)
required_perms = ['kfet.manage_addcosts'] required_perms = ['kfet.manage_addcosts']
if not request.user.has_perms(required_perms): if not request.user.has_perms(required_perms):
data = { data = {