From 58dd9b63c432a8ca287c2e24422369bfd6c2f0bc Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Mon, 20 Jan 2014 11:36:48 +0100
Subject: [PATCH] Bug 7825: QA followup - preselection of items (bootstrap)

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Retested with all 3 themes, works as expected.
---
 .../opac-tmpl/bootstrap/en/modules/opac-reserve.tt |   39 +++++++++++---------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
index e82540c..0ed677b 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
@@ -416,6 +416,11 @@
         var copiesRowId = null;
         var wasSpecific = false;
         var lastCopiesRowId = null;
+
+        $(".toggle-hold-options").show();
+        $(".hold-options").hide();
+        $(".holddatefrom,.holddateto").prop("readOnly", true);
+
         $(".checkitem").parent().click(function(e){
             if(e.target.tagName.toLowerCase() == 'td'){
                 $(this).find("input.checkitem").each( function() {
@@ -434,12 +439,22 @@
           }
         });
 
+        $(".toggle-hold-options").on("click",function(e){
+            e.preventDefault();
+            toggleLink = $(this);
+            var optionsID = this.id.replace("toggle-hold-options-","");
+            $("#hold-options-"+optionsID).toggle(0, function() {
+                toggleLink.text($(this).is(':visible') ? _("Hide options") : _("Show more options"));
+            });
+        });
+
         // Hides all 'specific copy' table rows on load.
         $(".copiesrow").hide();
 
-        [% FOREACH bibitemloo IN bibitemloop %]
-          [% IF bibitemloo.holdable %]
-            [% IF OPACItemHolds == 'force' %]
+        [% IF OPACItemHolds == 'force' %]
+          [% FOREACH bibitemloo IN bibitemloop %]
+            [% IF bibitemloo.holdable %]
+              $("#toggle-hold-options-[% bibitemloo.biblionumber %]").click();
               $("#copiesrow_[% bibitemloo.biblionumber %]").show();
             [% END %]
           [% END %]
@@ -454,10 +469,6 @@
             }
         });
 
-        $(".toggle-hold-options").show();
-        $(".hold-options").hide();
-        $(".holddatefrom,.holddateto").prop("readOnly", true);
-
         $(".date-format").each(function(){
             if($(this).hasClass("to")){ var op = "to"; }
             if($(this).hasClass("from")){ var op = "from"; }
@@ -509,8 +520,9 @@
             $(".selectany").attr("checked", "checked");
         [% END %]
 
-        // If we can choose a specific item, we preselect the first one
-        [% IF OPACItemHolds =="1" or OPACItemHolds == 'force' %]
+        // If the user is *allowed* to choose a specific item
+        // The first one is preselected
+        [% IF OPACItemHolds =="1" %]
             $("table.copiesrow").each(function(){
                 var id = suffixOf($(this).attr("id"), "_");
                 select_first_available(id);
@@ -596,15 +608,6 @@
             return true;
         });
 
-        $(".toggle-hold-options").on("click",function(e){
-            e.preventDefault();
-            toggleLink = $(this);
-            var optionsID = this.id.replace("toggle-hold-options-","");
-            $("#hold-options-"+optionsID).toggle(0, function() {
-                toggleLink.text($(this).is(':visible') ? _("Hide options") : _("Show more options"));
-            });
-        });
-
         [% FOREACH bibitemloo IN bibitemloop %]
             [% IF ( bibitemloo.holdable ) %]
                 // http://jqueryui.com/demos/datepicker/#date-range
-- 
1.7.10.4