From 26f29497255d3c2097ad66edd672170c5ea27501 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Fri, 18 Oct 2024 08:13:54 +0000
Subject: [PATCH] fix oer search difficulty level filter, fixes #2429

Closes #2429

Merge request studip/studip!3514
---
 app/views/oer/market/_searchform.php    | 14 ++++++-------
 resources/assets/javascripts/lib/oer.js | 27 +++++++++++--------------
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/app/views/oer/market/_searchform.php b/app/views/oer/market/_searchform.php
index 474042b6d09..6ac771f18d8 100644
--- a/app/views/oer/market/_searchform.php
+++ b/app/views/oer/market/_searchform.php
@@ -20,28 +20,28 @@
                 -
                 <span>{{ difficulty[1] }}</span>
                 <a href="#"
-                   @click.prevent="clearDifficulty"
+                   @click.prevent="clearDifficulty()"
                    class="erasefilter"
                    title="<?= _('Filter des Niveaus entfernen') ?>">
-                    <studip-icon shape="decline" role="clickable" :size="16" class="text-bottom"></studip-icon>
+                    <studip-icon shape="decline" class="text-bottom"></studip-icon>
                 </a>
             </span>
 
             <input type="text"
                    name="search"
-                   @focus="showFilterPanel"
-                   @keyup="sync_search_text"
-                   @keydown.enter.prevent="search">
+                   @focus="showFilterPanel()"
+                   @keyup="sync_search_text()"
+                   @keydown.enter.prevent="search()">
 
             <button v-if="difficulty[0] != 1 || difficulty[1] != 12 || (category != null) || (searchtext.length > 0)"
                     class="erase"
                     type="button"
                     title="<?= _('Suchformular zurücksetzen') ?>"
-                    @click="clearAllFilters">
+                    @click="clearAllFilters()">
                 <studip-icon shape="decline" role="clickable"></studip-icon>
             </button>
 
-            <button @click="triggerFilterPanel"
+            <button @click="triggerFilterPanel()"
                     type="button"
                     title="<?= _('Suchfilter einstellen') ?>"
                     :class="activeFilterPanel ? 'active' : ''">
diff --git a/resources/assets/javascripts/lib/oer.js b/resources/assets/javascripts/lib/oer.js
index 17f0186ad11..704d5ba9da7 100644
--- a/resources/assets/javascripts/lib/oer.js
+++ b/resources/assets/javascripts/lib/oer.js
@@ -66,7 +66,7 @@ const OER = {
                     clearAllFilters: function (keep_results) {
                         this.clearCategory();
                         this.clearDifficulty();
-                        if (this.searchtext != '') {
+                        if (this.searchtext.length !== 0) {
                             this.searchtext = '';
                         }
                         $(".oer_search input[name=search]").val('');
@@ -75,10 +75,9 @@ const OER = {
                         }
                     },
                     clearDifficulty: function () {
-                        if ((this.difficulty[0] != 1) && (this.difficulty[1] != 12)) {
-                            this.difficulty = [1, 12];
-                        }
-                        jQuery("#difficulty_slider").slider("values", this.difficulty);
+                        this.difficulty[0] = 1;
+                        this.difficulty[1] = 12;
+                        jQuery('#difficulty_slider').slider('values', this.difficulty);
                     },
                     clearCategory: function () {
                         if (this.category != null) {
@@ -201,7 +200,7 @@ const OER = {
                         }
                     }
                 },
-                mounted: function () {
+                mounted() {
                     this.results = $(this.$el).data('searchresults');
                     if (this.results !== false) {
                         $("#new_ones").hide();
@@ -209,8 +208,14 @@ const OER = {
                     if ($(this.$el).data('filteredcategory')) {
                         this.category = $(this.$el).data('filteredcategory');
                     }
+
+                    document.addEventListener('click', (event) => {
+                        if (event.closest('.searchform') === null) {
+                            this.hideFilterPanel();
+                        }
+                    })
                 },
-                updated: function () {
+                updated() {
                     this.$nextTick(function () {
                         if (!jQuery("#difficulty_slider.ui-slider").length) { //to prevent an endless loop
                             let v = this;
@@ -228,14 +233,6 @@ const OER = {
                 }
             });
         });
-
-
-        jQuery(document).on("click", function (evnt) {
-            if (!jQuery(evnt.target).is(".searchform *") && STUDIP.OER.Search) {
-                STUDIP.OER.Search.hideFilterPanel();
-            }
-        });
-
     }
 };
 
-- 
GitLab