Bug 25909: Recent change to datatables JS in the OPAC causes errors
authorOwen Leonard <oleonard@myacpl.org>
Thu, 2 Jul 2020 12:50:17 +0000 (12:50 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 16 Jul 2020 14:33:29 +0000 (15:33 +0100)
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 <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/opac-tmpl/bootstrap/en/includes/datatables.inc
koha-tmpl/opac-tmpl/bootstrap/js/datatables.js

index d711ee5..c8f18ec 100644 (file)
@@ -2,7 +2,6 @@
 [% USE Asset %]
 [% Asset.js("lib/jquery/plugins/jquery.dataTables.min.js") | $raw %]
 <script>
-//<![CDATA[
     var MSG_DT_FIRST = _("First");
     var MSG_DT_LAST = _("Last");
     var MSG_DT_NEXT = _("Next");
     var MSG_DT_PROCESSING = _("Processing...");
     var MSG_DT_SEARCH = _("Search:");
     var MSG_DT_ZERO_RECORDS = _("No matching records found");
+    var MSG_DT_COPY_TO_CLIPBOARD = _("Copy to clipboard");
+    var MSG_DT_COPY_KEYS = _("Press <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>To cancel, click this message or press escape.");
+    var MSG_DT_COPIED_ROWS = _("Copied %d rows to clipboard");
+    var MSG_DT_COPIED_ONE_ROW = _("Copied one row to clipboard");
+    var MSG_CLEAR_FILTER = _("Clear filter");
+    var MSG_DT_ALL = _("All");
     var CONFIG_EXCLUDE_ARTICLES_FROM_SORT = _("a an the");
-//]]>
 </script>
 [% Asset.js("js/datatables.js") | $raw %]
index 19f2944..bc51357 100644 (file)
@@ -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 <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>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 <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>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: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __('Clear filter') + '</span>',
+        text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + window.MSG_CLEAR_FILTER + '</span>',
         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 = "";