From fac4e695fcc3678f9b036cf0ef2740ad66c48b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Mon, 24 Mar 2025 21:36:25 +0100 Subject: [PATCH] Javascript based search system (using json to be dynamic) --- static/search.js | 72 ++++++++++++++++++++++ views/people.html | 148 +++++++++++++++++++++------------------------- 2 files changed, 138 insertions(+), 82 deletions(-) create mode 100644 static/search.js diff --git a/static/search.js b/static/search.js new file mode 100644 index 0000000..a6ec53b --- /dev/null +++ b/static/search.js @@ -0,0 +1,72 @@ +$(document).ready(function() { + $("#search").on("click", function() { + search(); + }); + + $("#advanced").on("click", function() { + if ($(this).data("state") === "true") { + $(this).find("i").removeClass("bi-chevron-double-up"); + $(this).find("i").addClass("bi-chevron-double-down"); + $("#advanced-section").addClass("d-none"); + $(this).data("state", "false"); + } else { + $(this).find("i").removeClass("bi-chevron-double-down"); + $(this).find("i").addClass("bi-chevron-double-up"); + $("#advanced-section").removeClass("d-none"); + $(this).data("state", "true"); + } + }); + + var json = $("#search-json").val(); + if (json.length > 0) { + var searchData = JSON.parse(json); + for (const [key, value] of Object.entries(searchData)) { + if (key === "advanced") { + if (value) { + $("#advanced").trigger("click"); + } + + continue; + } + + if (key === "fields") { + // TODO: gérer les champs suppl. + continue + } + + if (typeof value === "boolean" && value) { + console.log(key, value, typeof(value)); + $("[data-search-field=" + key + "]").prop("checked", true); + } else { + $("[data-search-field=" + key + "]").val(value); + } + } + } +}); + +function search() { + var advancedSearch = ($("#advanced").data("state") === "true"); + var searchData = { + advanced: advancedSearch + }; + + $("[data-search-field]").each(function() { + var advancedField = $(this).data("search-advanced"); + if (!advancedSearch && advancedField) { + return; + } + + var index = $(this).data("search-field"); + var value = $(this).val(); + + if ($(this).attr("type") == "checkbox") { + value = $(this).prop("checked"); + } + + searchData[index] = value; + }); + + var json = JSON.stringify(searchData); + $("#search-json").val(json); + $("#search-form").submit(); +} \ No newline at end of file diff --git a/views/people.html b/views/people.html index 6d1479f..bea48f5 100644 --- a/views/people.html +++ b/views/people.html @@ -44,20 +44,24 @@ {% endif %} -
-
+
+
+ + + + +
+
- {% if PermShow %} - - {% endif %} - - {% if PermShowArchived %} - - {% endif %} - - -
-
- - - - -
-
- - - +
+ + +
-
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+
+ +
-
+ - +
@@ -249,42 +270,5 @@ {% endblock %} {% block javascript %} - + {% endblock %} \ No newline at end of file