From 68f87480012f46e2ddcb9656a390b80beb35a78c Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Fri, 21 Feb 2020 15:43:06 +0100
Subject: [PATCH] Bug 24706: Fix ergonomic issue on the list view if empty

If the list is empty, the toolbar does not render correctly.
Buttons are displayed instead of links, also the "Sort" is displayed
when it should not

Test plan:
- Create a new list, do not add items
- Notice that the toolbar now renders correctly
- Use the different link to create/edit/delete
- Confirm that the sort link is not displayed
- Add a new item
- Confirm that the toolbar is looking the same as before
---
 .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 26 ++++++++++++----------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
index ebaa86e27d..0b6a904bae 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
@@ -176,7 +176,7 @@
                                         <form method="get" action="/cgi-bin/koha/opac-shelves.pl" class="form-inline">
                                             <input type="hidden" name="op" value="edit_form" />
                                             <input type="hidden" name="referer" value="view" />
-                                            <input type='hidden' name='category' value='[% category | html %]' />
+                                            <input type='hidden' name='category' value='[% shelf.category | html %]' />
                                             <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
                                             <button type="submit" class="btn btn-link editshelf"><i class="fa fa-fw fa-pencil-square-o"></i> Edit list</button>
                                         </form>
@@ -184,7 +184,7 @@
                                         <form method="post" action="/cgi-bin/koha/opac-shelves.pl" class="form-inline">
                                             <input type="hidden" name="op" value="delete" />
                                             <input type="hidden" name="referer" value="list" />
-                                            <input type='hidden' name='category' value='[% category | html %]' />
+                                            <input type='hidden' name='category' value='[% shelf.category | html %]' />
                                             <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
                                             <button type="submit" class="btn btn-link remove deleteshelf" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST);"><i class="fa fa-fw fa-remove"></i> Delete list</button>
                                         </form>
@@ -481,22 +481,22 @@
                         [% ELSE %]
                             <div id="toolbar" class="toolbar clearfix">
                                 <div class="list-actions">
-                                    <a class="newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form">New list</a> <span class="sep"></span>
+                                    <a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-fw fa-plus"></i> New list</a>
                                     [% IF can_manage_shelf %]
                                         <span class="sep">|</span>
                                         <form method="get" action="/cgi-bin/koha/opac-shelves.pl" class="form-inline">
                                             <input type="hidden" name="op" value="edit_form" />
                                             <input type="hidden" name="referer" value="view" />
-                                            <input type="hidden" name="category" value="category" />
+                                            <input type="hidden" name="category" value="[% shelf.category | html %]" />
                                             <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
-                                            <input type="submit" class="editshelf" value="Edit list" />
+                                            <button type="submit" class="btn btn-link editshelf"><i class="fa fa-fw fa-pencil-square-o"></i> Edit list</button>
                                         </form>
 
                                         <form method="post" action="/cgi-bin/koha/opac-shelves.pl" class="form-inline">
                                             <input type="hidden" name="op" value="delete" />
-                                            <input type="hidden" name="shelfnumber" value="[% shelfnumber | html %]"/>
-                                            <input type="hidden" name="category" value="category" />
-                                            <input type="submit" class="deleteshelf" value="Delete list" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST);"/>
+                                            <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]"/>
+                                            <input type="hidden" name="category" value="[% shelf.category | html %]" />
+                                            <button type="submit" class="btn btn-link remove deleteshelf" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST);"><i class="fa fa-fw fa-remove"></i> Delete list</button>
                                         </form>
                                     [% END %]
                                 </div> <!-- / .list-actions -->
@@ -945,11 +945,13 @@ $(function() {
         stickyClass: "floating"
     });
 
-    sortMenu( $("#sorting-form") );
+    [% IF itemsloop %]
+        sortMenu( $("#sorting-form") );
 
-    $("#sortfield").on("change", function(){
-        $('#sorting-form').submit();
-    });
+        $("#sortfield").on("change", function(){
+            $('#sorting-form').submit();
+        });
+    [% END %]
 
 }); // document.ready
 
-- 
2.11.0