From af83dc35a82a385bf7e56449d09c261782e47571 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Fri, 14 Jun 2024 18:06:15 +0000
Subject: [PATCH] Bug 28453: Update pagination subroutine to generate Bootstrap
 markup

This patch modifies Output.pm to change the HTML it generates when
creating pagination bars. The changes allow the pagination menu to be
styled like Bootstrap pagination, making them consistent with the
pagination on catalog search results.

To test, apply the patch and rebuild the staff interface CSS
(https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client).

 - Test pages where the pagination_bar subroutine is called:
 - Authorities -> Authority search results.
 - Cataloging -> Cataloging search results.
 - Cataloging -> MARC Editor -> Edit tag which is configured to use the
   unimarc_field_210c value builder.
 - Reports -> Saved SQL reports -> Results.
 - Tools -> Comments.
 - Lists -> List contents.

The pagination bar markup was removed from the templates for these pages
because it wasn't being used:

 - Administration -> Patron attribute types.
 - Administration -> Record matching rules.
 - Tools -> Tags.

Sponsored-by: Athens County Public Libraries
Signed-off-by: David Nind <david@davidnind.com>
---
 C4/Output.pm                                  | 54 +++++++------------
 .../prog/css/src/staff-global.scss            | 36 -------------
 .../prog/en/modules/admin/matching-rules.tt   |  2 -
 .../en/modules/admin/patron-attr-types.tt     |  2 -
 .../modules/authorities/searchresultlist.tt   |  8 ++-
 .../prog/en/modules/cataloguing/addbooks.tt   | 16 +++---
 .../value_builder/unimarc_field_210c.tt       | 18 ++++---
 .../modules/reports/guided_reports_start.tt   |  8 +--
 .../prog/en/modules/reviews/reviewswaiting.tt |  6 ++-
 .../prog/en/modules/virtualshelves/shelves.tt | 10 +++-
 10 files changed, 64 insertions(+), 96 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index d8ea0bfb52..90fbad510b 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -110,21 +110,17 @@ sub pagination_bar {
 
     # navigation bar useful only if more than one page to display !
     if ( $nb_pages > 1 ) {
-
+        $pagination_bar = '<ul class="pagination">';
         # link to first page?
         if ( $current_page > 1 ) {
             $pagination_bar .=
-                "\n" . '&nbsp;'
-              . '<a href="'
+                "\n" . ''
+              . '<li class="page-item"><a class="page-link output first" href="'
               . $url
               . '1'
               . $url_suffix
               . '"rel="start">'
-              . '&lt;&lt;' . '</a>';
-        }
-        else {
-            $pagination_bar .=
-              "\n" . '&nbsp;<span class="inactive">&lt;&lt;</span>';
+              . '<i class="fa fa-fw fa-angle-double-left"></i> First' . '</a></li>';
         }
 
         # link on previous page ?
@@ -132,16 +128,12 @@ sub pagination_bar {
             my $previous = $current_page - 1;
 
             $pagination_bar .=
-                "\n" . '&nbsp;'
-              . '<a href="'
+                "\n" . ''
+              . '<li class="page-item"><a class="page-link output previous" href="'
               . $url
               . $previous
               . $url_suffix
-              . '" rel="prev">' . '&lt;' . '</a>';
-        }
-        else {
-            $pagination_bar .=
-              "\n" . '&nbsp;<span class="inactive">&lt;</span>';
+              . '" rel="prev">' . '<i class="fa fa-fw fa-angle-left"></i> Previous' . '</a></li>';
         }
 
         my $min_to_display      = $current_page - $pages_around;
@@ -160,25 +152,25 @@ sub pagination_bar {
                     and $last_displayed_page != $page_number - 1 )
                 {
                     $pagination_bar .=
-                      "\n" . '&nbsp;<span class="inactive">...</span>';
+                      "\n" . '<li class="page-item disabled"><a class="page-link">...</a></li>';
                 }
 
                 if ( $page_number == $current_page ) {
                     $pagination_bar .=
-                        "\n" . '&nbsp;'
-                      . '<span class="currentPage">'
+                        "\n" . ''
+                      . '<li class="page-item active" aria-current="page"><a class="page-link" href="#">'
                       . $page_number
-                      . '</span>';
+                      . '</a></li>';
                 }
                 else {
                     $pagination_bar .=
-                        "\n" . '&nbsp;'
-                      . '<a href="'
+                        "\n" . ''
+                      . '<li class="page-item"><a class="page-link" href="'
                       . $url
                       . $page_number
                       . $url_suffix
                       . '">'
-                      . $page_number . '</a>';
+                      . $page_number . '</a></li>';
                 }
                 $last_displayed_page = $page_number;
             }
@@ -189,31 +181,25 @@ sub pagination_bar {
             my $next = $current_page + 1;
 
             $pagination_bar .= "\n"
-              . '&nbsp;<a href="'
+              . '<li class="page-item"><a class="page-link output next" href="'
               . $url
               . $next
               . $url_suffix
-              . '" rel="next">' . '&gt;' . '</a>';
-        }
-        else {
-            $pagination_bar .=
-              "\n" . '&nbsp;<span class="inactive">&gt;</span>';
+              . '" rel="next">' . 'Next <i class="fa fa-fw fa-angle-right"></i>' . '</a></li>';
         }
 
         # link to last page?
         if ( $current_page != $nb_pages ) {
             $pagination_bar .= "\n"
-              . '&nbsp;<a href="'
+              . '<li class="page-item"><a class="page-link output last" href="'
               . $url
               . $nb_pages
               . $url_suffix
               . '" rel="last">'
-              . '&gt;&gt;' . '</a>';
-        }
-        else {
-            $pagination_bar .=
-              "\n" . '&nbsp;<span class="inactive">&gt;&gt;</span>';
+              . 'Last <i class="fa fa-fw fa-angle-double-right"></i>' . '</a></li>';
         }
+
+        $pagination_bar .= "\n" . '</ul>';
     }
 
     return $pagination_bar;
diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
index b43fe29c30..c92b6eb94f 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
@@ -676,42 +676,6 @@ div {
         }
     }
 
-    &.pages {
-        margin: .5em 0;
-
-        a {
-            font-weight: bold;
-            padding: 1px 5px;
-            text-decoration: none;
-
-            &:link,
-            &:visited {
-                background-color: #EEEEEE;
-                color: #3366CC;
-            }
-
-            &:hover,
-            &:active {
-                background-color: #FFC;
-            }
-        }
-
-        .current,
-        .currentPage {
-            background-color: #E6FCB7;
-            color: #666;
-            font-weight: bold;
-            padding: 1px 5px;
-        }
-
-        .inactive {
-            background-color: #F3F3F3;
-            color: #BCBCBC;
-            font-weight: bold;
-            padding: 1px 5px;
-        }
-    }
-
     .browse {
         margin: .5em 0;
     }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt
index 0de0a22dc8..b838870e01 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt
@@ -482,8 +482,6 @@
                     [% ELSE %]
                         <p>There are no saved matching rules.</p>
                     [% END # /IF ( available_matching_rules ) %]
-
-                    <div class="pages">[% pagination_bar | $raw %]</div>
                 [% END # /IF ( display_list ) %]
 
                 [% IF ( matching_rule_form ) %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
index 5e846dc3e4..ecc7408d16 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
@@ -390,8 +390,6 @@
   <p>There are no saved patron attribute types.</p>
 [% END %]
 
-<div class="pages">[% pagination_bar | $raw %]</div>
-
 [% END %]
 
             </main>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
index 2461371da0..f430630bff 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
@@ -54,7 +54,9 @@
     [% END %]
 
     [% IF ( total ) %]
-    <div class="pages">[% pagination_bar | $raw %]</div>
+    <nav class="pages" id="pagination_top">
+        [% pagination_bar | $raw %]
+    </nav>
 
     <p id="authorities_searchresultlist_current_page_info">
       Results [% from | html %] to [% to | html %] of [% total | html %]
@@ -141,7 +143,9 @@
 
     [% INCLUDE 'authority-detail-modal.inc' %]
 
-    <div class="pages">[% pagination_bar | $raw %]</div>
+    <nav class="pages" id="pagination_bottom">
+        [% pagination_bar | $raw %]
+    </nav>
 
     [% ELSE %]
       No results found
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
index 9e4b2c6fb3..092a0e6b6c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
@@ -94,11 +94,13 @@
                 [% IF ( total ) %]
                     <h2>Records found in the catalog</h2>
                     <div class="page-section">
-                    <div>
-                        [% total | html %] result(s) found in catalog,
-                        <a href="#searchresult-breeding">[% breeding_count | html %] result(s) found in reservoir</a>
-                    </div>
-                    <div class="pages">[% pagination_bar | $raw %]</div>
+                        <div>
+                            [% total | html %] result(s) found in catalog,
+                            <a href="#searchresult-breeding">[% breeding_count | html %] result(s) found in reservoir</a>
+                        </div>
+                        <nav class="pages" id="pagination_top">
+                            [% pagination_bar | $raw %]
+                        </nav>
                         <div class="searchresults">
                             <table>
                                 <tr>
@@ -186,7 +188,9 @@
                                     </tr>
                                 [% END # /FOREACH resultsloo %]
                             </table>
-                            <div class="pages">[% pagination_bar | $raw %]</div>
+                            <nav class="pages" id="pagination_bottom">
+                                [% pagination_bar | $raw %]
+                            </nav>
                         </div> <!-- /.searchresults -->
                     </div> <!-- /.page-section -->
                 [% ELSE # IF total %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt
index f1b9cd0eda..f578b2fa36 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_210c.tt
@@ -22,7 +22,7 @@
             <input type="hidden" name="type" value="intranet" />
             <input type="hidden" name="nbstatements" value="[% nbstatements | html %]" />
             <input type="hidden" name="index" value="[% index | html %]" />
-            <input type="hidden" name="authtypecode" value="PERSO_NAME" />
+            <input type="hidden" name="authtypecode" value="EDITORS" />
             <input type="hidden" name="q" value="[% index | html %]" />
             <input type="hidden" name="marclist" value="all" />
             <input type="hidden" name="and_or" value="and" />
@@ -48,10 +48,11 @@
                 </fieldset>
         </form>
             [% IF ( total ) %]
-            <h3>Authority search results</h3>
-            <div class="pages">
-                          [% pagination_bar | $raw %]
-                        </div>[% END %]
+                <h3>Authority search results</h3>
+                <nav class="pages" id="pagination_top">
+                    [% pagination_bar | $raw %]
+                </nav>
+            [% END %]
             <p>
                 [% IF ( total ) %]
                     &nbsp;<strong>Results [% from | html %] to [% to | html %] of [% total | html %]</strong><br /><br />
@@ -85,9 +86,10 @@
         </div>
 [% END %]
 
-            [% IF ( total ) %]<div class="pages">
-                          [% pagination_bar | $raw %]
-                        </div>
+            [% IF ( total ) %]
+                <nav class="pages" id="pagination_bottom">
+                    [% pagination_bar | $raw %]
+                </nav>
             [% END %]
 
 <!-- Authority details modal -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
index 6bf5cc03b4..d70b181812 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
@@ -1154,9 +1154,9 @@
                                     </div> <!-- /#toolbar.btn-toolbar -->
                                 [% END # /IF batch operations || ( unlimited_total > 10 && limit <= 1000 ) %]
 
-                                <div class="pages">
+                                <nav id="pagination_top" class="pages">
                                     [% pagination_bar | $raw %]
-                                </div>
+                                </nav>
 
                             [% END # UNLESS ( errors ) %]
                         [% END # IF ( execute ) %]
@@ -1236,7 +1236,9 @@
                                 </tbody>
                             </table>
                         [% END %]
-                        <div class="pages">[% pagination_bar | $raw %]</div>
+                        <nav class="pages" id="pagination_bottom">
+                            [% pagination_bar | $raw %]
+                        </nav>
                     </div>
                     [% INCLUDE 'chart.inc' %]
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
index 1a2ea563fc..a8627aefd1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
@@ -122,7 +122,11 @@
     </tr>
     [% END %]</tbody>
 </table>
- <div class="pages">[% pagination_bar | $raw %]</div>
+
+    <nav class="pages" id="pagination_bottom">
+        [% pagination_bar | $raw %]
+    </nav>
+
 [% ELSE %]
 [% IF ( status ) %]<p><strong>No comments have been approved.</strong></p>[% ELSE %]<p><strong>No comments to moderate.</strong></p>[% END %]
 [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
index 926afb5c1f..e23a28855f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
@@ -242,7 +242,11 @@
                 [% IF itemsloop %]
                     [% SET contents = shelf.get_contents %]
                     [% IF ( contents.count ) %]<p>This list contains [% contents.count | html %] titles</p>[% END %]
-                    <div class="pages">[% pagination_bar | $raw %]</div>
+
+                    <nav class="pages" id="pagination_top">
+                        [% pagination_bar | $raw %]
+                    </nav>
+
                     <form action="/cgi-bin/koha/virtualshelves/shelves.pl" id="listform" method="post">
                         [% INCLUDE 'csrf-token.inc' %]
                         <input type="hidden" name="op" value="cud-remove_biblios" />
@@ -388,7 +392,9 @@
                             </table> <!-- /#searchresults -->
                         </div> <!-- /.page-section -->
 
-                        <div class="pages">[% pagination_bar | $raw %]</div>
+                        <nav class="pages" id="pagination_bottom">
+                            [% pagination_bar | $raw %]
+                        </nav>
                     </form>
                 [% END # /IF itemsloop %]
             [% END # /IF op == 'view' %]
-- 
2.39.5