Koha/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
Jonathan Druart 44ddbf8ec7 Bug 29241: Allow display of past date for .futuredate
When a past date is set for a flatpickr instance with the .futuredate
class, only dates in the future are available AND the input is blanked.
It does not display the date in the past.

For instance if a hold is expired (expirationdate in the past), the date input will be blanked.

We can use the flatpickr's allowInvalidPreload option to allow date in the past to be displayed.

Test plan:
Place a hold
Edit its expirationdate and set a date in the past (yesterday is fine)
Go to /reserve/request.pl?biblionumbers=42
=> With the patch you see the date, and the widget let you chose anoter date,
in the future
=> Without this patch the expiration date is not displayed

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-10-25 13:56:30 +02:00

78 lines
3.5 KiB
PHP

[% USE Asset %]
[% USE Koha %]
[% USE raw %]
<!-- calendar.inc -->
[% FILTER collapse %]
<script>
var debug = "[% debug | html %]";
var dateformat_pref = "[% Koha.Preference('dateformat ') | html %]";
var dateformat_string = [% IF ( dateformat == "us" ) %]"mm/dd/yy"[% ELSIF ( dateformat == "metric" ) %]"dd/mm/yy"[% ELSIF ( dateformat == "dmydot" ) %]"dd.mm.yy"[% ELSE %]"yy-mm-dd"[% END %];
var flatpickr_dateformat_string = [% IF ( dateformat == "us" ) %]"m/d/Y"[% ELSIF ( dateformat == "metric" ) %]"d/m/Y"[% ELSIF ( dateformat == "dmydot" ) %]"d.m.Y"[% ELSE %]"Y-m-d"[% END %];
var sentmsg = 0;
var bidi = [% IF(bidi) %] true[% ELSE %] false[% END %];
var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
var flatpickr_timeformat_string = [% IF Koha.Preference('TimeFormat') == '12hr' %]"G:i K"[% ELSE %]"H:i"[% END %];
var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
</script>
<!-- / calendar.inc -->
[% Asset.js("js/calendar.js") | $raw %]
[% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
<script>
flatpickr.l10ns.default.weekdays = flatpickr_weekdays;
flatpickr.l10ns.default.months = flatpickr_months;
flatpickr.setDefaults({
allowInput: true,
dateFormat: flatpickr_dateformat_string,
nextArrow: '<i class="fa fa-fw fa-arrow-right"></i>',
prevArrow: '<i class="fa fa-fw fa-arrow-left"></i>',
time_24hr: flatpickr_timeformat,
locale: {
"firstDayOfWeek": calendarFirstDayOfWeek
},
onReady: function( selectedDates, dateStr, instance ){
/* When flatpickr instance is created, automatically append a "clear date" link */
$(instance.input)
/* Add a wrapper element so that we can prevent the clear button from wrapping */
.wrap("<span class='flatpickr_wrapper'></span>")
.after( $("<a/>")
.attr("href","#")
.addClass("clear_date")
.on("click", function(e){
e.preventDefault();
instance.clear();
})
.addClass("fa fa-fw fa-remove")
.attr("aria-hidden", true)
.attr("aria-label", _("Clear date") )
).keydown(function(e) {
var key = (event.keyCode ? event.keyCode : event.which);
if ( key == 40 ) {
instance.set('allowInput',false);
}
});
},
onClose: function( selectedDates, dateText, instance) {
validate_date( dateText, instance );
var thisInput = instance.input;
if ( thisInput.hasAttribute('data-date_to') ) {
var endPicker = document.querySelector("#"+thisInput.dataset.date_to)._flatpickr;
endPicker.set('minDate', selectedDates[0]);
}
},
});
$(document).ready(function(){
$(".flatpickr").each(function(){
let options = {};
if( $(this).hasClass("futuredate") ) {
options['minDate'] = new Date().fp_incr(1);
options['allowInvalidPreload'] = true;
}
if( $(this).hasClass("pastdate") ) {
options['maxDate'] = new Date().fp_incr(-1);
}
$(this).flatpickr(options);
});
});
</script>
[% END %]