From 8aa3dfe9ae5574f8b1fddbc40cb13b7234a3db58 Mon Sep 17 00:00:00 2001
From: Julian Maurice <julian.maurice@biblibre.com>
Date: Tue, 8 Sep 2015 08:49:44 +0200
Subject: [PATCH] Bug 14699: Show number of selected searches in search history

With the number displayed, it should remove the ambiguity about what
"Select all" and "Clear all" do.
The number is repeated in the "Delete" confirmation dialog.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
---
 .../prog/en/modules/catalogue/search-history.tt     | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt
index 240558a..1ae68e7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt
@@ -8,7 +8,6 @@
 <script type="text/javascript" src="[% interface %]/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 selected search history entries?");
 $(document).ready(function() {
     // We show table ordered by descending dates by default
     // (so that the more recent query is shown first)
@@ -75,7 +74,15 @@ $(document).ready(function() {
         if ( $(ids).length < 1 ) {
             return false;
         }
-        if ( confirm(MSG_CONFIRM_DELETE_HISTORY) ) {
+
+        var msg;
+        if (ids.length == 1) {
+          msg = _("Are you sure you want to delete the selected search history entry?");
+        } else {
+          msg = _("Are you sure you want to delete the %s selected search history entries?").format(ids.length);
+        }
+
+        if ( confirm(msg) ) {
             form.submit();
         }
         return false;
@@ -86,9 +93,13 @@ $(document).ready(function() {
 function enableCheckboxActions(form){
     // Enable/disable controls if checkboxes are checked
     var table = form.find('table').dataTable();
-    var checkedBoxes = table.$("input:checkbox:checked");
-    if (checkedBoxes.size()) {
-      form.find(".selections").html(_("With selected searches: "));
+    var checked_count = table.$("input:checkbox:checked").length;
+    if (checked_count) {
+      if (checked_count == 1) {
+        form.find(".selections").html(_("With selected search: "));
+      } else {
+        form.find(".selections").html(_("With %s selected searches: ").format(checked_count));
+      }
       form.find(".selections-toolbar .links a").removeClass("disabled");
     } else {
       form.find(".selections").html(_("Select searches to: "));
-- 
2.9.3