2020-09-26 16:19:37 +02:00
|
|
|
// Formulaire saisie des notes
|
|
|
|
|
2024-08-25 09:07:52 +02:00
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
let noteInputs = document.querySelectorAll("#formnotes .note");
|
|
|
|
noteInputs.forEach(function (input) {
|
|
|
|
input.addEventListener("input", function() {
|
|
|
|
this.setAttribute("data-modified", "true");
|
|
|
|
});
|
|
|
|
input.addEventListener("blur", function() {
|
|
|
|
if (this.getAttribute("data-modified") === "true" && this.value !== this.getAttribute("data-last-saved-value")) {
|
|
|
|
valid_note.call(this);
|
|
|
|
this.setAttribute("data-modified", "false"); // Reset the modified flag
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var formInputs = document.querySelectorAll("#formnotes input");
|
|
|
|
formInputs.forEach(function (input) {
|
|
|
|
input.addEventListener("paste", paste_text);
|
|
|
|
});
|
2021-06-21 18:46:35 +02:00
|
|
|
|
2024-08-25 09:07:52 +02:00
|
|
|
var masquerBtn = document.querySelector(".btn_masquer_DEM");
|
|
|
|
masquerBtn.addEventListener("click", masquer_DEM);
|
2020-09-26 16:19:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function is_valid_note(v) {
|
2023-06-03 22:43:04 +02:00
|
|
|
if (!v) return true;
|
2021-06-21 18:46:35 +02:00
|
|
|
|
2024-08-25 09:07:52 +02:00
|
|
|
var note_min = parseFloat(document.querySelector("#eval_note_min").textContent);
|
|
|
|
var note_max = parseFloat(document.querySelector("#eval_note_max").textContent);
|
2021-06-21 18:46:35 +02:00
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
if (!v.match("^-?[0-9]*.?[0-9]*$")) {
|
|
|
|
return v == "ABS" || v == "EXC" || v == "SUPR" || v == "ATT" || v == "DEM";
|
|
|
|
} else {
|
|
|
|
var x = parseFloat(v);
|
|
|
|
return x >= note_min && x <= note_max;
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function valid_note(e) {
|
2023-06-03 22:43:04 +02:00
|
|
|
var v = this.value.trim().toUpperCase().replace(",", ".");
|
|
|
|
if (is_valid_note(v)) {
|
2024-08-25 09:07:52 +02:00
|
|
|
if (v && v != this.getAttribute("data-last-saved-value")) {
|
2023-06-03 22:43:04 +02:00
|
|
|
this.className = "note_valid_new";
|
2024-08-25 09:07:52 +02:00
|
|
|
const etudid = parseInt(this.getAttribute("data-etudid"));
|
2023-06-03 22:43:04 +02:00
|
|
|
save_note(this, v, etudid);
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
2023-06-03 22:43:04 +02:00
|
|
|
} else {
|
|
|
|
/* Saisie invalide */
|
|
|
|
this.className = "note_invalid";
|
|
|
|
sco_message("valeur invalide ou hors barème");
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
2024-08-25 09:07:52 +02:00
|
|
|
let isSaving = false; // true si requête en cours
|
|
|
|
|
2023-06-03 22:43:04 +02:00
|
|
|
async function save_note(elem, v, etudid) {
|
2024-08-25 09:07:52 +02:00
|
|
|
let evaluation_id = document.querySelector("#formnotes_evaluation_id").getAttribute("value");
|
|
|
|
let formsemestre_id = document.querySelector("#formnotes_formsemestre_id").getAttribute("value");
|
|
|
|
var scoMsg = document.getElementById("sco_msg");
|
|
|
|
scoMsg.innerHTML = "en cours...";
|
|
|
|
scoMsg.style.display = "block";
|
|
|
|
isSaving = true; // Set the flag to true when the request starts
|
2023-06-03 22:43:04 +02:00
|
|
|
try {
|
|
|
|
const response = await fetch(
|
2024-04-10 18:40:32 +02:00
|
|
|
SCO_URL + "../api/evaluation/" + evaluation_id + "/notes/set",
|
2023-06-03 22:43:04 +02:00
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2021-06-21 18:46:35 +02:00
|
|
|
},
|
2023-06-03 22:43:04 +02:00
|
|
|
body: JSON.stringify({
|
|
|
|
notes: [[etudid, v]],
|
|
|
|
comment: document.getElementById("formnotes_comment").value,
|
|
|
|
}),
|
|
|
|
}
|
2021-06-21 18:46:35 +02:00
|
|
|
);
|
2023-06-03 22:43:04 +02:00
|
|
|
if (!response.ok) {
|
|
|
|
sco_message("Erreur: valeur non enregistrée");
|
|
|
|
} else {
|
|
|
|
const data = await response.json();
|
2024-08-25 09:07:52 +02:00
|
|
|
var scoMsg = document.getElementById("sco_msg");
|
|
|
|
scoMsg.style.display = "none";
|
2023-06-03 22:43:04 +02:00
|
|
|
if (data.etudids_changed.length > 0) {
|
|
|
|
sco_message("enregistré");
|
|
|
|
elem.className = "note_saved";
|
|
|
|
// Il y avait une decision de jury ?
|
|
|
|
if (data.etudids_with_decision.includes(etudid)) {
|
2024-08-25 09:07:52 +02:00
|
|
|
if (v !== elem.getAttribute("data-orig-value")) {
|
|
|
|
var juryLink = document.getElementById("jurylink_" + etudid);
|
|
|
|
juryLink.innerHTML = '<a href="formsemestre_validation_etud_form?formsemestre_id=' +
|
|
|
|
formsemestre_id +
|
|
|
|
"&etudid=" +
|
|
|
|
etudid +
|
|
|
|
'">mettre à jour décision de jury</a>';
|
2023-06-03 22:43:04 +02:00
|
|
|
} else {
|
2024-08-25 09:07:52 +02:00
|
|
|
var juryLink = document.getElementById("jurylink_" + etudid);
|
|
|
|
juryLink.innerHTML = "";
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Mise à jour menu historique
|
|
|
|
if (data.history_menu[etudid]) {
|
2024-08-25 09:07:52 +02:00
|
|
|
var historyElem = document.getElementById("hist_" + etudid);
|
|
|
|
historyElem.innerHTML = data.history_menu[etudid];
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
2024-08-25 09:07:52 +02:00
|
|
|
elem.setAttribute("data-last-saved-value", v);
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Fetch error:", error);
|
|
|
|
sco_message("Erreur réseau: valeur non enregistrée");
|
2024-08-25 09:07:52 +02:00
|
|
|
} finally {
|
|
|
|
isSaving = false; // Reset the flag when the request is complete
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
2024-08-25 09:07:52 +02:00
|
|
|
// Set up the beforeunload event listener
|
|
|
|
window.addEventListener('beforeunload', function (e) {
|
|
|
|
let noteInputs = document.querySelectorAll("#formnotes .note");
|
|
|
|
noteInputs.forEach(function (input) {
|
|
|
|
if (input.getAttribute("data-modified") === "true" && input.value !== input.getAttribute("data-last-saved-value")) {
|
|
|
|
valid_note.call(input);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (isSaving) {
|
|
|
|
// Display a confirmation dialog
|
|
|
|
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.returnValue = confirmationMessage; // For compatibility with older browsers
|
|
|
|
return confirmationMessage; // For compatibility with older browsers
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
function change_history(e) {
|
2023-06-03 22:43:04 +02:00
|
|
|
let opt = e.selectedOptions[0];
|
2024-08-25 09:07:52 +02:00
|
|
|
let val = opt.getAttribute("data-note");
|
|
|
|
const etudid = parseInt(e.getAttribute("data-etudid"));
|
2023-06-03 22:43:04 +02:00
|
|
|
// le input associé a ce menu:
|
|
|
|
let input_elem = e.parentElement.parentElement.parentElement.childNodes[0];
|
|
|
|
input_elem.value = val;
|
|
|
|
save_note(input_elem, val, etudid);
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Contribution S.L.: copier/coller des notes
|
|
|
|
|
|
|
|
function paste_text(e) {
|
2023-06-03 22:43:04 +02:00
|
|
|
var event = e.originalEvent;
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
var clipb = e.originalEvent.clipboardData;
|
|
|
|
var data = clipb.getData("Text");
|
|
|
|
var list = data.split(/\r\n|\r|\n|\t| /g);
|
|
|
|
var currentInput = event.currentTarget;
|
|
|
|
var masquerDEM = document
|
|
|
|
.querySelector("body")
|
|
|
|
.classList.contains("masquer_DEM");
|
|
|
|
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
2024-03-21 16:42:28 +01:00
|
|
|
if (!currentInput.disabled) { // skip DEM
|
|
|
|
currentInput.value = list[i];
|
|
|
|
}
|
2023-06-03 22:43:04 +02:00
|
|
|
var evt = document.createEvent("HTMLEvents");
|
|
|
|
evt.initEvent("blur", false, true);
|
|
|
|
currentInput.dispatchEvent(evt);
|
|
|
|
var sibbling = currentInput.parentElement.parentElement.nextElementSibling;
|
|
|
|
while (
|
|
|
|
sibbling &&
|
|
|
|
(sibbling.style.display == "none" ||
|
|
|
|
(masquerDEM && sibbling.classList.contains("etud_dem")))
|
|
|
|
) {
|
|
|
|
sibbling = sibbling.nextElementSibling;
|
|
|
|
}
|
|
|
|
if (sibbling) {
|
|
|
|
currentInput = sibbling.querySelector("input");
|
|
|
|
if (!currentInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
2023-06-03 22:43:04 +02:00
|
|
|
}
|
2021-06-21 18:46:35 +02:00
|
|
|
}
|
2023-01-11 21:19:44 +01:00
|
|
|
|
2023-03-22 21:57:40 +01:00
|
|
|
function masquer_DEM() {
|
2023-06-03 22:43:04 +02:00
|
|
|
document.querySelector("body").classList.toggle("masquer_DEM");
|
2023-01-11 21:19:44 +01:00
|
|
|
}
|