From 7625232114d068421c233978d7fb95b90a75b7e8 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 2 Jul 2020 12:50:17 +0000 Subject: [PATCH] Bug 25909: Recent change to datatables JS in the OPAC causes errors This patch reverts some changes made by Bug 25287 which prematurely introduced the double-underscore i18n function. The i18n features haven't been fully implemented in the OPAC. Some lines are reverts to the previous version, and some are additions, for instance where Bug 25287 introduced new DataTables features and a new string translation is required. In addition to i18n changes, the patch also reverts the default configuration of DataTables in the OPAC so that the "dom" configuration option is set back to "t." This turns off features like pagination buttons, filters, etc. which were previously disabled by default. Enabling these features requires revision to the OPAC CSS in order for them to display well. To test, apply the patch and view a page in the OPAC which includes a DataTable. For instance: checkouts on the "your summary" page, serial issues on the "full subscription history" page. Tables should display correctly and sorting should work correctly. There should be no other DataTables controls visible. To test translatability: To test, apply the patch and test that the correct strings are translatable. In this example I'm testing fr-FR: - Update a translation: > cd misc/translator > perl translate update fr-FR - Open the corresponding .po file for the strings pulled from the templates e.g. misc/translator/po/fr-FR-opac-bootstrap.po - Locate strings pulled from bootstrap/en/includes/datatables.inc for translation, e.g.: #. SCRIPT #: opac-tmpl/bootstrap/en/includes/datatables.inc:4 msgid "Copy to clipboard" msgstr "" - Edit the "msgstr" string however you want (it's just for testing) - Install the updated translation: > perl translate install fr-FR Open the translated copy of datatables.inc and confirm that the translated string appears. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize https://bugs.koha-community.org/show_bug.cgi?id=25630 --- .../opac-tmpl/bootstrap/en/includes/datatables.inc | 8 +++- koha-tmpl/opac-tmpl/bootstrap/js/datatables.js | 48 +++++++++++----------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/datatables.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/datatables.inc index d711ee5bfa..c8f18ec072 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/datatables.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/datatables.inc @@ -2,7 +2,6 @@ [% USE Asset %] [% Asset.js("lib/jquery/plugins/jquery.dataTables.min.js") | $raw %] [% Asset.js("js/datatables.js") | $raw %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js index 19f2944dde..bc51357529 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -5,38 +5,38 @@ // // other settings // } ) ); var dataTablesDefaults = { - "oLanguage": { - "oPaginate": { - "sFirst" : __('First'), - "sLast" : __('Last'), - "sNext" : __('Next'), - "sPrevious" : __('Previous'), + "language": { + "paginate": { + "first" : window.MSG_DT_FIRST || "First", + "last" : window.MSG_DT_LAST || "Last", + "next" : window.MSG_DT_NEXT || "Next", + "previous" : window.MSG_DT_PREVIOUS || "Previous" }, - "sEmptyTable" : __('No data available in table'), - "sInfo" : __('Showing _START_ to _END_ of _TOTAL_ entries'), - "sInfoEmpty" : __('No entries to show'), - "sInfoFiltered" : __('(filtered from _MAX_ total entries)'), - "sLengthMenu" : __('Show _MENU_ entries'), - "sLoadingRecords" : __('Loading...'), - "sProcessing" : __('Processing...'), - "sSearch" : __('Search:'), - "sZeroRecords" : __('No matching records found'), + "emptyTable" : window.MSG_DT_EMPTY_TABLE || "No data available in table", + "info" : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries", + "infoEmpty" : window.MSG_DT_INFO_EMPTY || "No entries to show", + "infoFiltered" : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)", + "lengthMenu" : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries", + "loadingRecords" : window.MSG_DT_LOADING_RECORDS || "Loading...", + "processing" : window.MSG_DT_PROCESSING || "Processing...", + "search" : window.MSG_DT_SEARCH || "Search:", + "zeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found", buttons: { - "copyTitle" : __('Copy to clipboard'), - "copyKeys" : __('Press ctrl or + C to copy the table data
to your system clipboard.

To cancel, click this message or press escape.'), + "copyTitle" : window.MSG_DT_COPY_TO_CLIPBOARD || "Copy to clipboard", + "copyKeys" : window.MSG_DT_COPY_KEYS || "Press ctrl or + C to copy the table data
to your system clipboard.

To cancel, click this message or press escape.", "copySuccess": { - _: __('Copied %d rows to clipboard'), - 1: __('Copied one row to clipboard'), + _: window.MSG_DT_COPIED_ROWS || "Copied %d rows to clipboard", + 1: window.MSG_DT_COPIED_ONE_ROW || "Copied one row to clipboard", } } }, - "dom": '<"top pager"<"table_entries"ilp><"table_controls"fB>>tr<"bottom pager"ip>', + "dom": 't', "buttons": [{ fade: 100, className: "dt_button_clear_filter", - titleAttr: __('Clear filter'), + titleAttr: window.MSG_CLEAR_FILTER, enabled: false, - text: ' ' + __('Clear filter') + '', + text: ' ' + window.MSG_CLEAR_FILTER + '', available: function ( dt ) { // The "clear filter" button is made available if this test returns true if( dt.settings()[0].aanFeatures.f ){ // aanFeatures.f is null if there is no search form @@ -48,7 +48,7 @@ var dataTablesDefaults = { node.addClass("disabled"); } }], - "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, __('All')]], + "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All" ]], "iDisplayLength": 20, initComplete: function( settings) { var tableId = settings.nTable.id @@ -355,7 +355,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { * from a configuration file (in English, "a," "an," and "the") */ - var config_exclude_articles_from_sort = __('a an the'); + var config_exclude_articles_from_sort = window.CONFIG_EXCLUDE_ARTICLES_FROM_SORT || "a an the"; if (config_exclude_articles_from_sort){ var articles = config_exclude_articles_from_sort.split(" "); var rpattern = ""; -- 2.11.0