From f0268c9e1b0610becf73ff256a5e02a1ced40ffb Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 28 Oct 2019 16:02:35 +0000 Subject: [PATCH] Bug 23913: Use a single menu to sort lists in the OPAC This patch modifies the sorting form on the OPAC list contents view so that the two menus (sort field and direction) are combined into one. This makes it consistent with the sort menu on the search results page. To test, apply the patch and view a list with multiple titles on it. Test the "Sort by" menu, trying all the various options. Confirm that the pre-selected item in the sorting menu is correct after each re-sort. Edit the list to change the default sorting and verify that the "Sort by" menu reflects your selection. --- .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 110 ++++++++++++--------- opac/opac-shelves.pl | 9 +- 2 files changed, 72 insertions(+), 47 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 c1d273f66ea..51a699eb203 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -207,52 +207,68 @@ - - - [% IF sortfield == 'author' %] - - [% ELSE %] - - [% END %] - - [% IF sortfield == 'title' %] - - [% ELSE %] - - [% END %] - - [% IF sortfield == 'itemcallnumber' %] - - [% ELSE %] - - [% END %] - - [% IF sortfield == 'copyrightdate' %] - - [% ELSE %] - - [% END %] - - [% IF sortfield == "dateadded" %] - - [% ELSE %] - - [% END %] - - - @@ -977,6 +993,10 @@ $(function() { stickyClass: "floating" }); + $("#sortfield").on("change", function(){ + $('#sorting-form').submit(); + }); + }); // document.ready function AdjustRemark() { diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 802366d9940..f671f1f3f11 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -234,9 +234,14 @@ if ( $op eq 'view' ) { if ( $shelf ) { if ( $shelf->can_be_viewed( $loggedinuser ) ) { $category = $shelf->category; - my $sortfield = $query->param('sortfield') || $shelf->sortfield; # Passed in sorting overrides default sorting + my( $sortfield, $direction ); + if( defined( $query->param('sortfield') ) ){ # Passed in sorting overrides default sorting + ( $sortfield, $direction ) = split /:/, $query->param('sortfield'); + } else { + $sortfield = $shelf->sortfield; + $direction = 'asc'; + } $sortfield = 'title' unless grep $_ eq $sortfield, qw( title author copyrightdate itemcallnumber dateadded ); - my $direction = $query->param('direction') || 'asc'; $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; my ( $page, $rows ); unless ( $query->param('print') or $query->param('rss') ) { -- 2.11.0