From 7ed5a2946d6d751349145c9f09d7fb71a570880b Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Fri, 20 Dec 2013 16:34:44 +0100
Subject: [PATCH] Bug 11430: OPAC changes -- prog theme

---
 .../prog/en/modules/opac-search-history.tt         |  264 +++++++++++++-------
 1 file changed, 172 insertions(+), 92 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt
index e8581dd..102a5a4 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt
@@ -4,23 +4,67 @@
 [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your search history
 [% INCLUDE 'doc-head-close.inc' %]
 [% INCLUDE 'datatables.inc' %]
+<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
 <script type="text/javascript">
 //<![CDATA[
-var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete your search history?");
+var MSG_CONFIRM_DELETE_HISTORY = _("Are you sure you want to delete selected search history?");
 $(document).ready(function() {
     // We show table ordered by descending dates by default
     // (so that the more recent query is shown first)
     $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
-        "aaSorting": [[ 0, "desc" ]],
-        "aoColumns": [
-            { "sType": "title-string" },
-            null,
-            null
-        ]
+        "aaSorting": [[ 1, "desc" ]],
+        "aoColumnDefs": [
+            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
+            { "aTargets": [ 1 ], "sType": "title-string" },
+        ],
     }));
 
     [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]$('#tabs').tabs();[% END %]
+
+    $(".CheckNone").click(function(e){
+        e.preventDefault();
+        var form = $(this).parents("form").get(0);
+        $(form).unCheckCheckboxes();
+        enableCheckboxActions(form);
+    });
+    $(".CheckAll").click(function(e){
+        e.preventDefault();
+        var form = $(this).parents("form").get(0);
+        $(form).checkCheckboxes();
+        enableCheckboxActions(form);
+    });
+
+    $("input:checkbox").click(function(){
+        var form = $(this).parents("form").get(0);
+        enableCheckboxActions(form);
+    });
+
+    $(".action_delete").click(function(e){
+        e.preventDefault();
+        var form = $(this).parents("form").get(0);
+        var ids = $(form).find("input:checkbox:checked");
+        if ( $(ids).length < 1 ) {
+            return false;
+        }
+        if ( confirm(MSG_CONFIRM_DELETE_HISTORY) ) {
+            $(form).submit();
+        }
+        return false;
+    });
 });
+
+function enableCheckboxActions(form){
+    // Enable/disable controls if checkboxes are checked
+    var checkedBoxes = $(form).find("input:checkbox:checked");
+    if ($(checkedBoxes).size()) {
+      $(form).find(".selections").html(_("With selected searches: "));
+      $(form).find(".selections-toolbar .links a").removeClass("disabled");
+    } else {
+      $(form).find(".selections").html(_("Select searches to: "));
+      $(form).find(".selections-toolbar .links a").addClass("disabled");
+    }
+}
+
 //]]>
 
 </script>
@@ -48,124 +92,160 @@ $(document).ready(function() {
           </ul>
       [% END %]
         <div id="biblio_tab">
+          <div id="current_biblio">
           [% IF ( current_biblio_searches ) %]
             <h2>Current session</h2>
             <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
+              <div class="selections-toolbar">
+                <a class="CheckAll" href="#">Select all</a>
+                <a class="CheckNone" href="#">Clear all</a>
+                <span class="sep">|</span>
+                <span class="links">
+                  <span class="selections">Select searches to: </span>
+                  <a href="#" class="action_delete disabled">Delete</a>
+                </span>
+              </div>
               <input type="hidden" name="action" value="delete" />
-              <input type="hidden" name="previous" value="0" />
-              <input type="hidden" name="type" value="biblio" />
-              <input type="submit" class="deleteshelf" value="Delete your current catalog history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
+              <table class="historyt">
+                <thead>
+                  <tr>
+                    <th></th>
+                    <th>Date</th>
+                    <th>Search</th>
+                    <th>Results</th>
+                  </tr>
+                </thead>
+                <tbody>
+                [% FOREACH s IN current_biblio_searches %]
+                  <tr>
+                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
+                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
+                    <td><a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
+                    <td>[% s.total %]</td>
+                  </tr>
+                [% END %]
+                </tbody>
+              </table>
             </form>
-            <table class="historyt">
-              <thead>
-                <tr>
-                  <th>Date</th>
-                  <th>Search</th>
-                  <th>Results</th>
-                </tr>
-              </thead>
-              <tbody>
-              [% FOREACH s IN current_biblio_searches %]
-                <tr>
-                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
-                  <td><a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
-                  <td>[% s.total %]</td>
-                </tr>
-              [% END %]
-              </tbody>
-            </table>
           [% END %]
+          </div>
 
+          <div id="previous_biblio">
           [% IF ( previous_biblio_searches ) %]
             <h2>Previous sessions</h2>
             <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
+              <div class="selections-toolbar">
+                <a class="CheckAll" href="#">Select all</a>
+                <a class="CheckNone" href="#">Clear all</a>
+                <span class="sep">|</span>
+                <span class="links">
+                  <span class="selections">Select searches to: </span>
+                  <a href="#" class="action_delete disabled">Delete</a>
+                </span>
+              </div>
+
               <input type="hidden" name="action" value="delete" />
-              <input type="hidden" name="previous" value="1" />
-              <input type="hidden" name="type" value="biblio" />
-              <input type="submit" class="deleteshelf" value="Delete your previous catalog search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
+              <table id="bib_prev_t" class="historyt">
+                <thead>
+                  <tr>
+                    <th></th>
+                    <th>Date</th>
+                    <th>Search</th>
+                    <th>Results</th>
+                  </tr>
+                </thead>
+                <tbody>
+                [% FOREACH s IN previous_biblio_searches %]
+                  <tr>
+                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
+                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
+                    <td><a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
+                    <td>[% s.total %]</td>
+                  </tr>
+                [% END %]
+                </tbody>
+              </table>
             </form>
-            <table class="historyt">
-              <thead>
-                <tr>
-                  <th>Date</th>
-                  <th>Search</th>
-                  <th>Results</th>
-                </tr>
-              </thead>
-              <tbody>
-              [% FOREACH s IN previous_biblio_searches %]
-                <tr>
-                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
-                  <td><a href="/cgi-bin/koha/opac-search.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
-                  <td>[% s.total %]</td>
-                </tr>
-              [% END %]
-              </tbody>
-            </table>
           [% END %]
+          </div>
 
           [% IF !current_biblio_searches && !previous_biblio_searches %]
             <p>Your catalog search history is empty.</p>
           [% END %]
         </div>
 
-
       [% IF Koha.Preference( 'OpacAuthorities' ) == 1 %]
         <div id="authority_tab">
           [% IF ( current_authority_searches ) %]
             <h2>Current session</h2>
             <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
+              <div class="selections-toolbar">
+                <a class="CheckAll" href="#">Select all</a>
+                <a class="CheckNone" href="#">Clear all</a>
+                <span class="sep">|</span>
+                <span class="links">
+                  <span class="selections">Select searches to: </span>
+                  <a href="#" class="action_delete disabled">Delete</a>
+                </span>
+              </div>
               <input type="hidden" name="action" value="delete" />
-              <input type="hidden" name="previous" value="0" />
-              <input type="hidden" name="type" value="authority" />
-              <input type="submit" class="deleteshelf" value="Delete your current authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
+              <table class="historyt">
+                <thead>
+                  <tr>
+                    <th></th>
+                    <th>Date</th>
+                    <th>Search</th>
+                    <th>Results</th>
+                  </tr>
+                </thead>
+                <tbody>
+                [% FOREACH s IN current_authority_searches %]
+                  <tr>
+                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
+                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
+                    <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
+                    <td>[% s.total %]</td>
+                  </tr>
+                [% END %]
+                </tbody>
+              </table>
             </form>
-            <table class="historyt">
-              <thead>
-                <tr>
-                  <th>Date</th>
-                  <th>Search</th>
-                  <th>Results</th>
-                </tr>
-              </thead>
-              <tbody>
-              [% FOREACH s IN current_authority_searches %]
-                <tr>
-                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
-                  <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
-                  <td>[% s.total %]</td>
-                </tr>
-              [% END %]
-              </tbody>
-            </table>
           [% END %]
 
           [% IF ( previous_authority_searches ) %]
             <h2>Previous sessions</h2>
             <form action="/cgi-bin/koha/opac-search-history.pl" method="get">
+              <div class="selections-toolbar">
+                <a class="CheckAll" href="#">Select all</a>
+                <a class="CheckNone" href="#">Clear all</a>
+                <span class="sep">|</span>
+                <span class="links">
+                  <span class="selections">Select searches to: </span>
+                  <a href="#" class="action_delete disabled">Delete</a>
+                </span>
+              </div>
               <input type="hidden" name="action" value="delete" />
-              <input type="hidden" name="previous" value="1" />
-              <input type="hidden" name="type" value="authority" />
-              <input type="submit" class="deleteshelf" value="Delete your previous authority search history" onclick="return confirm(MSG_CONFIRM_DELETE_HISTORY);" />
+              <table class="historyt">
+                <thead>
+                  <tr>
+                    <th></th>
+                    <th>Date</th>
+                    <th>Search</th>
+                    <th>Results</th>
+                  </tr>
+                </thead>
+                <tbody>
+                [% FOREACH s IN previous_authority_searches %]
+                  <tr>
+                    <td><input type="checkbox" name="id" value="[% s.id %]" /></td>
+                    <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
+                    <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
+                    <td>[% s.total %]</td>
+                  </tr>
+                [% END %]
+                </tbody>
+              </table>
             </form>
-            <table class="historyt">
-              <thead>
-                <tr>
-                  <th>Date</th>
-                  <th>Search</th>
-                  <th>Results</th>
-                </tr>
-              </thead>
-              <tbody>
-              [% FOREACH s IN previous_authority_searches %]
-                <tr>
-                  <td><span title="[% s.time %]">[% s.time |$KohaDates with_hours => 1 %]</span></td>
-                  <td><a href="/cgi-bin/koha/opac-authorities-home.pl?[% s.query_cgi |html %]">[% s.query_desc |html %]</a></td>
-                  <td>[% s.total %]</td>
-                </tr>
-              [% END %]
-              </tbody>
-            </table>
           [% END %]
 
           [% IF !current_authority_searches && !previous_authority_searches %]
-- 
1.7.10.4