Lock interfaces when a transfer is performed to prevent spam click accidents

This commit is contained in:
Yohann D'ANELLO 2020-08-09 13:19:27 +02:00
parent 4afb849aec
commit 255e4dd0aa
2 changed files with 51 additions and 7 deletions

View File

@ -1,6 +1,9 @@
// Copyright (C) 2018-2020 by BDE ENS Paris-Saclay // Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// When a transaction is performed, lock the interface to prevent spam clicks.
let LOCK = false;
/** /**
* Refresh the history table on the consumptions page. * Refresh the history table on the consumptions page.
*/ */
@ -35,8 +38,11 @@ $(document).ready(function() {
note_list_obj.html(""); note_list_obj.html("");
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons, $("#conso_button_" + button.id).click(function() {
"consos_list")); if (LOCK)
return;
removeNote(button, "conso_button", buttons,"consos_list");
});
}); });
} }
}); });
@ -52,8 +58,11 @@ $(document).ready(function() {
$("#note_list").html(consos_list_obj.html()); $("#note_list").html(consos_list_obj.html());
consos_list_obj.html(""); consos_list_obj.html("");
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons, $("#conso_button_" + button.id).click(function() {
"note_list")); if (LOCK)
return;
removeNote(button, "conso_button", buttons,"note_list");
});
}); });
} }
else { else {
@ -127,7 +136,11 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
$("#" + list).html(html); $("#" + list).html(html);
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons, list)); $("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons, list);
});
}); });
} }
else else
@ -148,6 +161,7 @@ function reset() {
$("#profile_pic_link").attr("href", "#"); $("#profile_pic_link").attr("href", "#");
refreshHistory(); refreshHistory();
refreshBalance(); refreshBalance();
LOCK = false;
} }
@ -155,6 +169,11 @@ function reset() {
* Apply all transactions: all notes in `notes` buy each item in `buttons` * Apply all transactions: all notes in `notes` buy each item in `buttons`
*/ */
function consumeAll() { function consumeAll() {
if (LOCK)
return;
LOCK = true;
let error = false; let error = false;
if (notes_display.length === 0) { if (notes_display.length === 0) {
@ -168,8 +187,10 @@ function consumeAll() {
error = true; error = true;
} }
if (error) if (error) {
LOCK = false;
return; return;
}
notes_display.forEach(function(note_display) { notes_display.forEach(function(note_display) {
buttons.forEach(function(button) { buttons.forEach(function(button) {

View File

@ -1,3 +1,5 @@
let LOCK = true;
sources = []; sources = [];
sources_notes_display = []; sources_notes_display = [];
dests = []; dests = [];
@ -42,6 +44,8 @@ function reset(refresh=true) {
refreshBalance(); refreshBalance();
refreshHistory(); refreshHistory();
} }
LOCK = false;
} }
$(document).ready(function() { $(document).ready(function() {
@ -91,6 +95,9 @@ $(document).ready(function() {
let dest = $("#dest_note"); let dest = $("#dest_note");
$("#type_transfer").click(function() { $("#type_transfer").click(function() {
if (LOCK)
return;
$("#source_me_div").removeClass('d-none'); $("#source_me_div").removeClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -102,6 +109,9 @@ $(document).ready(function() {
}); });
$("#type_credit").click(function() { $("#type_credit").click(function() {
if (LOCK)
return;
$("#source_me_div").addClass('d-none'); $("#source_me_div").addClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -122,6 +132,9 @@ $(document).ready(function() {
}); });
$("#type_debit").click(function() { $("#type_debit").click(function() {
if (LOCK)
return;
$("#source_me_div").addClass('d-none'); $("#source_me_div").addClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -165,6 +178,9 @@ $(document).ready(function() {
location.hash = ""; location.hash = "";
$("#source_me").click(function() { $("#source_me").click(function() {
if (LOCK)
return;
// Shortcut to set the current user as the only emitter // Shortcut to set the current user as the only emitter
sources_notes_display.length = 0; sources_notes_display.length = 0;
sources.length = 0; sources.length = 0;
@ -198,6 +214,11 @@ $(document).ready(function() {
}); });
$("#btn_transfer").click(function() { $("#btn_transfer").click(function() {
if (LOCK)
return;
LOCK = true;
let error = false; let error = false;
let amount_field = $("#amount"); let amount_field = $("#amount");
@ -237,8 +258,10 @@ $("#btn_transfer").click(function() {
error = true; error = true;
} }
if (error) if (error) {
LOCK = false;
return; return;
}
let reason = reason_field.val(); let reason = reason_field.val();