1
0
forked from ScoDoc/ScoDoc

fix multi-select "formData"

This commit is contained in:
Iziram 2024-08-25 08:05:40 +02:00
parent 6e6f76dc26
commit aa9d85f4bd
6 changed files with 37 additions and 18 deletions

View File

@ -224,14 +224,13 @@ def menu_groups_choice(
groups_infos,
submit_on_change=False,
default_deselect_others=True,
html_export=True,
):
"""Menu pour selection groupes
group_ids est la liste des groupes actuellement sélectionnés
et doit comporter au moins un élément, sauf si formsemestre_id est spécifié.
(utilisé pour retrouver le semestre et proposer la liste des autres groupes)
Si html_export :
Si url_export :
selecteur.value = &group_ids=xxx&group_ids=yyy...
sinon :
selecteur.value = [xxx, yyy, ...]
@ -273,9 +272,6 @@ def menu_groups_choice(
values=values, name="group_ids", html_id="group_ids_sel"
)
if html_export:
multi_select.export_format('return "&group_ids="+values.join("&group_ids=")')
if submit_on_change:
multi_select.change_event("submit_group_selector();")

View File

@ -23,7 +23,14 @@ function groups_view_url() {
urlParams.delete("group_ids");
// ajout des groupes selectionnes
var selected_groups = document.getElementById("group_ids_sel").value;
url.search = urlParams.toString() + selected_groups;
if (Array.isArray(selected_groups)) {
selected_groups.forEach((value) => {
urlParams.append("group_ids", value);
});
} else {
urlParams.set("group_ids", selected_groups);
}
url.search = urlParams.toString();
return url.href;
}
@ -61,11 +68,13 @@ function change_list_options(selected_options) {
// Menu choix groupe:
function toggle_visible_etuds() {
//
document.querySelectorAll('.etud_elem').forEach(element => {
element.style.display = 'none';
document.querySelectorAll(".etud_elem").forEach((element) => {
element.style.display = "none";
});
var qargs = "";
var selectedOptions = document.querySelectorAll("#group_ids_sel option:checked");
var selectedOptions = document.querySelectorAll(
"#group_ids_sel option:checked"
);
var qargs = "";
selectedOptions.forEach(function (opt) {
var group_id = opt.value;
@ -79,7 +88,9 @@ function toggle_visible_etuds() {
let input_eval = document.querySelectorAll("#formnotes_evaluation_id");
if (input_eval.length > 0) {
let evaluation_id = input_eval[0].value;
let menu_saisie_tableur_a = document.querySelector("#menu_saisie_tableur a");
let menu_saisie_tableur_a = document.querySelector(
"#menu_saisie_tableur a"
);
menu_saisie_tableur_a.setAttribute(
"href",
"saisie_notes_tableur?evaluation_id=" + evaluation_id + qargs

View File

@ -263,8 +263,20 @@ class MultiSelect extends HTMLElement {
}
this.dispatchEvent(new Event("change"));
// create a FormData object
const fd = new FormData();
const values = this._values();
// check if values is an array
if (Array.isArray(values)) {
values.forEach((value) => {
fd.append(this.name, value);
});
} else {
fd.append(this.name, values);
}
// update the form values
this._internals.setFormValue(this._values());
this._internals.setFormValue(fd);
}
_values(newValues = null) {

View File

@ -24,8 +24,7 @@
#
##############################################################################
"""Vues assiduité
"""
"""Vues assiduité"""
import datetime
import json
@ -1167,7 +1166,7 @@ def signal_assiduites_group():
formsemestre_date_fin=str(formsemestre.date_fin),
formsemestre_id=formsemestre_id,
gr_tit=gr_tit,
grp=sco_groups_view.menu_groups_choice(groups_infos, html_export=False),
grp=sco_groups_view.menu_groups_choice(groups_infos),
minitimeline=_mini_timeline(),
moduleimpl_select=_module_selector(formsemestre, moduleimpl_id),
nonworkdays=_non_work_days(),

View File

@ -41,11 +41,11 @@ def formulaire_feuille_appel(formsemestre_id: int):
group_ids: list[int] = request.args.getlist("group_ids")
data = {"group_ids": group_ids}
else:
group_ids_str = request.form.get("group_ids")
group_ids_list = request.form.getlist("group_ids")
try:
group_ids = [int(gid) for gid in group_ids_str.split(",") if gid]
group_ids = [int(gid) for gid in group_ids_list if gid]
except ValueError as exc:
log(f"formulaire_feuille_appel: group_ids invalide: {group_ids_str[:100]}")
log(f"formulaire_feuille_appel: group_ids invalide: {group_ids_list[:100]}")
raise ScoValueError("groupes invalides") from exc
data = {}
@ -81,6 +81,6 @@ def formulaire_feuille_appel(formsemestre_id: int):
sco_data=ScoData(formsemestre=formsemestre),
form=form,
group_name=groups_infos.groups_titles,
grp=menu_groups_choice(groups_infos, html_export=False),
grp=menu_groups_choice(groups_infos),
formsemestre_id=formsemestre_id,
)

View File

@ -30,6 +30,7 @@ Module notes: issu de ScoDoc7 / ZNotes.py
Emmanuel Viennet, 2021
"""
import html
from operator import itemgetter
import time