DocScoDoc/app/templates/scolar/partition_editor.html

681 lines
24 KiB
HTML
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-24 21:52:26 +02:00
<div>
<label class="edition">
2022-07-27 21:58:50 +02:00
<input type="checkbox" autocomplete="off">
2022-07-25 22:17:46 +02:00
Edition des partitions - tout s'enregistre automatiquement dès qu'il y a modification
2022-07-24 21:52:26 +02:00
</label>
</div>
2022-07-23 11:17:29 +02:00
<main>
<div class="wait"></div>
2022-07-24 21:52:26 +02:00
2022-07-23 11:17:29 +02:00
<section id="zoneChoix">
<h2>Choix</h2>
<div class="filtres">
<div class="partitions">
<h3>Afficher les partitions</h3>
<div></div>
</div>
<div class="masques">
<h3>
Afficher les étudiants affectés aux groupes<br>
<small>Ne s'actualise pas automatiquement lors d'une modification</small>
</h3>
<div></div>
</div>
</div>
<div class="etudiants"></div>
</section>
<section id="zoneGroupes">
<h2>Groupes</h2>
<div class="groupes"></div>
</section>
</main>
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();
document.querySelector('.wait').style.display = "none";
}
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 */
2022-07-24 00:18:32 +02:00
let outputPartitions = "<div>";
2022-07-23 11:17:29 +02:00
let outputMasques = "";
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-07-23 11:17:29 +02:00
// Filtres
2022-07-27 17:20:43 +02:00
outputPartitions += `<div 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>`;
outputMasques += `<div data-idpartition="${partition.id}"><div data-idpartition="${partition.id}" data-idgroupe=aucun>Non affectés - ${partition.partition_name}</div>`;
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-07-27 16:11:20 +02:00
/***************/
2022-07-27 17:20:43 +02:00
outputMasques += `<div data-idgroupe="${groupe.id}"><span class="editing move">||</span><span>${groupe.name}</span><span class="editing modif">✏️</span><span class="editing suppr"></span></div>`;
2022-07-27 16:11:20 +02:00
/***************/
2022-07-27 17:20:43 +02:00
output += templateGroupe_zoneGroupes(groupe.id, groupe.name);
2022-07-27 16:11:20 +02:00
})
return output;
})()}
2022-07-23 11:17:29 +02:00
</div>`;
2022-07-24 21:52:26 +02:00
outputMasques += `
<div class="editing ajoutGroupe">+</div>
</div>`;
2022-07-23 11:17:29 +02:00
})
2022-07-24 21:52:26 +02:00
document.querySelector(".filtres>.partitions>div").innerHTML = outputPartitions + `
<div class="editing ajoutPartition">+</div>
</div>`;
2022-07-23 11:17:29 +02:00
document.querySelector(".filtres>.masques>div").innerHTML = outputMasques;
document.querySelector("#zoneGroupes>.groupes").innerHTML = outputGroupes;
/* Etudiants */
output = "";
etudiants.forEach(etudiant => {
output += `
<div>
<div class=nom data-etudid="${etudiant.etudid}" data-nom="${etudiant.nom_disp}" data-prenom="${etudiant.prenom}">${etudiant.nom_disp} ${etudiant.prenom}<br><small>${etudiant.bac}</small></div>
${(() => {
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 += `
2022-07-27 17:20:43 +02:00
<label><input type=radio name="${partition.id}-${etudiant.etudid}" value="${groupe.id}" ${(etudiant.partitions[partition.id] == groupe.id) ? "checked" : ""}><span>${groupe.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-07-27 17:20:43 +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
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>`
}
2022-07-24 21:52:26 +02:00
/******************************/
/* Gestionnaire d'événements */
/******************************/
2022-07-25 22:17:46 +02:00
function input() {
document.querySelector("body").classList.toggle("editionActivated");
/*if (event.currentTarget.checked == false) {
go();
}*/
}
2022-07-23 11:17:29 +02:00
function processEvents() {
2022-07-24 21:52:26 +02:00
/*--------------------*/
/* Edition partitions */
/*--------------------*/
2022-07-25 22:17:46 +02:00
document.querySelector(".edition>input").addEventListener("input", input);
2022-07-24 21:52:26 +02:00
document.querySelectorAll(".ajoutPartition, .ajoutGroupe").forEach(btnPlus => { btnPlus.addEventListener("click", addPartition) })
document.querySelectorAll(".modif").forEach(btn => { btn.addEventListener("click", editText) })
document.querySelectorAll(".suppr").forEach(btn => { btn.addEventListener("click", suppr) })
document.querySelectorAll(".move").forEach(btn => { btn.addEventListener("mousedown", moveStart) })
/*---------*/
/* Filtres */
/*---------*/
document.querySelectorAll(".filtres>div>div>div>div:not(.editing)").forEach(btn => { btn.addEventListener("click", filtre) })
/*--------------------*/
/* Changement groupe */
/*--------------------*/
2022-07-23 11:17:29 +02:00
document.querySelectorAll("#zoneChoix 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) })
2022-07-23 11:17:29 +02:00
}
2022-07-24 21:52:26 +02:00
/**********************/
/* Filtrage */
/**********************/
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");
})
}
if (!this.dataset.idgroupe) {
2022-07-24 00:18:32 +02:00
let groupesSelected = [];
this.parentElement.querySelectorAll(":not(.unselect)").forEach(e => {
groupesSelected.push(e.dataset.idpartition);
})
2022-07-23 11:17:29 +02:00
document.querySelectorAll(`
.etudiants .partition[data-idpartition],
#zoneGroupes [data-idpartition]
`).forEach(e => {
2022-07-24 00:18:32 +02:00
if (groupesSelected.includes(e.dataset.idpartition)) {
2022-07-23 11:17:29 +02:00
e.classList.remove("hide")
} else {
e.classList.add("hide")
}
})
} else {
2022-07-24 00:18:32 +02:00
let groupesSelected = {};
this.parentElement.parentElement.querySelectorAll("[data-idgroupe]:not(.unselect)").forEach(e => {
let idpartition = e.parentElement.dataset.idpartition;
2022-07-24 21:52:26 +02:00
if (!groupesSelected[idpartition]) {
2022-07-24 00:18:32 +02:00
groupesSelected[idpartition] = [];
2022-07-23 11:17:29 +02:00
}
2022-07-24 00:18:32 +02:00
groupesSelected[idpartition].push(e.dataset.idgroupe)
})
document.querySelectorAll("#zoneChoix .etudiants>div").forEach(e => {
let found = true;
2022-07-24 21:52:26 +02:00
Object.entries(groupesSelected).forEach(([idpartition, tabGroupes]) => {
if (!tabGroupes.includes(
e.querySelector(`[data-idpartition="${idpartition}"] input:checked`).value
)
) {
2022-07-24 00:18:32 +02:00
found = false
2022-07-24 21:52:26 +02:00
}
2022-07-24 00:18:32 +02:00
})
2022-07-23 11:17:29 +02:00
if (found) {
e.classList.remove("hide")
} else {
e.classList.add("hide")
}
})
}
}
2022-07-24 21:52:26 +02:00
/****************************/
/* Affectation à un groupe */
/****************************/
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;
if (this.classList.contains("ajoutPartition")) {
2022-07-26 00:38:46 +02:00
// Partition
2022-07-25 22:17:46 +02:00
var name = "Nouvelle " + date.getSeconds();
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 + "/partition/create";
2022-07-25 22:17:46 +02:00
var payload = { partition_name: name };
} else {
2022-07-26 00:38:46 +02:00
// Groupe
2022-07-25 22:17:46 +02:00
var name = "Nouveau " + date.getSeconds();
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${this.parentElement.dataset.idpartition}/group/create`;
2022-07-25 22:17:46 +02:00
var payload = { group_name: name };
}
2022-07-26 11:14:36 +02:00
var div = document.createElement("div");
2022-07-24 21:52:26 +02:00
div.innerHTML = `
<span class="editing move">||</span>
2022-07-25 22:17:46 +02:00
<span>${name}</span>
2022-07-24 21:52:26 +02:00
<span class="editing modif">✏️</span>
<span class="editing suppr"></span>`;
div.querySelector(".modif").addEventListener("click", editText);
div.querySelector(".suppr").addEventListener("click", suppr);
div.querySelector(".move").addEventListener("mousedown", moveStart);
this.parentElement.insertBefore(div, this);
// 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") {
message("Le nom " + name + " existe déjà");
div.remove();
return;
}
if (this.classList.contains("ajoutPartition")) {
div.dataset.idpartition = r.id;
2022-07-26 00:38:46 +02:00
// Ajout dans la zone masques
2022-07-26 11:14:36 +02:00
div = document.createElement("div");
2022-07-26 00:38:46 +02:00
div.dataset.idpartition = r.id;
div.innerHTML = `
<div data-idpartition="${r.id}" data-idgroupe=aucun>Non affectés - ${name}</div>
<div class="editing ajoutGroupe">+</div>`;
div.querySelector("div").addEventListener("click", filtre);
div.querySelector(".ajoutGroupe").addEventListener("click", addPartition);
document.querySelector("#zoneChoix .masques>div").appendChild(div);
// 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,
2022-07-27 16:11:20 +02:00
prenom: e.previousElementSibling.dataset.prenom
2022-07-26 00:38:46 +02:00
}
outputGroupes += templateEtudiant_zoneGroupes(etudiant);
////////////////////////
let div = document.createElement("div");
div.className = "partition";
div.dataset.idpartition = r.id;
div.innerHTML = `
<div>${name}</div>
<label title="Aucun groupe">
<input type="radio" name="${r.id}-${etudid}" value="aucun" checked>
<span class="aucun"></span>
</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>`;
2022-07-25 22:17:46 +02:00
} else {
div.dataset.idgroupe = r.id;
2022-07-26 00:38:46 +02:00
// Ajout du bouton pour chaque étudiant
let idpartition = this.parentElement.dataset.idpartition;
document.querySelectorAll(`#zoneChoix .etudiants [data-idpartition="${idpartition}"]`).forEach(e => {
let etudid = e.parentElement.parentElement.dataset.etudid;
let label = document.createElement("label");
2022-07-26 11:14:36 +02:00
label.innerHTML = `<input type=radio name="${idpartition}-${etudid}" value="${r.id}"><span>${name}</span>`;
2022-07-26 00:38:46 +02:00
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);
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() {
this.previousElementSibling.classList.add("editingText");
this.previousElementSibling.setAttribute("contenteditable", "true");
this.previousElementSibling.focus();
this.previousElementSibling.addEventListener("keydown", writing);
}
function writing(event) {
switch (event.key) {
case 'Enter':
saveEditing(this);
event.preventDefault();
break;
case 'Escape':
saveEditing(this);
event.preventDefault();
break;
}
}
function saveEditing(obj) {
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.querySelector(`.masques [data-idpartition="${obj.parentElement.dataset.idpartition}"][data-idgroupe="aucun"]`).innerText = "Non affectés - " + 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>";
}
})
.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>";
}
})
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;
moveData.element = this.parentElement;
moveData.element.classList.add("moving");
moveData.element.parentElement.classList.add('grabbing');
document.body.addEventListener("mousemove", move);
moveData.element.parentElement.querySelectorAll("div:not([data-idgroupe=aucun])").forEach(e => {
e.addEventListener("mouseup", newPosition)
})
document.body.addEventListener("mouseup", moveEnd);
}
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");
moveData.element.parentElement.querySelectorAll("div:not([data-idgroupe=aucun])").forEach(e => {
e.removeEventListener("mouseup", newPosition)
})
moveData = {};
}
function newPosition() {
moveData.element.parentElement.insertBefore(moveData.element, this);
let positions = [];
Array.from(moveData.element.parentElement.children).forEach(e => {
2022-07-25 22:17:46 +02:00
if ((e.dataset.idpartition && e.dataset.idgroupe != "aucun") || (e.dataset.idgroupe && e.dataset.idgroupe != "aucun")) {
positions.push(parseInt(e.dataset.idgroupe || e.dataset.idpartition))
2022-07-24 21:52:26 +02:00
}
})
// Save positions
2022-07-25 22:17:46 +02:00
if (this.dataset.idpartition) {
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
document.querySelectorAll(`#zoneChoix .masques>div`).forEach(parent => {
positions.forEach(position => {
parent.append(parent.querySelector(`[data-idpartition="${position}"]`))
})
})
document.querySelectorAll(`#zoneChoix .grpPartitions`).forEach(parent => {
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 {
2022-07-27 16:11:20 +02:00
var url = `/ScoDoc/{{formsemestre.departement.acronym}}/api/partition/${this.parentElement.dataset.idpartition}/groups/order`;
2022-07-25 22:17:46 +02:00
document.querySelectorAll(`#zoneChoix .etudiants .partition[data-idpartition="${this.parentElement.dataset.idpartition}"]`).forEach(partition => {
positions.forEach(position => {
partition.append(partition.querySelector(`[value="${position}"]`).parentElement)
})
})
document.querySelectorAll(`#zoneGroupes .partition[data-idpartition="${this.parentElement.dataset.idpartition}"]`).forEach(partition => {
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>";
}
})
.catch(error => {
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données.</h2>";
})
}
/*************************/
/* Message */
/*************************/
function message(msg) {
var div = document.createElement("div");
div.className = "message_curtom";
div.innerHTML = msg;
document.querySelector("body").appendChild(div);
setTimeout(() => {
div.remove();
}, 3000);
2022-07-24 21:52:26 +02:00
}
2022-07-23 11:17:29 +02:00
</script>