forked from DGNum/gestioCOF
Fix requêtes AJAX simultanées K-Psul
- `lock` limite à 1 le nombre de requêtes AJAX critiques (perform/cancel operations) simultanées afin d'éviter de compter plusieurs la même commande. Ce qui arrivait dans le cas où le panier était fait et en tapant 2 fois enter rapidement (la 2nde requête était lancée avant que la réponse de la 1ère ne revienne)
This commit is contained in:
parent
7ea0998bdb
commit
c27222c751
1 changed files with 13 additions and 1 deletions
|
@ -116,6 +116,9 @@ $(document).ready(function() {
|
||||||
// General
|
// General
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
|
// Lock to avoid multiple requests
|
||||||
|
lock = 0;
|
||||||
|
|
||||||
// Retrieve settings
|
// Retrieve settings
|
||||||
|
|
||||||
settings = {}
|
settings = {}
|
||||||
|
@ -369,6 +372,9 @@ $(document).ready(function() {
|
||||||
var operations = $('#operation_formset');
|
var operations = $('#operation_formset');
|
||||||
|
|
||||||
function performOperations(password = '') {
|
function performOperations(password = '') {
|
||||||
|
if (lock == 1)
|
||||||
|
return false;
|
||||||
|
lock = 1;
|
||||||
var data = operationGroup.serialize() + '&' + operations.serialize();
|
var data = operationGroup.serialize() + '&' + operations.serialize();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
@ -383,6 +389,7 @@ $(document).ready(function() {
|
||||||
})
|
})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
coolReset();
|
coolReset();
|
||||||
|
lock = 0;
|
||||||
})
|
})
|
||||||
.fail(function($xhr) {
|
.fail(function($xhr) {
|
||||||
var data = $xhr.responseJSON;
|
var data = $xhr.responseJSON;
|
||||||
|
@ -398,6 +405,7 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
lock = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,6 +422,9 @@ $(document).ready(function() {
|
||||||
var cancelForm = $('#cancel_form');
|
var cancelForm = $('#cancel_form');
|
||||||
|
|
||||||
function cancelOperations(opes_array, password = '') {
|
function cancelOperations(opes_array, password = '') {
|
||||||
|
if (lock == 1)
|
||||||
|
return false
|
||||||
|
lock = 1;
|
||||||
var data = { 'operations' : opes_array }
|
var data = { 'operations' : opes_array }
|
||||||
$.ajax({
|
$.ajax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
@ -429,6 +440,7 @@ $(document).ready(function() {
|
||||||
})
|
})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
coolReset();
|
coolReset();
|
||||||
|
lock = 0;
|
||||||
})
|
})
|
||||||
.fail(function($xhr) {
|
.fail(function($xhr) {
|
||||||
var data = $xhr.responseJSON;
|
var data = $xhr.responseJSON;
|
||||||
|
@ -442,7 +454,7 @@ $(document).ready(function() {
|
||||||
displayErrors(getErrorsHtml(data));
|
displayErrors(getErrorsHtml(data));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
lock = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue