From 1f49a49554ad90eb6c07f0afb21e788e71bf5f09 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Nov 2021 14:17:09 +0100 Subject: [PATCH] Bug 29552: Flatpickr - Disable shortcut buttons if inactive If one of the buttons is not relevant we should disable it and mark is as such on the interface. Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 2805870d10..8d3f4ee4ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -127,6 +127,7 @@ $(".flatpickr").each(function(){ let options = {}; let refresh_max_date = 0; + let disable_buttons = []; if( $(this).data("flatpickr-futuredate") === true ) { let original_date = $(this).val(); @@ -143,13 +144,17 @@ else { options['minDate'] = new Date().fp_incr(1); } + disable_buttons.push(0); /* Yesterday */ } if( $(this).data("flatpickr-pastinclusive") === true ) { options['maxDate'] = new Date(); /* Not today or hh:mm will be 00:00 */ refresh_max_date = 1; + disable_buttons.push(2); /* Tomorrow */ } if( $(this).data("flatpickr-pastdate") === true ) { options['maxDate'] = new Date().fp_incr(-1); + disable_buttons.push(1); /* Today */ + disable_buttons.push(2); /* Tomorrow */ } if ( $(this).data('flatpickr-enable-time') === true ) { options['enableTime'] = true; @@ -157,6 +162,11 @@ } let fp = $(this).flatpickr(options); + + $(disable_buttons).each(function(index, value){ + $(fp.calendarContainer).find(".shortcut-buttons-flatpickr-button[data-index='"+value+"']").prop("disabled", "disabled").css("color", "#999"); + }); + if ( refresh_max_date ) { /* Refresh the maxDate every 30 secondes to make sure the user will not be stuck with the minute passed. -- 2.11.0