Bug 35000: Fix OPACMandatoryHoldDates feature in opac-reserve

Somewhere (perhaps after bug 29012) this feature has been broken
somehow.
The fact that we have two inputs for the date and the active one
is one level deeper, requires a few adjustments in the jquery
selectors etc. (Note that two Required lines were visible too.)
The corrected jquery constructs become a bit complexer now.

Test plan:
Enable AllowHoldDateInFuture + OPACAllowHoldDateInFuture.
Set circ rule for book to test with allows item level holds.
Set OPACMandatoryHoldDates to no hold dates.
Place hold on a book in OPAC. Check that More options is collapsed.
(If you force item level holds, it will open.)
Set OPACMandatoryHoldDates to Hold start date.
Refresh place hold page. More options is expanded now.
Click Place hold. You should see an alert and focus goes to start date.
Set OPACMandatoryHoldDates to Hold end date. Repeat place hold.
Set OPACMandatoryHoldDates to Both hold dates. Fill one. Place hold.
Bonus: Place hold on multiple biblios. Repeat former steps.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit cd7a8840d5)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Marcel de Rooy 2023-10-10 13:36:45 +02:00 committed by Fridolin Somers
parent d9d9587342
commit 28320fe33a
1 changed files with 12 additions and 15 deletions

View File

@ -293,6 +293,7 @@
<label for="from[% bibitemloo.biblionumber | html %]">Hold starts on date:</label>
<input type="text" name="reserve_date_[% bibitemloo.biblionumber | html %]" id="from[% bibitemloo.biblionumber | html %]" data-start_for="to[% bibitemloo.biblionumber | html %]" size="10" class="flatpickr holddatefrom" />
<span class="date-format from" data-biblionumber="[% bibitemloo.biblionumber | html %]">[% INCLUDE 'date-format.inc' %]</span>
<div class="required_label" style="display:none;">Required</div>
</li>
[% END %]
@ -300,6 +301,7 @@
<label for="to[% bibitemloo.biblionumber | html %]">Hold not needed after:</label>
<input type="text" name="expiration_date_[% bibitemloo.biblionumber | html %]" id="to[% bibitemloo.biblionumber | html %]" size="10" class="flatpickr futuredate" />
<span class="date-format to" data-biblionumber="[% bibitemloo.biblionumber | html %]">[% INCLUDE 'date-format.inc' %]</span>
<div class="required_label" style="display:none;">Required</div>
</li>
[% IF Koha.Preference('AllowHoldItemTypeSelection') %]
@ -519,16 +521,11 @@
$(".toggle-hold-options").show();
$(".hold-options").hide();
var OPACMandatoryHoldDates = "[% Koha.Preference('OPACMandatoryHoldDates') | html %]";
var requiredDiv = "<div class=\"required_label required\">" + _("Required") + "</div>";
if( OPACMandatoryHoldDates ) {
if( OPACMandatoryHoldDates == "start" || OPACMandatoryHoldDates == "both" ) {
$(".holddatefrom").prop( 'required', true );
$(".holddatefrom").parent().append(requiredDiv);
}
if( OPACMandatoryHoldDates == "end" || OPACMandatoryHoldDates == "both" ) {
$(".futuredate").prop( 'required', true );
$(".futuredate").parent().append(requiredDiv);
}
if( OPACMandatoryHoldDates == "start" || OPACMandatoryHoldDates == "both" ) {
$(".holddatefrom").prop( 'required', true ).siblings(".required_label").addClass('required').show();
}
if( OPACMandatoryHoldDates == "end" || OPACMandatoryHoldDates == "both" ) {
$(".futuredate").prop( 'required', true ).siblings(".required_label").addClass('required').show();
}
$(".checkitem").parent().click(function(e){
@ -564,7 +561,7 @@
[% FOREACH bibitemloo IN bibitemloop %]
[% IF bibitemloo.force_hold %]
if( $("#to[% bibitemloo.biblionumber | html %]:hidden").length )
if( $("#to[% bibitemloo.biblionumber | html %]").parent(":hidden").length )
$("#toggle-hold-options-[% bibitemloo.biblionumber | html %]").click();
$("#reqspecific_[% bibitemloo.biblionumber | html %]").click();
$("#copiesrow_[% bibitemloo.biblionumber | html %]").show();
@ -676,14 +673,14 @@
if( $(".holddatefrom").prop('required') && $("#from"+ biblioNum).val() == '' ) {
alert(MSG_EMPTY_START_DATE);
badBib = biblioNum;
if( $("#from"+biblioNum+":hidden").length ) $("#toggle-hold-options-"+biblioNum).click();
$("#from"+ biblioNum).focus();
if( $("#from"+biblioNum).parent(":hidden").length ) $("#toggle-hold-options-"+biblioNum).trigger('click');
$("#from"+biblioNum).siblings('.flatpickr_wrapper').find('.flatpickr-input').trigger('focus');
return false;
} else if( $(".futuredate").prop('required') && $("#to"+ biblioNum).val() == '' ) {
alert(MSG_EMPTY_END_DATE);
badBib = biblioNum;
if( $("#to"+biblioNum+":hidden").length ) $("#toggle-hold-options-"+biblioNum).click();
$("#to"+ biblioNum).focus();
if( $("#to"+biblioNum).parent(":hidden").length ) $("#toggle-hold-options-"+biblioNum).trigger('click');
$("#to"+biblioNum).siblings('.flatpickr_wrapper').find('.flatpickr-input').trigger('focus');
return false;
}