forked from DGNum/gestioCOF
Meilleure gestion des erreurs lors d'un ajout de majoration
This commit is contained in:
parent
4941b11f56
commit
44ea94520b
2 changed files with 14 additions and 6 deletions
|
@ -378,6 +378,14 @@ $(document).ready(function() {
|
|||
}
|
||||
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>';
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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: '<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,
|
||||
animation:'top',
|
||||
closeAnimation:'bottom',
|
||||
|
@ -1108,7 +1116,7 @@ $(document).ready(function() {
|
|||
that.$confirmButton.click();
|
||||
});
|
||||
},
|
||||
onClose: function() { this._lastFocused = articleSelect; }
|
||||
onClose: function() { this._lastFocused = triInput; }
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue