From 81680bb62775b4409ef03bf53bee5f895ffceda6 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Tue, 5 Oct 2021 15:18:15 +0000
Subject: [PATCH] BIESt #159: Raumsuche verwendet falsche HTTP-Semantik

---
 .../assets/javascripts/bootstrap/resources.js | 47 +++++++++++++++++++
 templates/sidebar/room-search-widget.php      | 15 +-----
 2 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/resources/assets/javascripts/bootstrap/resources.js b/resources/assets/javascripts/bootstrap/resources.js
index 9ceb8fa3908..2dc0302ed4e 100644
--- a/resources/assets/javascripts/bootstrap/resources.js
+++ b/resources/assets/javascripts/bootstrap/resources.js
@@ -81,6 +81,53 @@ STUDIP.ready(function () {
         }
     }
 
+    //Room search widget: remove empty form inputs from URL:
+    jQuery('.sidebar-widget-content form.room-search-form').submit(function() {
+        //Check if the seats checkbox is checked. Only include "its" input
+        //fields when it is checked.
+        let seats_checked = jQuery(this).find('input[name="special__seats_enabled"]').is(':checked');
+        if (seats_checked) {
+        } else {
+            jQuery(this).find('input[name="special__seats_min"]').attr('disabled', 'disabled');
+            jQuery(this).find('input[name="special__seats_max"]').attr('disabled', 'disabled');
+        }
+
+        //Check if the time range checkbox is checked. Only include "its" input
+        //fields when it is checked.
+        let time_range_checked = jQuery('#cb_special__time_range').is(':checked');
+        if (time_range_checked) {
+            var dow_select = jQuery(this).find('select[name="special__time_range_day_of_week"]')[0];
+            if (dow_select) {
+                if (!jQuery(dow_select).val() || (jQuery(dow_select).val() < 1)) {
+                    jQuery(dow_select).attr('disabled', 'disabled');
+                }
+            }
+        } else {
+            jQuery(this).find('select[name="special__time_range_semester_id"]').attr('disabled', 'disabled');
+            jQuery('#special__time_range_begin_date').attr('disabled', 'disabled');
+            jQuery('#special__time_range_begin_time').attr('disabled', 'disabled');
+            jQuery('#special__time_range_end_date').attr('disabled', 'disabled');
+            jQuery('#special__time_range_end_time').attr('disabled', 'disabled');
+            jQuery(this).find('select[name="special__time_range_day_of_week"]').attr('disabled', 'disabled');
+        }
+
+        //Disable all form input fields that don't have a value:
+        jQuery(this).find(':input').filter(
+            function(){
+                //A list of allowed input fields without values
+                //(submit buttons):
+                let empty_inputs = ['room_search', 'room_search_reset'];
+                if (jQuery.inArray(jQuery(this).prop('name'), empty_inputs) >= 0) {
+                    return false;
+                }
+                return !this.value;
+            }
+        ).attr('disabled', 'disabled');
+
+        //The form shall still be submitted.
+        return true;
+    });
+
     //other:
 
     jQuery(document).on(
diff --git a/templates/sidebar/room-search-widget.php b/templates/sidebar/room-search-widget.php
index 317671ac344..8ed29204972 100644
--- a/templates/sidebar/room-search-widget.php
+++ b/templates/sidebar/room-search-widget.php
@@ -1,6 +1,5 @@
 <form class="default room-search-form" action="<?= $action_link ?>"
-      method="post">
-    <input type="hidden" name="extended_search">
+      method="get">
 
     <ul class="criteria-list">
         <?= $this->render_partial(
@@ -125,15 +124,3 @@
         </select>
     </label>
 </form>
-<script type="text/javascript">
-/*  jQuery('.room-search-form .criteria-list input[type="date"]').datepicker(
-     {
-         dateFormat: 'yy-mm-dd'
-     }
- );
- jQuery('.room-search-form .criteria-list input[type="time"]').timepicker(
-     {
-         timeFormat: 'G:i'
-     }
- ); */
-</script>
-- 
GitLab