From 941ddb89ec0cb0698727781e36a17b2aede8f04d Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Tue, 23 Jul 2013 12:14:09 -0400
Subject: [PATCH] Bug 10632 - Enable datatables for courses and course details in the OPAC

We should use datatables for the courses and course items tables. This
will make the tables sortable and searchable from the client side.

Test Plan:
1) Apply this patch
2) View the courses in the OPAC, try sorting and searching
3) View the course details for a course, try sorting and searching the
   items.
---
 .../prog/en/modules/opac-course-details.tt         |   17 +++++++++++++-
 .../prog/en/modules/opac-course-reserves.tt        |   23 +++++++++++++-------
 opac/opac-course-reserves.pl                       |   12 ++-------
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-details.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-details.tt
index 4d0e121..d3a3194 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-details.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-details.tt
@@ -6,6 +6,21 @@
 [% INCLUDE 'doc-head-open.inc' %]
 [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Course reserves for [% course.course_name %]
 [% INCLUDE 'doc-head-close.inc' %]
+
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+<script type="text/javascript" id="js">
+$(document).ready(function() {
+    $("#course-items-table").dataTable($.extend(true, {}, dataTablesDefaults, {
+        "sPaginationType": "four_button",
+        "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
+        "iDisplayLength": 20
+    }));
+});
+</script>
+
 </head>
 <body id="opac-main">
 [% IF ( OpacNav ) %]<div id="doc3" class="yui-t1">[% ELSE %]<div id="doc3" class="yui-t7">[% END %]
@@ -35,7 +50,7 @@
         </div>
 
         [% IF ( course_reserves ) %]
-            <table>
+            <table id="course-items-table">
                 <thead>
                     <tr>
                         <th>Title</th>
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-reserves.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-reserves.tt
index d00748e..f3b5735 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-reserves.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-course-reserves.tt
@@ -4,6 +4,21 @@
 [% INCLUDE 'doc-head-open.inc' %]
 [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Courses
 [% INCLUDE 'doc-head-close.inc' %]
+
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+<script type="text/javascript" id="js">
+$(document).ready(function() {
+    $("#course_reserves_table").dataTable($.extend(true, {}, dataTablesDefaults, {
+        "sPaginationType": "four_button",
+        "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
+        "iDisplayLength": 20
+    }));
+});
+</script>
+
 </head>
 <body id="opac-main">
 [% IF ( OpacNav ) %]<div id="doc3" class="yui-t1">[% ELSE %]<div id="doc3" class="yui-t7">[% END %]
@@ -17,14 +32,6 @@
                 <div class="yui-g">
 
                     <h1>Courses</h1>
-                    <div id="search-toolbar">
-                        <form action="/cgi-bin/koha/opac-course-reserves.pl" method="get" id="search_courses_form">
-                            <fieldset>
-                                <label for="search_on">Search courses:</label> <input type="text" name="search_on" id="search_on" />
-                                <input type="submit" value="Search" />
-                            </fieldset>
-                        </form>
-                    </div><!-- /search-toolbar -->
 
                     <table id="course_reserves_table">
                         <thead>
diff --git a/opac/opac-course-reserves.pl b/opac/opac-course-reserves.pl
index 83852c4..b8ca85f 100755
--- a/opac/opac-course-reserves.pl
+++ b/opac/opac-course-reserves.pl
@@ -38,13 +38,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     }
 );
 
-my $search_on = $cgi->param('search_on');
+my $courses = SearchCourses( enabled => 'yes' );
 
-my $courses = SearchCourses( term => $search_on, enabled => 'yes' );
-
-if ( @$courses == 1 ) {
-    print $cgi->redirect( "/cgi-bin/koha/opac-course-details.pl?course_id=" . $courses->[0]->{'course_id'} );
-} else {
-    $template->param( courses => $courses );
-    output_html_with_http_headers $cgi, $cookie, $template->output;
-}
+$template->param( courses => $courses );
+output_html_with_http_headers $cgi, $cookie, $template->output;
-- 
1.7.2.5