From 638feb69a8da94e68dea14a01837c9daeb697183 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Thu, 30 Oct 2014 09:57:49 -0400
Subject: [PATCH] [Signed-off] Bug 12258 [Template follow-up] Datatable in
 Patrons Account Fines
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This follow-up corrects some of the QA issues affecting the other patch,
as well as changing the way the "filter" option is displayed:

- Added the use of the DataTables include file
- Removed redundant document.ready
- Fixed single quotes
- Fixed default sort (should be date descending to match the current
  functionality)
- Adding missing <tr>
- Converted filter button to a link

The last change is a judgement call, but the button in the DataTables
toolbar looked awkward and caused ugly wrapping at narrower viewport
sizes. I think a link is more keeping with the pattern established by
"select all / clear all" links.

To test, apply both patches and view the account page
(members/boraccount.pl) for a patron who has paid and unpaid fines (the
more the better).

- Confirm that the default sort is by date descending.
- Confirm that DataTables controls (paging, search, result count) work
  correctly.
- Confirm that clicking the "Filter paid transactions" link works
  correctly to toggle display of paid transactions.

Works as expected. Passed koha-qa.pl.
Signed-off-by: Marc VĂ©ron <veron@veron.ch>
---
 .../prog/en/modules/members/boraccount.tt          |   50 ++++++++++----------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
index b6c06d9..f87c475 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
@@ -1,32 +1,32 @@
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Patrons &rsaquo; Account for [% INCLUDE 'patron-title.inc' %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<link rel="stylesheet" type="text/css" href="/intranet-tmpl/prog/en/css/datatables.css" />
-<script type="text/javascript" src="/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.min.js"></script>
-[% INCLUDE 'datatables-strings.inc' %]
-<script type="text/javascript" src="/intranet-tmpl/prog/en/js/datatables.js"></script>
-<script type="text/javascript" id="js">$(document).ready(function() {
- $(document).ready(function() {
-    var txtActivefilter = _('Filter paid transactions');
-    var txtInactivefilter = _('Show all transactions');
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+[% INCLUDE 'datatables.inc' %]
+<script type="text/javascript">
+$(document).ready(function() {
+    var txtActivefilter = _("Filter paid transactions");
+    var txtInactivefilter = _("Show all transactions");
     var table_account_fines = $("#table_account_fines").dataTable($.extend(true, {}, dataTablesDefaults, {
         "sPaginationType": "four_button",
-        "iDisplayLength" : 25
+        'aaSorting': [[0, 'desc']],
+        "sDom": 'C<"top pager"ilpf><"#filter_c">tr<"bottom pager"ip>'
     }));
-    $('<button id="filter_transacs">'+txtActivefilter+'</button>').appendTo($("#table_account_fines_filter"));
-    $('#filter_transacs').click(function() {
+    $("#filter_c").html('<p><a href="#" id="filter_transacs">'+txtActivefilter+'</a>');
+    $('#filter_transacs').click(function(e) {
+        e.preventDefault();
         if ($(this).hasClass('filtered')) {
             var filteredValue = '';
-            $('#filter_transacs').text(txtActivefilter);
+            $(this).text(txtActivefilter);
         } else { //Not filtered. Let's do it!
             var filteredValue = '^((?!0.00).*)$'; //Filter not matching 0.00 http://stackoverflow.com/a/406408
-            $('#filter_transacs').text(txtInactivefilter);
+            $(this).text(txtInactivefilter);
         }
         table_account_fines.fnFilter(filteredValue, 4, true, false);
         $(this).toggleClass('filtered');
     });
- });
-}); </script>
+});
+</script>
 </head>
 <body id="pat_borraccount" class="pat">
 [% INCLUDE 'header.inc' %]
@@ -54,15 +54,17 @@
 <!-- The table with the account items -->
 <table id="table_account_fines">
     <thead>
-  	<th>Date</th>
-    <th>Description of charges</th>
-    <th>Note</th>
-    <th>Amount</th>
-    <th>Outstanding</th>
-    [% IF ( reverse_col ) %]
-    <th>&nbsp;</th>
-    [% END %]
-    <th>Print</th>
+      <tr>
+          <th>Date</th>
+          <th>Description of charges</th>
+          <th>Note</th>
+          <th>Amount</th>
+          <th>Outstanding</th>
+          [% IF ( reverse_col ) %]
+              <th>&nbsp;</th>
+          [% END %]
+          <th>Print</th>
+        </tr>
     </thead>
 
 	<!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
-- 
1.7.10.4