Adapte le JS aux nouvelles erreurs
This commit is contained in:
parent
29236e0b0e
commit
964eec6ab1
4 changed files with 70 additions and 105 deletions
|
@ -257,11 +257,11 @@ function KHistory(options = {}) {
|
||||||
switch ($xhr.status) {
|
switch ($xhr.status) {
|
||||||
case 403:
|
case 403:
|
||||||
requestAuth(data, function (password) {
|
requestAuth(data, function (password) {
|
||||||
this.cancel(opes, password);
|
that._cancel(type, opes, password);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
displayErrors(getErrorsHtml(data));
|
displayErrors(data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
window.lock = 0;
|
window.lock = 0;
|
||||||
|
|
|
@ -106,116 +106,81 @@ function amountToUKF(amount, is_cof = false, account = false) {
|
||||||
return rounding(amount * coef_cof * 10);
|
return rounding(amount * coef_cof * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorsHtml(data) {
|
function getErrorsHtml(data, is_error = true) {
|
||||||
var content = '';
|
console.log("data")
|
||||||
if (!data)
|
if (is_error) {
|
||||||
return "L'utilisateur n'est pas dans l'équipe";
|
data = data.map(error => error.message)
|
||||||
if ('operation_group' in data['errors']) {
|
|
||||||
content += 'Général';
|
|
||||||
content += '<ul>';
|
|
||||||
if (data['errors']['operation_group'].indexOf('on_acc') != -1)
|
|
||||||
content += '<li>Pas de compte sélectionné</li>';
|
|
||||||
if (data['errors']['operation_group'].indexOf('checkout') != -1)
|
|
||||||
content += '<li>Pas de caisse sélectionnée</li>';
|
|
||||||
content += '</ul>';
|
|
||||||
}
|
}
|
||||||
if ('missing_perms' in data['errors']) {
|
|
||||||
content += 'Permissions manquantes';
|
var content = is_error ? "Général :" : "Permissions manquantes :";
|
||||||
content += '<ul>';
|
content += "<ul>";
|
||||||
for (var i = 0; i < data['errors']['missing_perms'].length; i++)
|
for (const message of data) {
|
||||||
content += '<li>' + data['errors']['missing_perms'][i] + '</li>';
|
content += '<li>' + message + '</li>';
|
||||||
content += '</ul>';
|
|
||||||
}
|
|
||||||
if ('negative' in data['errors']) {
|
|
||||||
if (window.location.pathname.startsWith('/gestion/')) {
|
|
||||||
var url_base = '/gestion/k-fet/accounts/';
|
|
||||||
} else {
|
|
||||||
var url_base = '/k-fet/accounts/';
|
|
||||||
}
|
|
||||||
for (var i = 0; i < data['errors']['negative'].length; i++) {
|
|
||||||
content += '<a class="btn btn-primary" href="' + url_base + data['errors']['negative'][i] + '/edit" target="_blank" style="width:100%">Autorisation de négatif requise pour ' + data['errors']['negative'][i] + '</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>';
|
|
||||||
}
|
|
||||||
if ('account' in data['errors']) {
|
|
||||||
content += 'Général';
|
|
||||||
content += '<ul>';
|
|
||||||
content += '<li>Opération invalide sur le compte ' + data['errors']['account'] + '</li>';
|
|
||||||
content += '</ul>';
|
|
||||||
}
|
|
||||||
if ('frozen' in data['errors']) {
|
|
||||||
content += 'Général';
|
|
||||||
content += '<ul>';
|
|
||||||
content += '<li>Les comptes suivants sont gelés : ' + data['errors']['frozen'].join(", ") + '</li>';
|
|
||||||
content += '</ul>';
|
|
||||||
}
|
}
|
||||||
|
content += "</ul>";
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestAuth(data, callback, focus_next = null) {
|
function requestAuth(data, callback, focus_next = null) {
|
||||||
var content = getErrorsHtml(data);
|
var content = getErrorsHtml(data["missing_perms"], is_error = false);
|
||||||
content += '<div class="capslock"><span class="glyphicon glyphicon-lock"></span><input type="password" name="password" autofocus><div>',
|
content += '<div class="capslock"><span class="glyphicon glyphicon-lock"></span><input type="password" name="password" autofocus><div>';
|
||||||
$.confirm({
|
|
||||||
title: 'Authentification requise',
|
|
||||||
content: content,
|
|
||||||
backgroundDismiss: true,
|
|
||||||
animation: 'top',
|
|
||||||
closeAnimation: 'bottom',
|
|
||||||
keyboardEnabled: true,
|
|
||||||
confirm: function () {
|
|
||||||
var password = this.$content.find('input').val();
|
|
||||||
callback(password);
|
|
||||||
},
|
|
||||||
onOpen: function () {
|
|
||||||
var that = this;
|
|
||||||
var capslock = -1; // 1 -> caps on ; 0 -> caps off ; -1 or 2 -> unknown
|
|
||||||
this.$content.find('input').on('keypress', function (e) {
|
|
||||||
if (e.keyCode == 13)
|
|
||||||
that.$confirmButton.click();
|
|
||||||
|
|
||||||
var s = String.fromCharCode(e.which);
|
$.confirm({
|
||||||
if ((s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) || //caps on, shift off
|
title: 'Authentification requise',
|
||||||
(s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey)) { //caps on, shift on
|
content: content,
|
||||||
capslock = 1;
|
backgroundDismiss: true,
|
||||||
} else if ((s.toLowerCase() === s && s.toUpperCase() !== s && !e.shiftKey) || //caps off, shift off
|
animation: 'top',
|
||||||
(s.toLowerCase() !== s && s.toUpperCase() === s && e.shiftKey)) { //caps off, shift on
|
closeAnimation: 'bottom',
|
||||||
capslock = 0;
|
keyboardEnabled: true,
|
||||||
}
|
confirm: function () {
|
||||||
if (capslock == 1)
|
var password = this.$content.find('input').val();
|
||||||
$('.capslock .glyphicon').show();
|
callback(password);
|
||||||
else if (capslock == 0)
|
},
|
||||||
$('.capslock .glyphicon').hide();
|
onOpen: function () {
|
||||||
});
|
var that = this;
|
||||||
// Capslock key is not detected by keypress
|
var capslock = -1; // 1 -> caps on ; 0 -> caps off ; -1 or 2 -> unknown
|
||||||
this.$content.find('input').on('keydown', function (e) {
|
this.$content.find('input').on('keypress', function (e) {
|
||||||
if (e.which == 20) {
|
if (e.keyCode == 13)
|
||||||
capslock = 1 - capslock;
|
that.$confirmButton.click();
|
||||||
}
|
|
||||||
if (capslock == 1)
|
|
||||||
$('.capslock .glyphicon').show();
|
|
||||||
else if (capslock == 0)
|
|
||||||
$('.capslock .glyphicon').hide();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onClose: function () {
|
|
||||||
if (focus_next)
|
|
||||||
this._lastFocused = focus_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
var s = String.fromCharCode(e.which);
|
||||||
|
if ((s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) || //caps on, shift off
|
||||||
|
(s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey)) { //caps on, shift on
|
||||||
|
capslock = 1;
|
||||||
|
} else if ((s.toLowerCase() === s && s.toUpperCase() !== s && !e.shiftKey) || //caps off, shift off
|
||||||
|
(s.toLowerCase() !== s && s.toUpperCase() === s && e.shiftKey)) { //caps off, shift on
|
||||||
|
capslock = 0;
|
||||||
|
}
|
||||||
|
if (capslock == 1)
|
||||||
|
$('.capslock .glyphicon').show();
|
||||||
|
else if (capslock == 0)
|
||||||
|
$('.capslock .glyphicon').hide();
|
||||||
|
});
|
||||||
|
// Capslock key is not detected by keypress
|
||||||
|
this.$content.find('input').on('keydown', function (e) {
|
||||||
|
if (e.which == 20) {
|
||||||
|
capslock = 1 - capslock;
|
||||||
|
}
|
||||||
|
if (capslock == 1)
|
||||||
|
$('.capslock .glyphicon').show();
|
||||||
|
else if (capslock == 0)
|
||||||
|
$('.capslock .glyphicon').hide();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onClose: function () {
|
||||||
|
if (focus_next)
|
||||||
|
this._lastFocused = focus_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayErrors(html) {
|
function displayErrors(data) {
|
||||||
|
const content = getErrorsHtml(data["errors"], is_error = true);
|
||||||
$.alert({
|
$.alert({
|
||||||
title: 'Erreurs',
|
title: 'Erreurs',
|
||||||
content: html,
|
content: content,
|
||||||
backgroundDismiss: true,
|
backgroundDismiss: true,
|
||||||
animation: 'top',
|
animation: 'top',
|
||||||
closeAnimation: 'bottom',
|
closeAnimation: 'bottom',
|
||||||
|
|
|
@ -376,10 +376,10 @@ $(document).ready(function() {
|
||||||
requestAuth(data, performOperations, articleSelect);
|
requestAuth(data, performOperations, articleSelect);
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
if ('need_comment' in data['errors']) {
|
if ('need_comment' in data) {
|
||||||
askComment(performOperations);
|
askComment(performOperations);
|
||||||
} else {
|
} else {
|
||||||
displayErrors(getErrorsHtml(data));
|
displayErrors(data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1074,7 +1074,7 @@ $(document).ready(function() {
|
||||||
}, triInput);
|
}, triInput);
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
askAddcost(getErrorsHtml(data));
|
askAddcost(getErrorsHtml(data["errors"], is_error=true));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -72,7 +72,7 @@ $(document).ready(function () {
|
||||||
var $next = $form.next('.transfer_form').find('.from_acc input');
|
var $next = $form.next('.transfer_form').find('.from_acc input');
|
||||||
}
|
}
|
||||||
var $input_id = $input.next('input');
|
var $input_id = $input.next('input');
|
||||||
if (isValidTrigramme(trigramme)) {
|
if (trigramme.is_valid_trigramme()) {
|
||||||
getAccountData(trigramme, function(data) {
|
getAccountData(trigramme, function(data) {
|
||||||
$input_id.val(data.id);
|
$input_id.val(data.id);
|
||||||
$data.text(data.name);
|
$data.text(data.name);
|
||||||
|
@ -122,7 +122,7 @@ $(document).ready(function () {
|
||||||
requestAuth(data, performTransfers);
|
requestAuth(data, performTransfers);
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
displayErrors(getErrorsHtml(data));
|
displayErrors(data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue