From 4429524537a4fe54d1c1736e0ccb8e522ea3a321 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Wed, 12 Jun 2024 14:55:15 +0200 Subject: [PATCH] Fix 'vissible after start time' when creating series --- app/assets/javascripts/series.ts | 33 +++++++++++++++++++------------- app/javascript/packs/series.js | 3 ++- app/views/series/_form.html.erb | 1 + 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/series.ts b/app/assets/javascripts/series.ts index 6ce53d4841..d8fc40b909 100644 --- a/app/assets/javascripts/series.ts +++ b/app/assets/javascripts/series.ts @@ -19,6 +19,25 @@ const DRAG_AND_DROP_ARGS = { }, }; +function initSeriesForm(): void { + function init(): void { + initTimedVisibility(); + } + + function initTimedVisibility(): void { + const timedVisibilityOption = document.getElementById("series_visibility_timed") as HTMLInputElement; + const timingOptions = document.getElementById("timing-options"); + const visibilityOptions = document.querySelectorAll("[name=\"series[visibility]\"]"); + visibilityOptions.forEach( option => { + option.addEventListener("change", () => { + timingOptions.classList.toggle("visually-hidden", !timedVisibilityOption.checked); + }); + }); + } + + init(); +} + function initSeriesEdit(): void { function init(): void { initAddButtons(); @@ -28,7 +47,6 @@ function initSeriesEdit(): void { dodona.seriesEditActivitiesLoaded = () => { initAddButtons(); }; - initTimedVisibility(); } function initAddButtons(): void { @@ -151,17 +169,6 @@ function initSeriesEdit(): void { document.getElementById("to-many-activities-info").classList.toggle("d-none", count <= 10); } - function initTimedVisibility(): void { - const timedVisibilityOption = document.getElementById("series_visibility_timed") as HTMLInputElement; - const timingOptions = document.getElementById("timing-options"); - const visibilityOptions = document.querySelectorAll("[name=\"series[visibility]\"]"); - visibilityOptions.forEach( option => { - option.addEventListener("change", () => { - timingOptions.classList.toggle("visually-hidden", !timedVisibilityOption.checked); - }); - }); - } - init(); } @@ -190,4 +197,4 @@ function initSeriesShow(id: string): void { }); } -export { initSeriesEdit, initSeriesShow }; +export { initSeriesEdit, initSeriesShow, initSeriesForm }; diff --git a/app/javascript/packs/series.js b/app/javascript/packs/series.js index 76b75efa9d..a3bdabd15a 100644 --- a/app/javascript/packs/series.js +++ b/app/javascript/packs/series.js @@ -1,6 +1,7 @@ -import { initSeriesEdit, initSeriesShow } from "series.ts"; +import { initSeriesEdit, initSeriesShow, initSeriesForm } from "series.ts"; import { initDatePicker } from "utilities.ts"; window.dodona.initDeadlinePicker = initDatePicker; window.dodona.initSeriesEdit = initSeriesEdit; window.dodona.initSeriesShow = initSeriesShow; +window.dodona.initSeriesForm = initSeriesForm; diff --git a/app/views/series/_form.html.erb b/app/views/series/_form.html.erb index 5f1a17dbe6..710f468451 100644 --- a/app/views/series/_form.html.erb +++ b/app/views/series/_form.html.erb @@ -108,5 +108,6 @@ dodona.ready.then(function () { dodona.initDeadlinePicker("#deadline-group"); dodona.initDeadlinePicker("#start-group"); + dodona.initSeriesForm(); });