From 71523991b757eccdcdb17eae2928b8a55b4d194c Mon Sep 17 00:00:00 2001
From: Julian Maurice <julian.maurice@biblibre.com>
Date: Wed, 9 Jan 2013 14:56:43 +0100
Subject: [PATCH] Bug 9034: Filters are disabled by default

A small link above the table allow to enable this feature.
---
 .../prog/en/modules/catalogue/detail.tt            |  104 +++++++++++++++-----
 1 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
index 1763962..f05762d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
@@ -52,15 +52,70 @@ function verify_images() {
 <script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
 <script type="text/javascript">
 //<![CDATA[
+    function activate_filters(id) {
+        table = $("#" + id + " table");
+        if (table.length == 1) {
+            filters_row = table.find('thead tr.filters_row');
+            if (table.find('thead tr.columnFilter').length == 0) {
+                table.dataTable().columnFilter({
+                    'sPlaceHolder': 'head:after'
+                });
+                filters_row.addClass('columnFilter');
+            }
+            filters_row.show();
+        }
+
+        $('#' + id + '_activate_filters')
+            .text(_('Deactivate filters'))
+            .unbind('click')
+            .click(function() {
+                deactivate_filters(id);
+                return false;
+            });
+    }
+
+    function deactivate_filters(id) {
+        filters_row = $("#" + id + " table").find('thead tr.filters_row');
+
+        filters_row.find('input[type="text"]')
+            .val('')            // Empty filter text boxes
+            .trigger('keyup')   // Filter (display all rows)
+            .trigger('blur');   // Reset value to the column name
+        filters_row.hide();
+
+        $('#' + id + '_activate_filters')
+            .text(_('Activate filters'))
+            .unbind('click')
+            .click(function() {
+                activate_filters(id);
+                return false;
+            });
+    }
+
     $(document).ready(function() {
-        for (id in {holdings:0, otherholdings:0}) {
-            $("#"+ id +" > table").dataTable($.extend(true, {}, dataTablesDefaults, {
+        var ids = ['holdings', 'otherholdings'];
+        for (var i in ids) {
+            var id = ids[i];
+            table = $('#' + id + ' table');
+
+            // Duplicate the table header row for columnFilter
+            thead_row = table.find('thead tr');
+            clone = thead_row.clone().addClass('filters_row');
+            thead_row.before(clone);
+
+            // Enable sorting
+            table.dataTable($.extend(true, {}, dataTablesDefaults, {
                 'sDom': 't',
                 'bPaginate': false,
                 'bAutoWidth': false
-            })).columnFilter({
-                'sPlaceHolder': 'head:after'
-            });
+            }));
+
+            // Show a link to activate filtering
+            link = $('<a>')
+                .attr('href', '#')
+                .attr('id', id + '_activate_filters');
+            table.before(link);
+            deactivate_filters(id);
         }
     });
 //]]>
@@ -298,27 +353,24 @@ function verify_images() {
 [% BLOCK items_table %]
     <table>
         <thead>
-            [%# duplicate the header row for columnFilter %]
-            [% FOREACH i IN [1,2] %]
-                <tr>
-                    [% IF ( item_level_itypes ) %]<th>Item type</th>[% END %]
-                    <th>Current location</th>
-                    <th>Home Library</th>
-                    [% IF ( itemdata_ccode ) %]<th>Collection</th>[% END %]
-                    <th>Call number</th>
-                    <th>Status</th>
-                    <th>Last seen</th>
-                    <th>Barcode</th>
-                    [% IF ( volinfo ) %]<th>Publication details</th>[% END %]
-                    [% IF ( itemdata_uri ) %]<th>url</th>[% END %]
-                    [% IF ( itemdata_copynumber ) %]<th>Copy no.</th>[% END %]
-                    [% IF materials %]<th>Materials specified</th>[% END %]
-                    [% IF ( itemdata_itemnotes ) %]<th>Public notes</th>[% END %]
-                    [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th>Spine label</th>[% END %]
-                    [% IF ( hostrecords ) %]<th>Host records</th>[% END %]
-                    [% IF ( analyze ) %]<th>Used in</th><th></th>[% END %]
-                </tr>
-            [% END %]
+            <tr>
+                [% IF ( item_level_itypes ) %]<th>Item type</th>[% END %]
+                <th>Current location</th>
+                <th>Home Library</th>
+                [% IF ( itemdata_ccode ) %]<th>Collection</th>[% END %]
+                <th>Call number</th>
+                <th>Status</th>
+                <th>Last seen</th>
+                <th>Barcode</th>
+                [% IF ( volinfo ) %]<th>Publication details</th>[% END %]
+                [% IF ( itemdata_uri ) %]<th>url</th>[% END %]
+                [% IF ( itemdata_copynumber ) %]<th>Copy no.</th>[% END %]
+                [% IF materials %]<th>Materials specified</th>[% END %]
+                [% IF ( itemdata_itemnotes ) %]<th>Public notes</th>[% END %]
+                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th>Spine label</th>[% END %]
+                [% IF ( hostrecords ) %]<th>Host records</th>[% END %]
+                [% IF ( analyze ) %]<th>Used in</th><th></th>[% END %]
+            </tr>
         </thead>
         <tbody>
             [% FOREACH item IN items %]
-- 
1.7.2.5