From 97b54deb5d7128b93c17cc361692e7a4dee31055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 20 Aug 2016 17:55:46 +0200 Subject: [PATCH] Affichage des erreurs lors d'une commande --- kfet/templates/kfet/kpsul.html | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index b76a3fc1..2a6eec56 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -310,9 +310,11 @@ $(document).ready(function() { // ----- function requestAuth(data, callback) { + var content = getErrorsHtml(data); + content += '', $.confirm({ title: 'Authentification requise', - content: '', + content: content, backgroundDismiss: true, animation:'top', closeAnimation:'bottom', @@ -332,6 +334,44 @@ $(document).ready(function() { }); } + // ----- + // Errors ajax + // ----- + + function getErrorsHtml(data) { + var content = ''; + if ('operation_group' in data['errors']) { + content += 'Général'; + content += ''; + } + if ('missing_perms' in data['errors']) { + content += 'Permissions manquantes'; + content += ''; + } + if ('negative' in data['errors']) + content += 'Autorisation de négatif requise'; + return content; + } + + function displayErrors(html) { + $.alert({ + title: 'Erreurs', + content: html, + backgroundDismiss: true, + animation: 'top', + closeAnimation: 'bottom', + keyboardEnabled: true, + }); + } + // ----- // Perform operations // ----- @@ -362,6 +402,9 @@ $(document).ready(function() { case 403: requestAuth(data, performOperations); break; + case 400: + displayErrors(getErrorsHtml(data)); + break; } }); } @@ -828,7 +871,7 @@ $(document).ready(function() { operation_html .find('#id_form-__prefix__-type').val(type).end() - .find('#id_form-__prefix__-amount').val(amount).end() + .find('#id_form-__prefix__-amount').val((parseFloat(amount)).toFixed(2)).end() .find('#id_form-__prefix__-article').val(article).end() .find('#id_form-__prefix__-article_nb').val(article_nb).end() .find('#id_form-__prefix__-is_checkout').val(is_checkout);