From d59a4d86455f325c45437cabaad2a74f90c372db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 9 Nov 2012 12:08:10 +0100 Subject: [PATCH] Bug 7825: FIX some ergonomic issues in opac-reserve http://bugs.koha-community.org/show_bug.cgi?id=7825 Signed-off-by: Delaye Stephane --- .../opac-tmpl/prog/en/modules/opac-reserve.tt | 150 +++++++++++--------- 1 file changed, 80 insertions(+), 70 deletions(-) diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt index e1cb87c..99fa11f 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt @@ -14,93 +14,100 @@ return s.substring(index + 1); } +// Select the first item available +function select_first_available(id){ + var radios = $("input:radio[name='checkitem_" + id + "']"); + $(radios).first().attr("checked", "checked"); +} + $(document).ready(function() { $('#hold-request-form').preventDoubleFormSubmit(); var copiesRowId = null; var wasSpecific = false; var lastCopiesRowId = null; - $(".checkitem").parent().click(function(e){ - if(e.target.tagName.toLowerCase() == 'td'){ + $(".checkitem").parent().click(function(e){ + if(e.target.tagName.toLowerCase() == 'td'){ $(this).find("input.checkitem").each( function() { - $(this).attr('checked', !$(this).attr('checked')); - }); - } - }); + $(this).attr('checked', 'checked'); + }); + } + }); + + // click on a first td check the confirmjs checkbox + $("td.hold").click(function(e){ + if(e.target.tagName.toLowerCase() == 'td'){ + $(this).find("input.confirmjs").each( function() { + $(this).attr('checked', !$(this).attr('checked')); + $(this).change(); + }); + } + }); + // Hides all 'specific copy' table rows on load. $(".copiesrow").hide(); - $("#place_on_hdr").show(); - [% IF OPACItemHolds == '1' %] - $(".place_on_type").show(); - [% END %] - // Replace non-JS single-selection with multi-selection capability. $(".reserve_mode").val("multi"); $(".confirm_nonjs").remove(); $(".confirmjs_hold").each(function(){ var bib = $(this).attr("title"); var html = ""; - $(this).html(html); - }); - $(".confirmjs_nohold").each(function(){ - var bib = $(this).attr("title"); - var html = ""; + html += "value=\"" + bib + "\" id=\"" + bib + "\"/>"; $(this).html(html); }); - // Make sure a specific item was selected where specified - // before moving on to a new item. - function changeSelection (newCopiesRowId, isSpecific) { - if (copiesRowId && ((copiesRowId != newCopiesRowId) || (wasSpecific != isSpecific))) { - var biblioNum = suffixOf(copiesRowId, "_"); - - // If the 'specific copy' radio button was checked - if (wasSpecific && (copiesRowId != newCopiesRowId)) { - // Find the selected copy - var item = $(".checkitem_" + biblioNum + ":checked"); - if ($(item).size() == 0) { - alert(MSG_NO_COPY_SELECTED); - return false; - } - } - } - copiesRowId = newCopiesRowId; - wasSpecific = isSpecific; - return true; - } - - // When 'specific copy' radio button is clicked - $(".selectspecific").click(function() { - - // Make sure all other specific copy table rows are hidden - biblioNum = suffixOf($(this).attr("id"), "_"); + // expand or collapse the copiesrow tr + function toggle_copiesrow(biblioNum) { + var checkbox = $("input:checkbox[value='"+biblioNum+"']"); newCopiesRowId = "#copiesrow_" + biblioNum; + var select_specific = $("#reqspecific_"+biblioNum).is(":checked"); - if (!changeSelection(newCopiesRowId, true)) { - return false; + // If the checkbox is checked AND we want a specific item, we display the items block + if ( $(checkbox).is(":checked") && select_specific ) { + $(newCopiesRowId).show(); + } else { + $(newCopiesRowId).hide(); } - $(".copiesrow:not(" + newCopiesRowId + ")").hide(); + }; - // Show the specific copy table for this radio button. - $(newCopiesRowId).show(); - }); + $("#place_on_hdr").show(); + [% IF OPACItemHolds == '1' %] + $(".place_on_type").show(); + // onload, selectany is checked + $(".selectany").attr("checked", "checked"); + [% END %] - // When 'first available' radion button is clicked - $(".selectany").click(function() { - // Make sure all other specific copy table rows are hidden - biblioNum = suffixOf($(this).attr("id"), "_"); - newCopiesRowId = "#copiesrow_" + biblioNum; + // If we can choose a specific item, we preselect the first one + [% IF OPACItemHolds =="1" or OPACItemHolds == 'force' %] + $("tr.hold").each(function(){ + var id = suffixOf($(this).attr("id"), "_"); + select_first_available(id); + }); + [% END %] - if (!changeSelection(newCopiesRowId, false)) { - return false; + // On confirmsjs change + $(".confirmjs").change(function(){ + var id = suffixOf($(this).attr("id"), "_"); + // If I m checked, I enable radio buttons + if ( $(this).is(":checked") ) { + $("#reqspecific_" + id).attr("disabled", false); + $("#reqany_" + id).attr("disabled", false); } - - // Hide the copies table row - $(".copiesrow").hide(); + // Else its are disabled + else { + $("#reqspecific_" + id).attr("disabled", "disabled"); + $("#reqany_" + id).attr("disabled", "disabled"); + } + // expand or collaspe the items block + toggle_copiesrow(id); + }); + + // When 'specific copy' or 'first available' radio button is clicked + $(".selectspecific, .selectany").click(function() { + var id = suffixOf($(this).attr("id"), "_"); + toggle_copiesrow(id); }); // When 'Place Hold' button is clicked @@ -237,6 +244,7 @@
+ [% UNLESS ( none_available ) %] @@ -258,16 +266,17 @@ [% END %] [% UNLESS ( singleBranchMode ) %] - [% IF ( choose_branch ) %] + [% IF ( choose_branch ) %] - [% END %] + [% END %] [% END %] [% ELSE %][% END %] - + + [% FOREACH bibitemloo IN bibitemloop %] - - [% IF ( bibitemloo.holdable ) %] - + [% IF ( bibitemloo.holdable ) %] + - [% ELSE %] - [% UNLESS ( none_available ) %][% END %] - [% END %] + + [% ELSE %] + [% UNLESS ( none_available ) %][% END %] + [% END %] [% IF ( bibitemloo.holdable ) %]
Hold TitlePickup location
Title
+
@@ -278,10 +287,10 @@ value="any" /> -   [% ELSE %][% END %] [% bibitemloo.title |html %][% IF ( bibitemloo.subtitle ) %] [% FOREACH subtitl IN bibitemloo.subtitle %][% subtitl.subfield %][% END %][% END %] [% IF ( bibitemloo.author ) %], by [% bibitemloo.author %][% END %] @@ -490,6 +499,7 @@ [% END %] [% END %] [% END %] +
[% END %]
-- 1.7.10.4