From 67a23be1439c0668823c732922425a0ce9be0b01 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Tue, 28 Jan 2014 09:07:21 -0500
Subject: [PATCH] Bug 6427 [Part 19] - Add full debit and credit table Print and Download features

---
 .../intranet-tmpl/prog/en/includes/datatables.inc  |    3 +-
 koha-tmpl/intranet-tmpl/prog/en/js/datatables.js   |   24 ++++++++++
 .../prog/en/modules/members/account.tt             |   48 ++++++++++++++++++--
 3 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc
index 703d1e3..b306d0e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc
@@ -1,4 +1,5 @@
 <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/TableTools/media/js/TableTools.min.js"></script>
 <script type="text/javascript">
 //<![CDATA[
     var MSG_DT_FIRST = _("First");
@@ -17,4 +18,4 @@
     var CONFIG_EXCLUDE_ARTICLES_FROM_SORT = _("a an the");
 //]]>
 </script>
-<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
\ No newline at end of file
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
index c2a2cf8..d3e9b99 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
+++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
@@ -26,6 +26,30 @@ var dataTablesDefaults = {
     "sDom": '<"top pager"ilpf>t<"bottom pager"ip>'
 };
 
+// Set the classes that TableTools uses to something suitable for Bootstrap
+$.extend( true, $.fn.DataTable.TableTools.classes, {
+    "container": "btn-group",
+    "buttons": {
+        "normal": "btn btn-small",
+        "disabled": "btn btn-small disabled"
+    },
+    "collection": {
+        "container": "DTTT_dropdown dropdown-menu",
+        "buttons": {
+            "normal": "",
+            "disabled": "disabled"
+        }
+    }
+} );
+
+// Have the collection use a bootstrap compatible dropdown
+$.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
+    "collection": {
+        "container": "ul",
+        "button": "li",
+        "liner": "a"
+    }
+} );
 
 // Return an array of string containing the values of a particular column
 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt
index 5a8c071..ae98c2c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt
@@ -32,6 +32,26 @@ $(document).ready(function() {
     var sImageUrl = "[% interface %]/[% theme %]/img/";
 
     var debitsTable = $('#debits-table').dataTable( {
+        "sDom": "<'row-fluid'<'span6'T><'span6'>r>t<'row-fluid'><'top pager'ilpf>t<'bottom pager'ip>",
+        "oTableTools": {
+            "sSwfPath": "/intranet-tmpl/lib/jquery/plugins/TableTools/media/swf/copy_csv_xls_pdf.swf",
+            "aButtons": [
+                {
+                    "sExtends": "print",
+                    "sButtonText": "<i class='icon-print'></i> " + _("Print")
+                },
+                {
+                    "sExtends":    "collection",
+                    "sButtonText": "<i class='icon-download'></i> " + _("Download") + " <span class='caret' />",
+                    "aButtons": [
+                        {
+                            "sExtends": "csv",
+                            "sButtonText": "<i class='icon-file'></i> " + _("CSV")
+                        }
+                    ]
+                }
+            ]
+        },
         "bProcessing": true,
         "aoColumns": [
             {
@@ -117,6 +137,26 @@ $(document).ready(function() {
     } );
 
     var creditsTable = $('#credits-table').dataTable( {
+        "sDom": "<'row-fluid'<'span6'T><'span6'>r>t<'row-fluid'><'top pager'ilpf>t<'bottom pager'ip>",
+        "oTableTools": {
+            "sSwfPath": "/intranet-tmpl/lib/jquery/plugins/TableTools/media/swf/copy_csv_xls_pdf.swf",
+            "aButtons": [
+                {
+                    "sExtends": "print",
+                    "sButtonText": "<i class='icon-print'></i> " + _("Print")
+                },
+                {
+                    "sExtends":    "collection",
+                    "sButtonText": "<i class='icon-download'></i> " + _("Download") + " <span class='caret' />",
+                    "aButtons": [
+                        {
+                            "sExtends": "csv",
+                            "sButtonText": "<i class='icon-file'></i> " + _("CSV")
+                        }
+                    ]
+                }
+            ]
+        },
         "bProcessing": true,
         "aoColumns": [
             {
@@ -187,7 +227,7 @@ function fnFormatDebitDetails( debitsTable, nTr ) {
 
     var account_offsets = oData.account_offsets;
 
-    sOut += "<a class='debit_print btn btn-small' style='margin:5px;' onclick='accountPrint(\"debit\"," + oData.debit_id + ")'>" +
+    sOut += "<a class='debit_print btn btn-small noprint' style='margin:5px;' onclick='accountPrint(\"debit\"," + oData.debit_id + ")'>" +
                 "<i class='icon-print'></i> " + _("Print receipt") +
             "</a>";
 
@@ -275,7 +315,7 @@ function fnFormatCreditDetails( creditsTable, nTr ) {
 
     var sOut = "<div class='innerDetails' style='display:none;'>";
 
-    sOut += "<button class='credit_print btn btn-small' style='margin:5px;' onclick='accountPrint(\"credit\"," + oData.credit_id + ")'>" +
+    sOut += "<button class='credit_print btn btn-small noprint' style='margin:5px;' onclick='accountPrint(\"credit\"," + oData.credit_id + ")'>" +
                 "<i class='icon-print'></i> " + _("Print receipt") +
             "</button>";
 
@@ -372,7 +412,7 @@ function accountPrint( type, id ) {
 
                     <div>
                         <div id="account-debits">
-                            <a id="account-debits-switcher" href="#" onclick="return false">View payments</a>
+                            <p><a id="account-debits-switcher" href="#" onclick="return false">View payments</a></p>
                             <table cellpadding="0" cellspacing="0" border="0" class="display" id="debits-table">
                                 <thead>
                                     <tr>
@@ -394,7 +434,7 @@ function accountPrint( type, id ) {
                         </div>
 
                         <div id="account-credits">
-                            <a id="account-credits-switcher" href="#"  onclick="return false">View fees</a>
+                            <p><a id="account-credits-switcher" href="#"  onclick="return false">View fees</a></p>
                             <table cellpadding="0" cellspacing="0" border="0" class="display" id="credits-table">
                                 <thead>
                                     <tr>
-- 
1.7.2.5