Bugzilla – Attachment 138403 Details for
Bug 31262
Curbside pickups - disable dates without slots
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31262: Disable dates in the past for curbside pickups
Bug-31262-Disable-dates-in-the-past-for-curbside-p.patch (text/plain), 6.43 KB, created by
Jonathan Druart
on 2022-07-31 06:35:46 UTC
(
hide
)
Description:
Bug 31262: Disable dates in the past for curbside pickups
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-07-31 06:35:46 UTC
Size:
6.43 KB
patch
obsolete
>From a448290f2a00da129f58e7e351db13ca9381d7d0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Sun, 31 Jul 2022 08:29:41 +0200 >Subject: [PATCH] Bug 31262: Disable dates in the past for curbside pickups > >When creating a new pickup the dates in the past won't display any >available slots. It would be better to disable them in the date picker. > >Test plan: >Setup curbside pickups for your library (see bug 30650 test plan if >needed) >Create a new pickup (staff and OPAC) and confirm that the date picker widget >has the dates in the past disabled. > >QA note: More work would be needed to sync calendar.inc code between >OPAC and staff. Also note that the "clear date" code wasn't needed >(please confirm). > >Sponsored-by: Association KohaLa - https://koha-fr.org/ >--- > .../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(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >index 5f485e9b720..9d70130403f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt >@@ -472,7 +472,7 @@ > > <li> > <label for="pickup_date">Pickup date: </label> >- <input id="pickup_date" name="pickup_date" required="required" class="flatpickr" /> >+ <input id="pickup_date" name="pickup_date" required="required" class="flatpickr" data-flatpickr-futuredate="true" /> > </li> > > <li id="pickup-times" class="radio"></li> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >index 1ef4ffb6111..a2e5189fe6b 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >@@ -134,13 +134,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); > } > }); > }); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >index f20786b052b..6c921f7f372 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt >@@ -185,7 +185,7 @@ > </li> > <li> > <label for="pickup_date">Pickup date:</label> >- <input name="pickup_date" type="text" class="flatpickr" id="pickup-date" disabled required="required"/> >+ <input name="pickup_date" type="text" class="flatpickr" id="pickup-date" disabled required="required" data-flatpickr-futuredate="true" /> > <span class="required">Required</span> > </li> > >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31262
:
138403
|
143211
|
143212
|
143294
|
143610