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 f1e332e243..51347286e2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -98,6 +98,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 ed1827e45b..debafdd673 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 3e6226e6e5..70fb1f0326 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,7 +9,16 @@ 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: {}, }), getAll: variables => this.httpClient.get({ @@ -17,7 +26,7 @@ export class SysprefAPIClient { }), update: (variable, value) => this.httpClient.post({ - endpoint: "", + endpoint: "/cgi-bin/koha/svc/config/systempreferences", body: "pref_%s=%s".format( encodeURIComponent(variable), encodeURIComponent(value) @@ -29,7 +38,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 ff01036a0c..48fe475f42 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -1162,3 +1162,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); + }; +}