From 6907bf26f57921cebdab55101d0d2fdc7ae39a22 Mon Sep 17 00:00:00 2001 From: MatthieuLP Date: Mon, 24 Jul 2023 15:22:10 +0200 Subject: [PATCH] related to #1931 Added empty all filters button --- language/en_UK/common.lang.php | 1 + language/fr_FR/common.lang.php | 1 + themes/default/js/mcs.js | 26 ++++++++++++++++++++++++++ themes/default/template/index.tpl | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index 3a74c7d43..1be80ca5c 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -428,4 +428,5 @@ $lang['Choose filters'] = 'Choose filters'; $lang['Clear'] = 'Clear'; $lang['Fill in the filters to start a search'] = 'Fill in the filters to start a search'; $lang['Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'] = 'Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'; +$lang['Empty filters'] = 'Empty filters'; ?> diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index 36932156d..0a98b632c 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -433,3 +433,4 @@ $lang['Choose filters'] = 'Choisir les filtres'; $lang['Clear'] = 'Vider'; $lang['Fill in the filters to start a search'] = 'Complétez les filtres pour lancer une recherche'; $lang['Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'] = 'Des filtres préétablis vous sont proposés, mais vous pouvez aussi en ajouter ou en retirer grâce au bouton "Choisir les filtres".'; +$lang['Empty filters'] = 'Vider les filtres'; diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 59e192d72..563d42b65 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -39,6 +39,7 @@ $(document).ready(function () { // Declare params sent to pwg.images.filteredSearch.update PS_params = {}; PS_params.search_id = search_id; + empty_filters_list = []; // Setup word filter if (global_params.fields.allwords) { @@ -80,6 +81,8 @@ $(document).ready(function () { PS_params.allwords = word_search_str.slice(0, -1); PS_params.allwords_fields = word_search_fields; PS_params.allwords_mode = word_search_mode; + + empty_filters_list.push(PS_params.allwords); } //Hide filter spinner $(".filter-spinner").hide(); @@ -115,6 +118,8 @@ $(document).ready(function () { PS_params.tags = global_params.fields.tags.words.length > 0 ? global_params.fields.tags.words : ''; PS_params.tags_mode = global_params.fields.tags.mode; + + empty_filters_list.push(PS_params.tags); } // Setup album filter @@ -148,6 +153,8 @@ $(document).ready(function () { PS_params.categories = global_params.fields.cat.words.length > 0 ? global_params.fields.cat.words : ''; PS_params.categories_withsubs = global_params.fields.cat.sub_inc; + + empty_filters_list.push(PS_params.categories); } // Setup author filter @@ -178,6 +185,8 @@ $(document).ready(function () { }); PS_params.authors = global_params.fields.author.words.length > 0 ? global_params.fields.author.words : ''; + + empty_filters_list.push(PS_params.authors); } }); @@ -208,6 +217,8 @@ $(document).ready(function () { }); PS_params.added_by = global_params.fields.added_by.length > 0 ? global_params.fields.added_by : ''; + + empty_filters_list.push(PS_params.added_by); } }); @@ -239,6 +250,8 @@ $(document).ready(function () { }); PS_params.filetypes = global_params.fields.filetypes.length > 0 ? global_params.fields.filetypes : ''; + + empty_filters_list.push(PS_params.filetypes); } // Adapt no result message @@ -247,6 +260,19 @@ $(document).ready(function () { $(".mcs-no-result .text .bot").html(str_empty_search_bot_alt); } + if (!empty_filters_list.every(param => param === "" || param === null)) { + $(".clear-all").addClass("clickable"); + $(".clear-all.clickable").on('click', function () { + exclude_params = ['search_id', 'allwords_mode', 'allwords_fields', 'tags_mode', 'categories_withsubs']; + for (const key in PS_params) { + if (!exclude_params.includes(key)) { + PS_params[key] = ''; + } + } + performSearch(PS_params, true); + }); + } + /** * Filter Manager */ diff --git a/themes/default/template/index.tpl b/themes/default/template/index.tpl index ae2a16d13..2fcf6bdee 100644 --- a/themes/default/template/index.tpl +++ b/themes/default/template/index.tpl @@ -482,6 +482,10 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can {/if} +
+ {'Empty filters'|@translate} +
+ {*
Note div