Skip to content
Snippets Groups Projects
Commit 26d3e5e9 authored by Jean-Marie Place's avatar Jean-Marie Place
Browse files

fix t1054

parent 0be6fd65
No related branches found
No related tags found
No related merge requests found
// Formulaire saisie des notes // Formulaire saisie des notes
let nbSaving = 0; // nombre de requêtes en cours
function incSaving() {
nbSaving++;
// disable button 'Terminer'
anchor = document.querySelector(".link-terminer");
anchor.style.display = "none"
}
function decSaving() {
nbSaving--;
if (nbSaving == 0) {
// re-enable bouton 'Terminer'
anchor = document.querySelector(".link-terminer");
anchor.style.display = "";
}
}
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
let noteInputs = document.querySelectorAll("#formnotes .note"); let noteInputs = document.querySelectorAll("#formnotes .note");
noteInputs.forEach(function (input) { noteInputs.forEach(function (input) {
...@@ -54,15 +72,13 @@ function valid_note(e) { ...@@ -54,15 +72,13 @@ function valid_note(e) {
} }
} }
let isSaving = false; // true si requête en cours
async function save_note(elem, v, etudid) { async function save_note(elem, v, etudid) {
let evaluation_id = document.querySelector("#formnotes_evaluation_id").getAttribute("value"); let evaluation_id = document.querySelector("#formnotes_evaluation_id").getAttribute("value");
let formsemestre_id = document.querySelector("#formnotes_formsemestre_id").getAttribute("value"); let formsemestre_id = document.querySelector("#formnotes_formsemestre_id").getAttribute("value");
var scoMsg = document.getElementById("sco_msg"); var scoMsg = document.getElementById("sco_msg");
scoMsg.innerHTML = "en cours..."; scoMsg.innerHTML = "en cours...";
scoMsg.style.display = "block"; scoMsg.style.display = "block";
isSaving = true; // Set the flag to true when the request starts incSaving(); // update counter to show one more saving in progress
try { try {
const response = await fetch( const response = await fetch(
SCO_URL + "../api/evaluation/" + evaluation_id + "/notes/set", SCO_URL + "../api/evaluation/" + evaluation_id + "/notes/set",
...@@ -109,7 +125,7 @@ async function save_note(elem, v, etudid) { ...@@ -109,7 +125,7 @@ async function save_note(elem, v, etudid) {
console.error("Fetch error:", error); console.error("Fetch error:", error);
sco_message("Erreur réseau: valeur non enregistrée"); sco_message("Erreur réseau: valeur non enregistrée");
} finally { } finally {
isSaving = false; // Reset the flag when the request is complete decSaving(); // update counter to show one saving in progress less. May re-enable 'Terminer' button
} }
} }
...@@ -121,7 +137,7 @@ window.addEventListener('beforeunload', function (e) { ...@@ -121,7 +137,7 @@ window.addEventListener('beforeunload', function (e) {
valid_note.call(input); valid_note.call(input);
} }
}); });
if (isSaving) { if (nbSaving > 0) {
// Display a confirmation dialog // Display a confirmation dialog
const confirmationMessage = 'Des modifications sont en cours de sauvegarde. Êtes-vous sûr de vouloir quitter cette page ?'; const confirmationMessage = 'Des modifications sont en cours de sauvegarde. Êtes-vous sûr de vouloir quitter cette page ?';
e.preventDefault(); // Standard for most modern browsers e.preventDefault(); // Standard for most modern browsers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment