@@ -, +, @@
---
.../prog/en/modules/circ/curbside_pickups.tt | 2 +-
.../bootstrap/en/includes/calendar.inc | 60 +++++++++++++++++--
.../en/modules/opac-curbside-pickups.tt | 2 +-
3 files changed, 56 insertions(+), 8 deletions(-)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt
@@ -476,7 +476,7 @@
-
+
--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc
@@ -136,13 +136,61 @@
}
$(document).ready(function(){
- $(".flatpickr").flatpickr();
+ $(".flatpickr").each(function(){
+ let options = {};
+ let refresh_max_date = 0;
+ let disable_buttons = [];
- $(".clear-flatpickr").on("click", function(e){
- e.preventDefault();
- var element = $(this).data("fp");
- if( element ){
- document.querySelector("#" + element )._flatpickr.clear();
+ if( $(this).data("flatpickr-futuredate") === true ) {
+ let original_date = $(this).val();
+ if ( original_date ) {
+ original_date = Date_from_syspref( original_date ).getTime();
+ let tomorrow = new Date().fp_incr(1).getTime();
+
+ options['enable'] = [function(date){
+ date = date.getTime();
+ if ( date == original_date ) return true;
+ if ( date >= tomorrow) return true;
+ }];
+ }
+ else {
+ options['minDate'] = new Date().fp_incr(1);
+ }
+ disable_buttons.push(0); /* Yesterday */
+ disable_buttons.push(1); /* Today */
+ }
+ 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).setHours(23, 59, 00, 00);
+ disable_buttons.push(1); /* Today */
+ disable_buttons.push(2); /* Tomorrow */
+ }
+ if ( $(this).data('flatpickr-enable-time') === true ) {
+ options['enableTime'] = true;
+ options['dateFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
+ }
+
+ let fp = $(this).flatpickr(options);
+
+ $(disable_buttons).each(function(index, value){
+ $(fp.calendarContainer).find(".shortcut-buttons-flatpickr-button[data-index='"+value+"']").prop("disabled", "disabled");
+ });
+
+ if ( refresh_max_date ) {
+ /* Refresh the maxDate every 30 secondes to make sure the user will not
+ be stuck with the minute passed.
+ Adding 1 minute to not introduce a gap.
+ Example: last update at 40s, a new minute passed at 00.
+ Between 00 and 10s the user won't be able click 'Today'.
+ */
+ setInterval(() => {
+ let now = new Date();
+ fp.set("maxDate", now.setMinutes(now.getMinutes() + 1));
+ }, 30000);
}
});
});
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt
@@ -243,7 +243,7 @@
-
+
Required
--