From 3b75bda03d5d6080e9068f31e35cc38dfc1f5f04 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 Feb 2026 14:24:15 +0100 Subject: [PATCH] Bug 41995: Autocomplete for syspref search This patch adds autocompletion to the syspref search in the header. Test plan: 1. Go to the admin home page - /cgi-bin/koha/admin/admin-home.pl 2. In the header start typing the name of a syspref and notice that there is now autocompletion (you need at least 3 chars) 3. Select an entry and confirm that you are correctly redirected to the correct search result --- .../prog/en/includes/js_includes.inc | 10 ++++ .../prog/en/includes/prefs-admin-search.inc | 4 +- .../js/fetch/system-preferences-api-client.js | 17 +++++-- .../intranet-tmpl/prog/js/staff-global.js | 50 +++++++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index 189a2687c9c..999e180aaac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -97,6 +97,16 @@ [% END %] +[% IF ( CAN_user_parameters_manage_sysprefs ) %] + +[% END %] + [% IF Koha.Preference( 'CookieConsent' ) %] [% Asset.js("js/cookieconsent.js") | $raw %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-admin-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-admin-search.inc index ed1827e45b3..debafdd6736 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-admin-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-admin-search.inc @@ -11,11 +11,11 @@
- +
- +
diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/system-preferences-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/system-preferences-api-client.js index 49b2f3212bb..fd19fc01751 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/fetch/system-preferences-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/system-preferences-api-client.js @@ -1,7 +1,7 @@ export class SysprefAPIClient { constructor(HttpClient) { this.httpClient = new HttpClient({ - baseURL: "/cgi-bin/koha/svc/config/systempreferences", + baseURL: "", }); } @@ -9,11 +9,20 @@ export class SysprefAPIClient { return { get: variable => this.httpClient.get({ - endpoint: "/?pref=" + variable, + endpoint: + "/cgi-bin/koha/svc/config/systempreferences/?pref=" + + variable, + }), + getAll: (query, params) => + this.httpClient.getAll({ + endpoint: "/api/v1/sysprefs", + query, + params: { _order_by: "name", ...params }, + headers: {}, }), update: (variable, value) => this.httpClient.post({ - endpoint: "", + endpoint: "/cgi-bin/koha/svc/config/systempreferences", body: "pref_%s=%s".format( encodeURIComponent(variable), encodeURIComponent(value) @@ -25,7 +34,7 @@ export class SysprefAPIClient { }), update_all: sysprefs => this.httpClient.post({ - endpoint: "", + endpoint: "/cgi-bin/koha/svc/config/systempreferences", body: Object.keys(sysprefs) .map(variable => sysprefs[variable].length diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index bfac800c53f..d544cb30d76 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -1094,3 +1094,53 @@ function validatePatronSearch(form) { } return true; } + +function syspref_autocomplete(node) { + const client = APIClient.sysprefs; + node + .autocomplete({ + source: function (request, response) { + let patterns = request.term + .split(/[\s,]+/) + .filter(function (s) { + return s.length; + }); + + var table_prefix = "me"; + let search_fields = ["variable"]; + let term_subquery_or = []; + search_fields.forEach(function (field, i) { + term_subquery_or.push({ + [table_prefix + "." + field]: { + like: "%" + request.term + "%", + }, + }); + }); + let query = [{ "-or": term_subquery_or }]; + + let params = { + _page: 1, + _per_page: 10, + _order_by: "+me.variable", + }; + client.sysprefs.getAll(query, params).then(data => { + return response(data); + }); + }, + minLength: 3, + select: function (event, ui) { + window.location.href = ui.item.link; + }, + focus: function (event, ui) { + event.preventDefault(); // Don't replace the text field + }, + }) + .data("ui-autocomplete")._renderItem = function (ul, item) { + item.link = `/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=${item.variable}`; + item.value = item.variable; // Or we replace the input with the syspref's value when the item is selected + return $("
  • ") + .data("ui-autocomplete-item", item) + .append(`${item.variable}`) + .appendTo(ul); + }; +} -- 2.43.0