From aa9d85f4bd16998768450951159daf91ef083755 Mon Sep 17 00:00:00 2001 From: Iziram Date: Sun, 25 Aug 2024 08:05:40 +0200 Subject: [PATCH] fix multi-select "formData" --- app/scodoc/sco_groups_view.py | 6 +----- app/static/js/groups_view.js | 21 ++++++++++++++++----- app/static/js/multi-select.js | 14 +++++++++++++- app/views/assiduites.py | 5 ++--- app/views/groups.py | 8 ++++---- app/views/notes.py | 1 + 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 02185fd87..598ede762 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -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();") diff --git a/app/static/js/groups_view.js b/app/static/js/groups_view.js index 43eb694be..40e59c837 100644 --- a/app/static/js/groups_view.js +++ b/app/static/js/groups_view.js @@ -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 diff --git a/app/static/js/multi-select.js b/app/static/js/multi-select.js index acd2226b3..38bf86c02 100644 --- a/app/static/js/multi-select.js +++ b/app/static/js/multi-select.js @@ -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) { diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 9e4cd77b7..49b861a8a 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -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(), diff --git a/app/views/groups.py b/app/views/groups.py index 2dc869321..bff0b4685 100644 --- a/app/views/groups.py +++ b/app/views/groups.py @@ -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, ) diff --git a/app/views/notes.py b/app/views/notes.py index 194e5092f..e3fbdf4f7 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -30,6 +30,7 @@ Module notes: issu de ScoDoc7 / ZNotes.py Emmanuel Viennet, 2021 """ + import html from operator import itemgetter import time