From 7fdc5000ab61ab7ac07e308553b30137fe9862a9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Dec 2021 17:00:50 +0100 Subject: [PATCH] Bug 29695: Make "modalselect" syspref's values translatable We are using json files to retrieve the list of the DB columns. We can reuse what we have done in the previous patch and display translated strings. Test plan: Search for "unwanted" in the sysprefs Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi --- admin/preferences.pl | 6 +- .../prog/en/modules/admin/preferences.tt | 1 + .../prog/js/pages/preferences.js | 60 +++++++++---------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/admin/preferences.pl b/admin/preferences.pl index b6d753b890..45a5891c62 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -28,6 +28,7 @@ use C4::ClassSource qw( GetClassSources GetClassSource ); use C4::Output qw( output_html_with_http_headers ); use C4::Templates; use Koha::Acquisition::Currencies; +use Koha::Database::Columns; use IO::File; use YAML::XS; use Encode; @@ -401,6 +402,9 @@ if ( $tab ) { ); } -$template->param( TABS => \@TABS ); +$template->param( + TABS => \@TABS, + db_columns => Koha::Database::Columns->columns, +); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index c9def9f39c..36e8eb0f81 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -282,6 +282,7 @@ // This is here because of its dependence on template variables, everything else should go in js/pages/preferences.js - jpw var to_highlight = "[% To.json( searchfield ) | html %]"; var search_jumped = [% IF ( search_jumped ) %]true[% ELSE %]false[% END %]; + var db_columns = [% To.json( db_columns ) | $raw %]; [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/ajax.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index b60fbe57c2..fb63d4b397 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -231,38 +231,36 @@ $( document ).ready( function () { var pref_value = this.value; var prefs = pref_value.split("|"); - - - $.getJSON( themelang + "/modules/admin/preferences/" + datasource + ".json", function( data ){ - var items = []; - var checked = ""; - var readonly = ""; - var disabled = ""; - var style = ""; - $.each( data, function( key, val ){ - if( prefs.indexOf( val ) >= 0 ){ - checked = ' checked="checked" '; - } else { - checked = ""; - } - if( required.indexOf( val ) >= 0 ){ - style = "required"; - checked = ' checked="checked" '; - } else if( exclusions.indexOf( val ) >= 0 ){ - style = "disabled"; - disabled = ' disabled="disabled" '; - checked = ""; - } else { - style = ""; - disabled = ""; - } - items.push(''); - }); - $("
", { - "class": "columns-2", - html: items.join("") - }).appendTo("#prefModalForm"); + let data = db_columns[datasource]; + var items = []; + var checked = ""; + var readonly = ""; + var disabled = ""; + var style = ""; + $.each( Object.keys(data).sort(), function( i, key ){ + if( prefs.indexOf( key ) >= 0 ){ + checked = ' checked="checked" '; + } else { + checked = ""; + } + if( required.indexOf( key ) >= 0 ){ + style = "required"; + checked = ' checked="checked" '; + } else if( exclusions.indexOf( key ) >= 0 ){ + style = "disabled"; + disabled = ' disabled="disabled" '; + checked = ""; + } else { + style = ""; + disabled = ""; + } + items.push(''); }); + $("
", { + "class": "columns-2", + html: items.join("") + }).appendTo("#prefModalForm"); + $("#saveModalPrefs").data("target", this.id ); $("#prefModalLabel").text( pref_name ); $("#prefModal").modal("show"); -- 2.32.0