1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 15:32:22 +00:00

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
// 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.
*/
@ -35,8 +38,11 @@ $(document).ready(function() {
note_list_obj.html("");
buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
"consos_list"));
$("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons,"consos_list");
});
});
}
});
@ -52,8 +58,11 @@ $(document).ready(function() {
$("#note_list").html(consos_list_obj.html());
consos_list_obj.html("");
buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
"note_list"));
$("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons,"note_list");
});
});
}
else {
@ -127,7 +136,11 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
$("#" + list).html(html);
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
@ -148,6 +161,7 @@ function reset() {
$("#profile_pic_link").attr("href", "#");
refreshHistory();
refreshBalance();
LOCK = false;
}
@ -155,6 +169,11 @@ function reset() {
* Apply all transactions: all notes in `notes` buy each item in `buttons`
*/
function consumeAll() {
if (LOCK)
return;
LOCK = true;
let error = false;
if (notes_display.length === 0) {
@ -168,8 +187,10 @@ function consumeAll() {
error = true;
}
if (error)
if (error) {
LOCK = false;
return;
}
notes_display.forEach(function(note_display) {
buttons.forEach(function(button) {

View File

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