From 96979cb4011a2a977eafb70e853f31c1fe89b384 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Wed, 6 Oct 2021 15:59:52 +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:
  - Administration -> Record matching rules.
  - 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.
  - Tools -> Tags.
---
 C4/Output.pm                                  | 54 +++++++------------
 .../prog/css/src/staff-global.scss            | 40 ++------------
 .../prog/en/modules/admin/matching-rules.tt   |  1 -
 .../en/modules/admin/patron-attr-types.tt     |  2 -
 .../modules/authorities/searchresultlist.tt   |  9 +++-
 .../prog/en/modules/cataloguing/addbooks.tt   | 12 ++++-
 .../value_builder/unimarc_field_210c.tt       | 22 ++++----
 .../modules/reports/guided_reports_start.tt   | 10 +++-
 .../prog/en/modules/reviews/reviewswaiting.tt |  6 ++-
 .../prog/en/modules/tags/review.tt            |  6 +--
 .../prog/en/modules/virtualshelves/shelves.tt | 12 ++++-
 11 files changed, 77 insertions(+), 97 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index 09dc73d41d..643f54cc49 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -107,21 +107,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><a class="nav" 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 ?
@@ -129,16 +125,12 @@ sub pagination_bar {
             my $previous = $current_page - 1;
 
             $pagination_bar .=
-                "\n" . '&nbsp;'
-              . '<a href="'
+                "\n" . ''
+              . '<li><a class="nav" 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;
@@ -157,25 +149,25 @@ sub pagination_bar {
                     and $last_displayed_page != $page_number - 1 )
                 {
                     $pagination_bar .=
-                      "\n" . '&nbsp;<span class="inactive">...</span>';
+                      "\n" . '<li><span class="inactive">...</span></li>';
                 }
 
                 if ( $page_number == $current_page ) {
                     $pagination_bar .=
-                        "\n" . '&nbsp;'
-                      . '<span class="currentPage">'
+                        "\n" . ''
+                      . '<li class="active"><span>'
                       . $page_number
-                      . '</span>';
+                      . '</span></li>';
                 }
                 else {
                     $pagination_bar .=
-                        "\n" . '&nbsp;'
-                      . '<a href="'
+                        "\n" . ''
+                      . '<li><a class="nav" href="'
                       . $url
                       . $page_number
                       . $url_suffix
                       . '">'
-                      . $page_number . '</a>';
+                      . $page_number . '</a></li>';
                 }
                 $last_displayed_page = $page_number;
             }
@@ -186,31 +178,25 @@ sub pagination_bar {
             my $next = $current_page + 1;
 
             $pagination_bar .= "\n"
-              . '&nbsp;<a href="'
+              . '<li><a class="nav" 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><a class="nav" 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 5889f41d71..577cb20782 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
@@ -1251,42 +1251,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;
     }
@@ -3206,6 +3170,10 @@ nav {
         }
     }
 
+    &.pages {
+        font-size: 90%;
+    }
+
 
 }
 
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 06983048ec..ff48d9c398 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
@@ -478,7 +478,6 @@
                         <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 3696ad6162..b8127c0eb4 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
@@ -352,8 +352,6 @@ Patron attribute types &rsaquo; Administration &rsaquo; Koha
   <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 3baec6db23..22ca1ff556 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt
@@ -35,7 +35,10 @@
 
 <div id="merge_in_progress"></div>
 [% 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 %]
@@ -86,7 +89,9 @@
   </table>
 </div>
 
-<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 ef8e4fa2c8..4b2e281e2c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt
@@ -93,7 +93,11 @@
                         [% 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>
+
+                    <nav class="pages" id="pagination_top">
+                        [% pagination_bar | $raw %]
+                    </nav>
+
                     <div class="searchresults">
                         <table>
                             <tr>
@@ -180,7 +184,11 @@
                                 </tr>
                             [% END # /FOREACH resultsloo %]
                         </table>
-                        <div class="pages">[% pagination_bar | $raw %]</div>
+
+                        <nav class="pages" id="pagination_bottom">
+                            [% pagination_bar | $raw %]
+                        </nav>
+
                     </div> <!-- /.searchresults -->
                 [% ELSE # IF total %]
                     [% IF ( query ) %]
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 af3b92d7d3..a9f27410c0 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
@@ -16,7 +16,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="EDITORS" />
+            <input type="hidden" name="authtypecode" value="PERSO_NAME" />
             <input type="hidden" name="q" value="[% index | html %]" />
             <input type="hidden" name="marclist" value="all" />
             <input type="hidden" name="and_or" value="and" />
@@ -42,10 +42,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 />
@@ -68,10 +69,10 @@
                         <td>[% resul.summary.label | html %]</td>
                         <td>[% resul.used | html %] times</td>
                         <td>
-                        [% IF ( resul.to_report ) %]
+                        [% #IF ( resul.to_report ) %]
                             <button class="choosebt">Choose</button>
                             <p class="toreport" style="display:none">[% resul.to_report |replace('\n', '\\n') |replace('\r', '\\r') |html %]</p>
-                        [% END %]
+                        [% #END %]
                         </td>
                     </tr>
                 [% END %]
@@ -79,9 +80,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 3b197dd6f8..ec2f888b23 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
@@ -1076,7 +1076,10 @@
                         </select>
                     </form> <!-- /#limitselect -->
 
-                    <div class="pages">[% pagination_bar | $raw %]</div>
+                    <nav class="pages" id="pagination_top">
+                        [% pagination_bar | $raw %]
+                    </nav>
+
                     [% UNLESS ( errors ) %]
                         <table>
                             <tr>
@@ -1093,7 +1096,10 @@
                             [% END %]
                         </table>
                     [% END %]
-                    <div class="pages">[% pagination_bar | $raw %]</div>
+
+                    <nav class="pages" id="pagination_bottom">
+                        [% pagination_bar | $raw %]
+                    </nav>
 
                     [% 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 ef01a2b3c1..c0ec1c06f8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reviews/reviewswaiting.tt
@@ -81,7 +81,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/tags/review.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt
index 31bad4581e..d0337e69a5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt
@@ -80,11 +80,7 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; }
         [% END %]
   </div>
   [% END %]
-  [% IF ( pagination_bar ) %]
-  <div class="pages" id="pagination_top">
-    [% pagination_bar | $raw %]
-  </div>
-  [% END %]
+
   [% IF ( tagloop ) %]
   <p class="check"></p>
   <table id="tagst">
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 b2f12a4b4e..19064aaeda 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
@@ -186,7 +186,11 @@
     [% IF itemsloop %]
 
     <h3>Contents of <em>[% shelf.shelfname | html %]</em></h3>
-    <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">
         <input type="hidden" name="op" value="remove_biblios" />
         <input type="hidden" name="referer" value="view" />
@@ -307,7 +311,11 @@
 			</tr>
 		[% END %]<!-- /itemsloop -->
     </table>
-    <div class="pages">[% pagination_bar | $raw %]</div>
+
+    <nav class="pages" id="pagination_bottom">
+        [% pagination_bar | $raw %]
+    </nav>
+
 </form>
 
 	[% END %]
-- 
2.20.1