ScoDoc/app/templates/scolar/partition_editor.j2

926 lines
31 KiB
Plaintext
Raw Normal View History

{# -*- mode: jinja-html -*- #}
2022-07-23 11:17:29 +02:00
<h1>{% if not read_only %}Édition des p{% else %}P{%endif%}artitions</h1>
2022-07-23 11:17:29 +02:00
<main>
<div class="wait"></div>
2022-07-24 21:52:26 +02:00
2022-08-14 17:11:34 +02:00
<section id="zonePartitions">
2023-01-08 17:31:15 +01:00
<h2>Filtres</h2>
2022-08-14 17:11:34 +02:00
<div>
<label class="edition">
2023-01-08 17:31:15 +01:00
<input type="checkbox" autocomplete="off" id="inputModif">
Modifier les partitions et groupes
2022-08-14 17:11:34 +02:00
</label>
2023-01-08 17:31:15 +01:00
<div class="filtres"></div>
<div style="display: flex; justify-content: space-between;">
<div class="editing ajoutPartition">Ajouter une partition</div>
<label class="editing valider" for="inputModif">Fini</label>
2022-07-23 11:17:29 +02:00
</div>
2023-01-08 17:31:15 +01:00
2022-07-23 11:17:29 +02:00
</div>
2022-08-14 17:11:34 +02:00
</section>
<section id="zoneChoix">
<h2>Étudiants</h2>
2023-07-24 21:24:44 +02:00
<details>
2023-07-24 21:34:35 +02:00
<summary>Outils d'affectation</summary>
2023-07-24 21:24:44 +02:00
<div class="autoAffectation">
<a href="students_groups_auto_assignment?formsemestre_id={{formsemestre.id}}"><svg
xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="#0b0b0b" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4M10 17l5-5-5-5M13.8 12H3" />
</svg> Aide à l'affectation dans les parcours</a>
<div>Importer les résultats :
<form class=dropZone>
<div>
Déposez le fichier .xlsx ou <br>
<label>
<input type=file accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
</label>
</div>
</form>
</div>
2023-07-22 22:40:09 +02:00
</div>
2023-07-24 21:24:44 +02:00
<div class="autoAffectation">
Affecter automatiquement les étudiants du groupe<br>
<select name="affectationFrom" id="affectationFrom"></select>
vers le groupe
<select name="affectationTo" id="affectationTo"></select>
<div class="affectationGo">Valider</div>
</div>
</details>
2022-07-23 11:17:29 +02:00
<div class="etudiants"></div>
</section>
2022-08-14 17:11:34 +02:00
2022-07-23 11:17:29 +02:00
<section id="zoneGroupes">
<h2>Groupes</h2>
<div class="groupes"></div>
</section>
</main>
2023-07-22 22:40:09 +02:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx-populate/1.21.0/xlsx-populate.min.js"></script>
2022-07-23 11:17:29 +02:00
<script>
2022-07-23 11:17:29 +02:00
go();
async function go() {
2022-07-24 21:52:26 +02:00
document.querySelector('.wait').style.display = "";
2022-07-23 11:17:29 +02:00
let params = (new URL(document.location)).searchParams;
let formsemestre_id = params.get('formsemestre_id');
2022-07-27 16:11:20 +02:00
let partitions = await fetchData("/ScoDoc/{{formsemestre.departement.acronym}}/api/formsemestre/" + formsemestre_id + "/partitions");
let etudiants = await fetchData("/ScoDoc/{{formsemestre.departement.acronym}}/api/formsemestre/" + formsemestre_id + "/resultats");
2022-07-23 11:17:29 +02:00
2022-07-24 00:18:32 +02:00
etudiants.sort((a, b) => {
return a.nom_short.localeCompare(b.nom_short)
})
2022-07-23 11:17:29 +02:00
processDatas(partitions, etudiants);
processEvents();
2023-01-08 17:31:15 +01:00
listeGroupesAutoaffectation();
2022-07-23 11:17:29 +02:00
2023-01-08 17:31:15 +01:00
document.querySelector("body").classList.add("loaded");
2022-07-23 11:17:29 +02:00
document.querySelector('.wait').style.display = "none";
{% if edit_partition %}
setEditMode();
{% endif %}
2022-07-23 11:17:29 +02:00
}
function fetchData(request) {
return fetch(request)
.then(r => { return r.json() })
.then(data => {
return data;
}).catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors du transfert des données.</h2>";
throw 'Fin du script - données invalides';
})
}
function processDatas(partitions, etudiants) {
/* Filtres et groupes */
2023-01-08 17:31:15 +01:00
let divFiltres = document.querySelector(".filtres");
2022-07-23 11:17:29 +02:00
let outputGroupes = "";
2022-07-27 17:20:43 +02:00
let arrayPartitions = Object.values(partitions).sort((a, b) => {
return a.numero - b.numero;
})
arrayPartitions.forEach((partition) => {
2022-08-14 17:11:34 +02:00
2023-01-08 17:31:15 +01:00
let divPartition = templateFiltres_partition(partition);
divFiltres.appendChild(divPartition);
let arrayGroups = Object.values(partition.groups).sort((a, b) => {
return a.numero - b.numero;
})
arrayGroups.forEach((groupe) => {
let divPlus = divPartition.querySelector(".ajoutGroupe");
divPlus.parentElement.insertBefore(templateFiltres_groupe(groupe), divPlus);
})
2022-07-23 11:17:29 +02:00
// Groupes
outputGroupes += `
2022-07-27 17:20:43 +02:00
<div class=partition data-idpartition="${partition.id}">
2022-07-23 11:17:29 +02:00
<h3>${partition.partition_name}</h3>
<div class=groupe data-idgroupe=aucun>
<div>Non affecté(s)</div>
<div class=etudiants></div>
</div>
${(() => {
2022-07-27 17:20:43 +02:00
let arrayGroups = Object.values(partition.groups).sort((a, b) => {
return a.numero - b.numero;
})
2022-07-27 16:11:20 +02:00
let output = "";
2022-07-27 17:20:43 +02:00
arrayGroups.forEach((groupe) => {
2022-08-14 17:11:34 +02:00
output += templateGroupe_zoneGroupes(groupe.id, groupe.group_name);
2022-07-27 16:11:20 +02:00
})
return output;
})()}
2022-07-23 11:17:29 +02:00
</div>`;
})
2023-01-08 17:31:15 +01:00
document.querySelector("#zoneGroupes>.groupes").innerHTML = outputGroupes;
2022-07-23 11:17:29 +02:00
/* Etudiants */
output = "";
etudiants.forEach(etudiant => {
output += `
2023-07-22 22:40:09 +02:00
<div data-etudid="${etudiant.etudid}" >
<div class=nom data-etudid="${etudiant.etudid}" data-nom="${etudiant.nom_disp}" data-prenom="${etudiant.prenom}"><a href="ficheEtud?etudid=${etudiant.etudid}">${etudiant.nom_disp} ${etudiant.prenom}</a><div class=small>${etudiant.bac}</div></div>
2022-07-23 11:17:29 +02:00
${(() => {
let output = "<div class=grpPartitions>";
2022-07-27 17:20:43 +02:00
arrayPartitions.forEach((partition) => {
2022-07-23 11:17:29 +02:00
output += `
2022-07-27 17:20:43 +02:00
<div class=partition data-idpartition="${partition.id}">
<div>${partition.partition_name}</div>
2022-07-26 00:38:46 +02:00
${(() => {
2022-07-23 11:17:29 +02:00
let output = "";
let affected = false;
2022-07-27 17:20:43 +02:00
let arrayGroups = Object.values(partition.groups).sort((a, b) => {
return a.numero - b.numero;
})
arrayGroups.forEach((groupe) => {
2022-07-23 11:17:29 +02:00
output += `
2023-07-22 22:40:09 +02:00
<label><input type=radio name="${partition.id}-${etudiant.etudid}" value="${groupe.id}" ${(etudiant.partitions[partition.id] == groupe.id) ? "checked" : ""}><span data-grpname="${groupe.group_name}">${groupe.group_name}</span></label>`;
2022-07-23 11:17:29 +02:00
2022-07-27 17:20:43 +02:00
if (etudiant.partitions[partition.id] == groupe.id) {
2022-07-23 11:17:29 +02:00
affected = true;
2022-07-27 17:20:43 +02:00
document.querySelector(`#zoneGroupes [data-idgroupe="${groupe.id}"]>.etudiants`).innerHTML += templateEtudiant_zoneGroupes(etudiant);
2022-07-23 11:17:29 +02:00
}
})
if (!affected) {
2022-07-27 17:20:43 +02:00
document.querySelector(`#zoneGroupes [data-idpartition="${partition.id}"]>[data-idgroupe="aucun"]>.etudiants`).innerHTML += templateEtudiant_zoneGroupes(etudiant);
2022-07-23 11:17:29 +02:00
}
2022-08-14 17:11:34 +02:00
return `<label title="Aucun groupe"><input type=radio name="${partition.id}-${etudiant.etudid}" value="aucun" ${(!affected) ? "checked" : ""}><span class=aucun> - </span></label>` + output;
2022-07-23 11:17:29 +02:00
})()}
2022-07-26 00:38:46 +02:00
</div>`;
2022-07-23 11:17:29 +02:00
})
return output + "</div>";
})()}
</div>`;
})
document.querySelector("#zoneChoix>.etudiants").innerHTML = output;
2022-07-26 00:38:46 +02:00
}
2022-07-23 11:17:29 +02:00
2023-01-08 17:31:15 +01:00
function templateFiltres_partition(partition) {
let div = document.createElement("div");
div.dataset.idpartition = partition.id;
if (partition.groups_editable == false) {
div.classList.add("nonEditable");
}
div.innerHTML = `
<!-- Partition -->
<h3 data-idpartition="${partition.id}">
<span class="editing move">||</span>
<span>${partition.partition_name}</span>
<span class="editing modif">✏️</span>
<span class="editing suppr">❌</span>
<div class=onoff>Masquer<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#0b0b0b" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg></div>
</h3>
<!-- Groupes -->
<div class=groupes>
<button class="dt-button" data-idgroupe=aucun>
2023-01-08 17:31:15 +01:00
Non affectés
</button>
2023-01-08 17:31:15 +01:00
<div class="editing ajoutGroupe">+</div>
2023-02-15 21:27:00 +01:00
</div>
<!-- Config -->
<div class=config>
Configuration
<hr>
<label title="Calculer et afficher les rangs dans les groupes de cette partition ?">
2023-07-22 22:40:09 +02:00
<input class=rang type=checkbox ${partition.bul_show_rank ? "checked" : ""} data-attr=bul_show_rank> Rang bulletins
2023-02-15 21:27:00 +01:00
</label>
<label title="Doit-on afficher les groupes de cette partition dans les listes ?">
2023-07-22 22:40:09 +02:00
<input class=groupe type=checkbox ${partition.show_in_lists ? "checked" : ""} data-attr=show_in_lists> Afficher sur bulletins et tableaux
2023-02-15 21:27:00 +01:00
</label>
<label>
<a class="stdlink" href="/ScoDoc/{{formsemestre.departement.acronym}}/Scolarite/groups_auto_repartition?partition_id=${partition.id}">Répartir les étudiants</a>
</label>
2023-02-15 21:27:00 +01:00
</div>
`;
2023-01-08 17:31:15 +01:00
div.querySelector(".move").addEventListener("mousedown", moveStart);
div.querySelector(".modif").addEventListener("click", editText);
div.querySelector(".suppr").addEventListener("click", suppr);
div.querySelector(".onoff").addEventListener("click", masquerPartitions);
div.querySelector("[data-idgroupe]").addEventListener("click", filtre);
div.querySelector(".ajoutGroupe").addEventListener("click", addGroupe);
2023-02-15 21:27:00 +01:00
div.querySelector(".rang").addEventListener("input", setAttribute);
div.querySelector(".groupe").addEventListener("input", setAttribute);
2023-01-08 17:31:15 +01:00
return div;
}
function templateFiltres_groupe(groupe) {
let div = document.createElement("button");
div.classList.add("dt-button");
2023-01-08 17:31:15 +01:00
div.dataset.idgroupe = groupe.id;
div.innerHTML = `
<span class="editing move">||</span>
<span>${groupe.group_name}</span>
<span class="editing modif">✏️</span>
<span class="editing suppr">❌</span>`;
div.addEventListener("click", filtre);
div.querySelector(".move").addEventListener("mousedown", moveStart);
div.querySelector(".modif").addEventListener("click", editText);
div.querySelector(".suppr").addEventListener("click", suppr);
return div;
}
2022-07-26 00:38:46 +02:00
function templateGroupe_zoneGroupes(idGroupe, name) {
return `<div class=groupe data-idgroupe="${idGroupe}">
<div>${name}</div>
<div class=etudiants></div>
</div>`;
2022-07-23 11:17:29 +02:00
}
2022-07-26 00:38:46 +02:00
function templateEtudiant_zoneGroupes(etudiant) {
2022-07-23 11:17:29 +02:00
return `<div data-etudid="${etudiant.etudid}" data-nom="${etudiant.nom_disp}" data-prenom="${etudiant.prenom}">${etudiant.nom_disp} ${etudiant.prenom}</div>`
}
2023-01-08 17:31:15 +01:00
function listeGroupesAutoaffectation() {
let output = '<option value disabled selected hidden>Choisir</option>';
document.querySelectorAll('#zonePartitions .filtres>div').forEach(partition => {
2023-01-08 20:39:26 +01:00
output += `
<optgroup label="${partition.children[0].children[1].innerText}">
<option value="non-${partition.dataset.idpartition}">Non affectés ${partition.children[0].children[1].innerText}</option>`;
2023-01-08 17:31:15 +01:00
partition.querySelectorAll('[data-idgroupe]:not([data-idgroupe="aucun"])').forEach(groupe => {
2023-01-08 20:39:26 +01:00
output += `<option value=${groupe.dataset.idgroupe}>${groupe.children[1].innerText}</option>`;
2023-01-08 17:31:15 +01:00
})
output += "</optgroup>";
})
document.querySelector("#affectationFrom").innerHTML = output;
document.querySelector("#affectationTo").innerHTML = output;
2023-07-22 22:40:09 +02:00
2023-01-08 17:31:15 +01:00
}
2022-07-24 21:52:26 +02:00
/******************************/
/* Gestionnaire d'événements */
/******************************/
function setEditMode() {
let editing = document.querySelector("[contentEditable=true]");
if (!editing) {
document.querySelector("body").classList.toggle("editionActivated");
return;
2023-01-08 17:31:15 +01:00
}
this.checked = true;
2023-01-08 17:31:15 +01:00
if (!editing.classList.contains("highlight")) {
editing.classList.add("highlight");
2023-01-08 17:31:15 +01:00
setTimeout(() => { editing.classList.remove("highlight") }, 1000);
}
2022-07-25 22:17:46 +02:00
}
2022-07-23 11:17:29 +02:00
function processEvents() {
2022-07-24 21:52:26 +02:00
/*--------------------*/
/* Edition partitions */
/*--------------------*/
document.querySelector(".edition>input").addEventListener("input", setEditMode);
2023-01-08 17:31:15 +01:00
document.querySelectorAll(".ajoutPartition").forEach(btnPlus => { btnPlus.addEventListener("click", addPartition) })
2022-07-24 21:52:26 +02:00
/*--------------------*/
/* Changement groupe */
/*--------------------*/
2022-08-14 17:11:34 +02:00
document.querySelectorAll("label").forEach(btn => { btn.addEventListener("mousedown", (event) => { event.preventDefault() }) });
2022-07-24 21:52:26 +02:00
document.querySelectorAll(".etudiants input").forEach(input => { input.addEventListener("input", assignment) })
2023-01-08 17:31:15 +01:00
document.querySelector(".affectationGo").addEventListener("click", affectationGo);
2022-07-23 11:17:29 +02:00
}
2022-07-24 21:52:26 +02:00
/**********************/
/* Filtrage */
/**********************/
2023-01-08 17:31:15 +01:00
function masquerPartitions() {
let idPartition = this.closest("[data-idpartition]").dataset.idpartition;
document.querySelectorAll(`[data-idpartition="${idPartition}"]`).forEach(e => {
e.classList.toggle("hide");
})
}
2022-07-23 11:17:29 +02:00
function filtre() {
2022-07-24 21:52:26 +02:00
if (document.querySelector("body").classList.contains("editionActivated")) {
return;
}
2022-07-23 11:17:29 +02:00
let nbUnselected = this.parentElement.querySelectorAll(".unselect").length;
let nbBtn = this.parentElement.children.length;
if (nbUnselected == 0) {
Array.from(this.parentElement.children).forEach(e => {
e.classList.toggle("unselect");
})
}
this.classList.toggle("unselect");
nbUnselected = this.parentElement.querySelectorAll(".unselect").length;
if (nbUnselected == nbBtn) {
Array.from(this.parentElement.children).forEach(e => {
e.classList.toggle("unselect");
})
}
2023-01-08 17:31:15 +01:00
// Groupes
let groupesSelected = {};
2023-01-08 20:39:26 +01:00
document.querySelectorAll(".filtres [data-idgroupe]:not(.unselect)").forEach(e => {
let idpartition = e.closest("[data-idpartition]").dataset.idpartition;
2023-01-08 17:31:15 +01:00
if (!groupesSelected[idpartition]) {
groupesSelected[idpartition] = [];
}
groupesSelected[idpartition].push(e.dataset.idgroupe)
})
document.querySelectorAll("#zoneChoix .etudiants>div").forEach(e => {
let found = true;
Object.entries(groupesSelected).forEach(([idpartition, tabGroupes]) => {
if (!tabGroupes.includes(
e.querySelector(`[data-idpartition="${idpartition}"] input:checked`).value
)
) {
found = false
2022-07-23 11:17:29 +02:00
}
2022-07-24 00:18:32 +02:00
})
2023-01-08 17:31:15 +01:00
if (found) {
e.classList.remove("hide")
} else {
e.classList.add("hide")
}
})
2022-07-23 11:17:29 +02:00
}
2023-07-22 22:40:09 +02:00
/*****************************************/
/* Import des résultats auto affectation */
/*****************************************/
document.querySelector(".dropZone").addEventListener("drop", dropFile);
document.querySelector(".dropZone input").addEventListener("change", dropFile);
document.querySelector(".dropZone").addEventListener("dragover", dragOver);
document.querySelector(".dropZone").addEventListener("dragleave", dragLeave);
function dropFile(event) {
event.preventDefault();
this.classList.remove("fileOver");
if (event.target.files?.[0] || event.dataTransfer.items[0].type.match('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) {
let file = event.target.files?.[0] || event.dataTransfer.items[0].getAsFile();
let reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onloadend = () => {
manageFile(reader.result)
}
}
}
function manageFile(file) {
XlsxPopulate.fromDataAsync(file)
.then(function (workbook) {
const sheet = workbook.sheet(0);
let ligne = 1;
let colonne = 1;
let parcours;
let etudid;
while (parcours = sheet.row(ligne).cell(colonne).value()) {
ligne += 2;
while (etudid = sheet.row(ligne).cell(colonne).value()) {
console.log(parcours, etudid);
document.querySelector(`#zoneChoix .etudiants [data-etudid="${etudid}"] [data-grpname="${parcours}"]`)?.click();
ligne++;
}
ligne = 1;
colonne += 3;
}
})
}
function dragOver(event) {
event.preventDefault();
this.classList.add("fileOver")
}
function dragLeave() {
this.classList.remove("fileOver")
}
2022-07-24 21:52:26 +02:00
/****************************/
/* Affectation à un groupe */
/****************************/
2023-07-22 22:40:09 +02:00
function affectationGo() {
2023-01-08 17:31:15 +01:00
let from = document.querySelector("#affectationFrom").value;
let to = document.querySelector("#affectationTo").value;
2023-07-22 22:40:09 +02:00
if (!from || !to) {
2023-01-08 17:31:15 +01:00
return;
}
2023-01-08 20:39:26 +01:00
let elements = [];
2023-07-22 22:40:09 +02:00
if (from[0] != "n") {
2023-01-08 20:39:26 +01:00
elements = document.querySelectorAll(`#zoneChoix .etudiants [value="${from}"]:checked`)
} else {
2023-07-22 22:40:09 +02:00
document.querySelectorAll(`#zoneChoix .etudiants [data-idpartition="${from.split("-")[1]}"]`).forEach(element => {
if (!element.querySelector('input:not([value="aucun"]):checked')) {
2023-01-08 20:39:26 +01:00
elements.push(element);
}
})
}
console.log(elements);
2023-07-22 22:40:09 +02:00
elements.forEach(groupeSelected => {
if (to[0] != "n") {
2023-01-08 20:39:26 +01:00
groupeSelected.closest(".grpPartitions").querySelector(`[value="${to}"]`).click();
2023-07-22 22:40:09 +02:00
} else {
groupeSelected.closest(".grpPartitions").querySelector(`[value="aucun"]`).click();
2023-01-08 20:39:26 +01:00
}
2023-07-22 22:40:09 +02:00
2023-01-08 17:31:15 +01:00
})
}
2022-07-23 11:17:29 +02:00
function assignment() {
let groupe = this.parentElement.parentElement.parentElement.parentElement;
let nom = groupe.children[0].dataset.nom;
let prenom = groupe.children[0].dataset.prenom;
let etudid = groupe.children[0].dataset.etudid;
let idPartition = this.parentElement.parentElement.dataset.idpartition;
let idGroupe = this.value;
document.querySelector(`#zoneGroupes [data-idPartition="${idPartition}"] [data-etudid="${etudid}"]`).remove();
let etudiant = {
etudid: etudid,
nom_disp: nom,
prenom: prenom
}
let results = document.querySelector(`#zoneGroupes [data-idPartition="${idPartition}"] [data-idgroupe="${idGroupe}"]>.etudiants`);
2022-07-26 00:38:46 +02:00
results.innerHTML += templateEtudiant_zoneGroupes(etudiant);
2022-07-23 11:17:29 +02:00
/* Tri */
let results2 = [...results.children];
results2.sort((a, b) => {
return (a.dataset.nom + a.dataset.prenom).localeCompare(b.dataset.nom + b.dataset.prenom)
})
results.innerHTML = "";
results.append(...results2);
/* Save */
this.classList.add("saving");
2022-07-24 00:18:32 +02:00
if (idGroupe == "aucun") {
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${idPartition}/remove_etudiant/${etudid}`;
2022-07-24 00:18:32 +02:00
} else {
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/group/${idGroupe}/set_etudiant/${etudid}`
2022-07-24 00:18:32 +02:00
}
fetch(url, { method: "POST" })
2022-07-23 11:17:29 +02:00
.then(r => { return r.json() })
.then(r => {
2022-07-24 00:18:32 +02:00
if (r.etudid == etudid) {
2022-07-23 11:17:29 +02:00
this.classList.remove("saving");
this.classList.add("saved");
setTimeout(() => { this.classList.remove("saved") }, 800);
return;
}
throw 'Les données retournées ne sont pas valides';
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
}
2022-07-24 21:52:26 +02:00
2022-07-26 00:38:46 +02:00
/****************************/
/* Ajout partition / groupe */
/****************************/
2022-07-24 21:52:26 +02:00
function addPartition() {
2022-07-25 22:17:46 +02:00
let date = new Date;
2022-07-24 21:52:26 +02:00
2023-01-08 17:31:15 +01:00
var name = "Nouvelle " + date.getSeconds();
let params = (new URL(document.location)).searchParams;
let formsemestre_id = params.get('formsemestre_id');
var url = "/ScoDoc/{{formsemestre.departement.acronym}}/api/formsemestre/" + formsemestre_id + "/partition/create";
var payload = { partition_name: name };
2022-08-14 17:11:34 +02:00
2022-07-24 21:52:26 +02:00
// Save
2022-07-25 22:17:46 +02:00
fetch(url,
{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(r => { return r.json() })
.then(r => {
if (r.message == "invalid partition_name" || r.message == "invalid group_name") {
sco_message("Le nom " + name + " existe déjà");
2022-07-25 22:17:46 +02:00
div.remove();
return;
}
2022-07-26 00:38:46 +02:00
2023-01-08 17:31:15 +01:00
// Ajout dans la zone filtres
let partition = {
id: r.id,
partition_name: name
}
let divPartition = templateFiltres_partition(partition);
document.querySelector("#zonePartitions .filtres").appendChild(divPartition);
divPartition.querySelector(".modif").click();
// Ajout de la zone pour chaque étudiant
let outputGroupes = "";
document.querySelectorAll("#zoneChoix .grpPartitions").forEach(e => {
let etudid = e.previousElementSibling.dataset.etudid;
// Préparation pour la section suivante
let etudiant = {
etudid: etudid,
nom_disp: e.previousElementSibling.dataset.nom,
prenom: e.previousElementSibling.dataset.prenom
}
outputGroupes += templateEtudiant_zoneGroupes(etudiant);
////////////////////////
let div = document.createElement("div");
div.className = "partition";
2022-07-26 00:38:46 +02:00
div.dataset.idpartition = r.id;
div.innerHTML = `
2023-01-08 17:31:15 +01:00
<div>${name}</div>
<label title="Aucun groupe">
<input type="radio" name="${r.id}-${etudid}" value="aucun" checked>
<span class="aucun">-</span>
2023-01-08 17:31:15 +01:00
</label>
`;
div.querySelector("input").addEventListener("input", assignment);
e.appendChild(div);
});
// Ajout de la zone groupes
document.querySelector("#zoneGroupes>.groupes").innerHTML += `
<div class=partition data-idpartition="${r.id}">
<h3>${name}</h3>
<div class=groupe data-idgroupe=aucun>
<div>Non affecté(s)</div>
<div class=etudiants>${outputGroupes}</div>
</div>
</div>`;
listeGroupesAutoaffectation();
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
}
function addGroupe() {
let date = new Date;
// Groupe
var name = "Nouveau " + date.getSeconds();
let idPartition = this.parentElement.previousElementSibling.dataset.idpartition;
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${idPartition}/group/create`;
var payload = { group_name: name };
2022-07-26 00:38:46 +02:00
2023-01-08 17:31:15 +01:00
fetch(url,
{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(r => { return r.json() })
.then(r => {
if (r.message == "invalid partition_name" || r.message == "invalid group_name") {
sco_message("Le nom " + name + " existe déjà");
2023-01-08 17:31:15 +01:00
return;
2022-07-25 22:17:46 +02:00
}
2023-01-08 17:31:15 +01:00
let groupe = {
id: r.id,
group_name: name
}
let divGroupe = templateFiltres_groupe(groupe);
this.parentElement.insertBefore(divGroupe, this);
// Ajout du bouton pour chaque étudiant
document.querySelectorAll(`#zoneChoix .etudiants [data-idpartition="${idPartition}"]`).forEach(e => {
let etudid = e.parentElement.previousElementSibling.dataset.etudid;
let label = document.createElement("label");
label.innerHTML = `<input type=radio name="${idPartition}-${etudid}" value="${r.id}"><span>${name}</span>`;
label.querySelector("input").addEventListener("input", assignment);
e.appendChild(label);
})
// Ajout du groupe dans la zone Groupes
document.querySelector(`#zoneGroupes .partition[data-idpartition="${idPartition}"]`).innerHTML += templateGroupe_zoneGroupes(r.id, name);
// Lancement de l'édition du nom
divGroupe.querySelector(".modif").click();
listeGroupesAutoaffectation();
2022-07-25 22:17:46 +02:00
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
2022-07-24 21:52:26 +02:00
}
/********************/
/* Edition du texte */
/********************/
function editText() {
2022-08-14 17:11:34 +02:00
let e = this.previousElementSibling;
e.classList.add("editingText");
e.setAttribute("contenteditable", "true");
e.addEventListener("keydown", writing);
2023-01-08 17:31:15 +01:00
e.addEventListener("focusout", () => { saveEditing(this.previousElementSibling) });
2022-08-14 17:11:34 +02:00
// On sélectionne la zone
const range = document.createRange();
const selection = window.getSelection();
selection.removeAllRanges();
2022-08-14 17:11:34 +02:00
range.selectNodeContents(e);
selection.addRange(range);
2022-07-24 21:52:26 +02:00
}
function writing(event) {
switch (event.key) {
case 'Enter':
saveEditing(this);
event.preventDefault();
break;
case 'Escape':
saveEditing(this);
event.preventDefault();
break;
}
}
function saveEditing(obj) {
2023-07-22 22:40:09 +02:00
// Vérification que le champ est non vide
if (obj.innerText == "") {
event.preventDefault();
sco_message("Ce champ ne peut rester vide.");
obj.focus();
return;
}
// Fin de l'édition
2022-07-24 21:52:26 +02:00
obj.classList.remove("editingText");
obj.setAttribute("contenteditable", "false");
obj.removeEventListener("keydown", writing);
2022-07-25 22:17:46 +02:00
2022-07-24 21:52:26 +02:00
// Save
2022-07-25 22:17:46 +02:00
if (obj.parentElement.dataset.idpartition) {
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${obj.parentElement.dataset.idpartition}/edit`;
2022-07-25 22:17:46 +02:00
var payload = { partition_name: obj.innerText }
document.querySelectorAll(`#zoneChoix .etudiants [data-idpartition="${obj.parentElement.dataset.idpartition}"]>div`).forEach(e => { e.innerText = obj.innerText });
document.querySelector(`#zoneGroupes [data-idpartition="${obj.parentElement.dataset.idpartition}"]>h3`).innerText = obj.innerText;
} else {
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/group/${obj.parentElement.dataset.idgroupe}/edit`;
2022-07-25 22:17:46 +02:00
var payload = { group_name: obj.innerText }
document.querySelectorAll(`#zoneChoix .etudiants [value="${obj.parentElement.dataset.idgroupe}"]+span`).forEach(e => { e.innerText = obj.innerText });
2022-07-26 11:14:36 +02:00
document.querySelector(`#zoneGroupes [data-idgroupe="${obj.parentElement.dataset.idgroupe}"]>div`).innerText = obj.innerText;
2022-07-25 22:17:46 +02:00
}
fetch(url,
{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(r => { return r.json() })
.then(r => {
if (!r) {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
}
2023-01-08 17:31:15 +01:00
listeGroupesAutoaffectation();
2022-07-25 22:17:46 +02:00
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
2022-07-24 21:52:26 +02:00
}
/*********************************/
/* Suppression parcours / groupe */
/*********************************/
function suppr() {
if (this.parentElement.dataset.idpartition) {
var data = `data-idpartition="${this.parentElement.dataset.idpartition}"`;
} else {
var data = `data-idgroupe="${this.parentElement.dataset.idgroupe}"`;
}
let div = document.createElement("div");
div.className = "confirm";
div.innerHTML = `
<div>
2022-07-25 22:17:46 +02:00
<h1>Vous être sur le point de supprimer <span>${this.previousElementSibling.previousElementSibling.innerText}</span>,<br>cette opération est irréversible</h1>
2022-07-24 21:52:26 +02:00
<div>
<div class="ok" ${data}>Supprimer</div>
<div class="nok">Annuler</div>
</div>
</div>
`;
document.body.append(div);
document.querySelector(".ok").addEventListener("click", supprConfirmed);
document.querySelector(".nok").addEventListener("click", closeConfirm);
}
function supprConfirmed() {
closeConfirm();
/* Suppression des éléments dans la page */
if (this.dataset.idpartition) {
document.querySelectorAll(`[data-idpartition="${this.dataset.idpartition}"]`).forEach(e => { e.remove() })
2022-07-27 16:11:20 +02:00
var url = "/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/" + this.dataset.idpartition + "/delete";
2022-07-24 21:52:26 +02:00
} else {
document.querySelectorAll(`[value="${this.dataset.idgroupe}"]`).forEach(e => {
if (e.checked == true) {
e.parentElement.parentElement.querySelector("label").click()
}
e.parentElement.remove()
})
document.querySelectorAll(`[data-idgroupe="${this.dataset.idgroupe}"]`).forEach(e => { e.remove() })
2022-07-27 16:11:20 +02:00
var url = "/ScoDoc/{{formsemestre.departement.acronym}}/api/group/" + this.dataset.idgroupe + "/delete";
2022-07-24 21:52:26 +02:00
}
2022-07-25 22:17:46 +02:00
//Save
fetch(url, { method: "POST" })
.then(r => { return r.json() })
.then(r => {
if (r.OK != true) {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
}
2023-01-08 17:31:15 +01:00
listeGroupesAutoaffectation();
2022-07-25 22:17:46 +02:00
})
2022-07-24 21:52:26 +02:00
}
function closeConfirm() {
document.querySelector(".confirm").remove();
}
/*************************/
/* Changement de l'ordre */
/*************************/
let moveData = {};
function moveStart(event) {
moveData.x = event.pageX;
moveData.y = event.pageY;
2023-01-08 17:31:15 +01:00
if (this.parentElement.dataset.idpartition) {
moveData.element = this.parentElement.parentElement;
} else {
moveData.element = this.parentElement;
}
2022-07-24 21:52:26 +02:00
moveData.element.classList.add("moving");
moveData.element.parentElement.classList.add('grabbing');
document.body.addEventListener("mousemove", move);
document.body.addEventListener("mouseup", moveEnd);
2023-01-08 17:31:15 +01:00
Array.from(moveData.element.parentElement.children).forEach(e => {
if ((e.dataset.idpartition && e.classname != "nonEditable") ||
(e.dataset.idgroupe != "aucun")) {
e.addEventListener("mouseup", newPosition)
}
})
2022-07-24 21:52:26 +02:00
}
function move(event) {
event.preventDefault();
moveData.element.style.transform = `translate(${event.pageX - moveData.x}px, ${event.pageY - moveData.y}px)`
}
function moveEnd() {
document.body.removeEventListener("mousemove", move);
document.body.removeEventListener("mouseup", moveEnd);
moveData.element.parentElement.classList.remove('grabbing');
moveData.element.style.transform = "";
moveData.element.classList.remove("moving");
2023-01-08 17:31:15 +01:00
Array.from(moveData.element.parentElement.children).forEach(e => {
if ((e.dataset.idpartition && e.classname != "nonEditable") ||
(e.dataset.idgroupe && e.dataset.idgroupe != "aucun")) {
e.removeEventListener("mouseup", newPosition)
}
2022-07-24 21:52:26 +02:00
})
moveData = {};
}
2023-01-08 17:31:15 +01:00
function newPosition(event) {
2022-07-24 21:52:26 +02:00
moveData.element.parentElement.insertBefore(moveData.element, this);
let positions = [];
Array.from(moveData.element.parentElement.children).forEach(e => {
2023-01-08 17:31:15 +01:00
if ((e.dataset.idpartition && e.classname != "nonEditable") ||
(e.dataset.idgroupe && e.dataset.idgroupe != "aucun")) {
positions.push(parseInt(e.dataset.idpartition || e.dataset.idgroupe))
2022-07-24 21:52:26 +02:00
}
})
// Save positions
2023-01-08 17:31:15 +01:00
if (this.dataset.idpartition) {
2022-07-25 22:17:46 +02:00
let params = (new URL(document.location)).searchParams;
let formsemestre_id = params.get('formsemestre_id');
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/formsemestre/${formsemestre_id}/partitions/order`;
2022-07-25 22:17:46 +02:00
2022-08-14 17:11:34 +02:00
document.querySelectorAll(`#zonePartitions .masques>div`).forEach(parent => {
2022-07-25 22:17:46 +02:00
positions.forEach(position => {
parent.append(parent.querySelector(`[data-idpartition="${position}"]`))
})
})
document.querySelectorAll(`#zoneChoix .grpPartitions`).forEach(parent => {
2022-07-25 22:17:46 +02:00
positions.forEach(position => {
parent.append(parent.querySelector(`[data-idpartition="${position}"]`))
})
})
document.querySelectorAll(`#zoneGroupes>.groupes`).forEach(parent => {
positions.forEach(position => {
parent.append(parent.querySelector(`[data-idpartition="${position}"]`))
})
})
} else {
2023-01-08 17:31:15 +01:00
let idPartition = this.closest("[data-idpartition]").dataset.idpartition;
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${idPartition}/groups/order`;
2022-07-25 22:17:46 +02:00
2023-01-08 17:31:15 +01:00
document.querySelectorAll(`#zoneChoix .etudiants .partition[data-idpartition="${idPartition}"]`).forEach(partition => {
2022-07-25 22:17:46 +02:00
positions.forEach(position => {
partition.append(partition.querySelector(`[value="${position}"]`).parentElement)
})
})
2023-01-08 17:31:15 +01:00
document.querySelectorAll(`#zoneGroupes .partition[data-idpartition="${idPartition}"]`).forEach(partition => {
2022-07-25 22:17:46 +02:00
positions.forEach(position => {
partition.append(partition.querySelector(`[data-idgroupe="${position}"]`))
})
})
}
fetch(url,
{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(positions)
})
.then(r => { return r.json() })
.then(r => {
if (!r) {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
}
2023-01-08 17:31:15 +01:00
listeGroupesAutoaffectation();
2022-07-25 22:17:46 +02:00
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
}
2023-02-15 21:27:00 +01:00
/*****************/
/* Config */
/*****************/
function setAttribute() {
fetch("partition_set_attr",
{
method: "post",
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
2023-07-22 22:40:09 +02:00
body: `partition_id=${this.closest("[data-idpartition]").dataset.idpartition}&attr=${this.dataset.attr}&value=${this.checked ? 1 : 0}`
2023-02-15 21:27:00 +01:00
}
2023-07-22 22:40:09 +02:00
).then(function (response) {
return response.text();
2023-02-15 21:27:00 +01:00
})
2023-07-22 22:40:09 +02:00
.then(function (txt) {
sco_message(txt);
});
2023-02-15 21:27:00 +01:00
}
2022-07-23 11:17:29 +02:00
</script>