[Koha-patches] [PATCH] Bug 3229: Fixes sort-by feature for jquery tablesorter in lists.

Garry Collum gcollum at gmail.com
Wed Jun 24 03:42:05 CEST 2009


This patch adds some variables for the sortfield that are passed through the URL so that the sort-by feature works when the jquery tablesorter is used for a list of titles in opac-shelves.tmpl.
---
 C4/VirtualShelves/Page.pm                          |   13 ++++++++++++-
 koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc  |    4 ++--
 .../opac-tmpl/prog/en/modules/opac-shelves.tmpl    |   16 ++++++++++++++--
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm
index 99d1f5d..999692c 100644
--- a/C4/VirtualShelves/Page.pm
+++ b/C4/VirtualShelves/Page.pm
@@ -170,6 +170,15 @@ SWITCH: {
         #check that the user can view the shelf
 		if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
 			my $items;
+			my $authorsort;
+			my $copyrightsort;
+	                my $sortfield = ($query->param('sortfield') ? $query->param('sortfield') : 'title');
+			if ($sortfield eq 'author') {
+				$authorsort = 'author';
+			}
+			if ($sortfield eq 'copyrightdate'){
+				$copyrightsort = 'copyrightdate';
+			}
 			($items, $totitems) = GetShelfContents($shelfnumber, $shelflimit, $shelfoffset);
 			for my $this_item (@$items) {
 				# the virtualshelfcontents table does not store these columns nor are they retrieved from the items
@@ -188,6 +197,8 @@ SWITCH: {
 				shelfname   => $shelflist->{$shelfnumber}->{'shelfname'} || $privshelflist->{$shelfnumber}->{'shelfname'},
 				shelfnumber => $shelfnumber,
 				viewshelf   => $shelfnumber,
+				authorsort   => $authorsort,
+				copyrightsort => $copyrightsort,
 				manageshelf => $manageshelf,
 				itemsloop => $items,
 			);
@@ -291,7 +302,7 @@ foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflis
 
 my $url = $type eq 'opac' ? "/cgi-bin/koha/opac-shelves.pl" : "/cgi-bin/koha/virtualshelves/shelves.pl";
 my %qhash = ();
-foreach (qw(display viewshelf)) {
+foreach (qw(display viewshelf sortfield)) {
     $qhash{$_} = $query->param($_) if $query->param($_);
 }
 (scalar keys %qhash) and $url .= '?' . join '&', map {"$_=$qhash{$_}"} keys %qhash;
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
index 2d4e313..cd258f7 100644
--- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
@@ -103,7 +103,7 @@
 		<!-- TMPL_IF NAME="pubshelves" -->
 			<ul class="first-of-type">
 			<!-- TMPL_LOOP NAME="pubshelvesloop" -->
-			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelfnumber" -->"><!-- TMPL_VAR NAME="shelfname"  ESCAPE="html" --></a></li>
+			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelfnumber" -->&amp;sortfield=<!-- TMPL_VAR NAME="sortfield" -->"><!-- TMPL_VAR NAME="shelfname"  ESCAPE="html" --></a></li>
 			<!-- /TMPL_LOOP -->
 			</ul>   
 		<!-- TMPL_ELSE -->
@@ -120,7 +120,7 @@
 		<!-- TMPL_IF NAME="barshelves" -->
 			<ul class="first-of-type">
 			<!-- TMPL_LOOP NAME="barshelvesloop" -->
-			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelfnumber" -->"><!-- TMPL_VAR NAME="shelfname"  ESCAPE="html" --></a></li>
+			<li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelfnumber" -->&amp;sortfield=<!-- TMPL_VAR NAME="sortfield" -->"><!-- TMPL_VAR NAME="shelfname"  ESCAPE="html" --></a></li>
 			<!-- /TMPL_LOOP -->
 			</ul>   
 		<!-- TMPL_ELSE -->
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
index c15bdc3..a1dda46 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
@@ -77,10 +77,22 @@ $(function() {
     $("#listcontents").tablesorter({
         widgets : ['zebra'],
         <!-- TMPL_IF NAME="manageshelf" -->
+          <!-- TMPL_IF NAME="authorsort" -->
+          sortList: [[2,0]],
+          <!-- TMPL_ELSIF NAME="copyrightsort" -->
+          sortList: [[3,1]],
+          <!-- TMPL_ELSE -->
           sortList: [[1,0]],
+          <!-- /TMPL_IF -->
           headers: { 0: { sorter: false },1:{sorter: 'articles'}
         <!-- TMPL_ELSE -->
+          <!-- TMPL_IF NAME="authorsort" -->
+          sortList: [[1,0]],
+          <!-- TMPL_ELSIF NAME="copyrightsort" -->
+          sortList: [[2,1]],
+          <!-- TMPL_ELSE -->
           sortList: [[0,0]],
+          <!-- /TMPL_IF -->
           headers: { 0:{sorter:'articles'}
         <!-- /TMPL_IF -->
         }
@@ -338,7 +350,7 @@ $(document).ready(function(){
                           <!--TMPL_ELSE-->
                             <tr>
                           <!-- /TMPL_UNLESS -->
-                              <td><a href="opac-shelves.pl?display=privateshelves&amp;viewshelf=<!-- TMPL_VAR NAME="shelf" -->"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"  --></a></td>
+                              <td><a href="opac-shelves.pl?display=privateshelves&amp;viewshelf=<!-- TMPL_VAR NAME="shelf" -->&amp;sortfield=<!-- TMPL_VAR NAME="sortfield" -->"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"  --></a></td>
                               <td><!-- TMPL_VAR NAME="count" --> item(s)</td>
                               <td><!-- TMPL_VAR NAME="sortfield" --></td>
                               <td>
@@ -406,7 +418,7 @@ $(document).ready(function(){
                       <!--TMPL_ELSE-->
                         <tr>
                       <!-- /TMPL_UNLESS -->
-                          <td><a href="opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelf" -->"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"  --></a></td>
+                          <td><a href="opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelf" -->&amp;sortfield=<!-- TMPL_VAR NAME="sortfield" -->"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"  --></a></td>
                           <td><!-- TMPL_VAR NAME="count" --> item(s)</td>
                           <td><!-- TMPL_VAR NAME="sortfield" --></td>
                           <td>
-- 
1.5.6.5




More information about the Koha-patches mailing list