From 999c050182f840d0b6e0c5bb13eb66ec59a62018 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Wed, 13 Nov 2024 15:15:00 +0000
Subject: [PATCH] prevent warning if no self assign is activated, fixes #2518

Closes #2518

Merge request studip/studip!3632
---
 app/controllers/course/statusgroups.php       |  8 +++---
 .../course/statusgroups/create_groups.php     |  9 ++++---
 app/views/course/statusgroups/edit.php        | 13 +++++++---
 .../assets/javascripts/lib/statusgroups.js    | 25 -------------------
 4 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/app/controllers/course/statusgroups.php b/app/controllers/course/statusgroups.php
index 1658a37b892..df8c86e7487 100644
--- a/app/controllers/course/statusgroups.php
+++ b/app/controllers/course/statusgroups.php
@@ -580,9 +580,11 @@ class Course_StatusgroupsController extends AuthenticatedController
         if ($selfassign !== 0) {
             $selfassign += Request::int('exclusive', 0);
         // Selfassign is not set but exclusive selfassign or some timeframe -> show warning message
-        } else if (Request::int('exclusive', 0) !== 0
-                || Request::get('selfassign_start', null) !== null
-                || Request::get('selfassign_end', null) !== null) {
+        } else if (
+            Request::bool('exclusive')
+            || Request::get('selfassign_start')
+            || Request::get('selfassign_end')
+        ) {
             PageLayout::postWarning(_('Einstellungen zum Eintrag in eine Gruppe oder zum Eintragszeitraum können ' .
                 'nur gespeichert werden, wenn der Selbsteintrag aktiviert ist.'));
         }
diff --git a/app/views/course/statusgroups/create_groups.php b/app/views/course/statusgroups/create_groups.php
index c011b79253d..46165009ccb 100644
--- a/app/views/course/statusgroups/create_groups.php
+++ b/app/views/course/statusgroups/create_groups.php
@@ -106,24 +106,25 @@
         </section>
         <section>
             <label>
-                <input type="checkbox" name="selfassign" value="1">
+                <input type="checkbox" name="selfassign" value="1"
+                       data-shows=".self-assign-option">
                 <?= _('Selbsteintrag') ?>
             </label>
         </section>
-        <section>
+        <section class="self-assign-option">
             <label>
                 <input type="checkbox" name="exclusive" value="1">
                 <?= _('Selbsteintrag in nur eine Gruppe') ?>
             </label>
         </section>
-        <section class="col-3">
+        <section class="col-3 self-assign-option">
             <label class="col-3">
                 <?= _('Selbsteintrag erlaubt ab') ?>
                 <input type="text" data-datetime-picker id="selfassign_start"  size="20"
                        name="selfassign_start" value="<?= date('d.m.Y H:i') ?>">
             </label>
         </section>
-        <section class="col-3">
+        <section class="col-3 self-assign-option">
             <label class="col-3">
                 <?= _('Selbsteintrag erlaubt bis') ?>
                 <input type="text" data-datetime-picker='{">":"#selfassign_start"}' size="20"
diff --git a/app/views/course/statusgroups/edit.php b/app/views/course/statusgroups/edit.php
index 1e71d3d9fc6..f09e0436b33 100644
--- a/app/views/course/statusgroups/edit.php
+++ b/app/views/course/statusgroups/edit.php
@@ -39,22 +39,27 @@
         </label>
 
         <label>
-            <input type="checkbox" name="selfassign" value="1"<?= $group->selfassign ? ' checked' : '' ?>>
+            <input type="checkbox"
+                   name="selfassign"
+                   value="1"
+                   data-shows=".self-assign-option"
+                <?= $group->selfassign ? ' checked' : '' ?>
+            >
             <?= _('Selbsteintrag erlaubt') ?>
         </label>
 
-        <label>
+        <label class="self-assign-option">
             <input type="checkbox" name="exclusive" value="1"<?= $group->selfassign == 2 ? ' checked' : '' ?>>
             <?= _('Exklusiver Selbsteintrag (in nur eine Gruppe)') ?>
         </label>
 
-        <label class="col-3">
+        <label class="col-3 self-assign-option">
             <?= _('Selbsteintrag erlaubt ab') ?>
             <input class="size-s" type="text" size="20" name="selfassign_start" id="selfassign_start" value="<?= $group->selfassign_start ?
                 date('d.m.Y H:i', $group->selfassign_start) : '' ?>" data-datetime-picker>
         </label>
 
-        <label class="col-3">
+        <label class="col-3 self-assign-option">
             <?= _('Selbsteintrag erlaubt bis') ?>
             <input class="size-s" type="text" size="20" name="selfassign_end" value="<?= $group->selfassign_end ?
                 date('d.m.Y H:i', $group->selfassign_end) : '' ?>" data-datetime-picker='{">":"#selfassign_start"}'>
diff --git a/resources/assets/javascripts/lib/statusgroups.js b/resources/assets/javascripts/lib/statusgroups.js
index 917396e33de..6c1c5beeafb 100644
--- a/resources/assets/javascripts/lib/statusgroups.js
+++ b/resources/assets/javascripts/lib/statusgroups.js
@@ -38,31 +38,6 @@ const Statusgroups = {
     },
 
     initInputs: function() {
-        //$('input[name="selfassign_start"]').datetimepicker();
-        if (!$('input[name="selfassign"]').attr('checked')) {
-            $('input[name="exclusive"]')
-                .closest($('section'))
-                .hide();
-            $('input[name="selfassign_start"]')
-                .closest($('section'))
-                .hide();
-            $('input[name="selfassign_end"]')
-                .closest($('section'))
-                .hide();
-        }
-        //$('input[name="selfassign_end"]').datetimepicker();
-        $('input[name="selfassign"]').on('click', function() {
-            $('input[name="exclusive"]')
-                .closest($('section'))
-                .toggle();
-            $('input[name="selfassign_start"]')
-                .closest($('section'))
-                .toggle();
-            $('input[name="selfassign_end"]')
-                .closest($('section'))
-                .toggle();
-        });
-
         $('input[name="numbering_type"]').on('click', function() {
             var type = $('input[name="numbering_type"]:checked').val(),
                 disabled = parseInt(type, 10) === 2;
-- 
GitLab