[% FILTER collapse %]
<script>
var debug = "[% debug | html %]";
- var dateformat_pref = "[% Koha.Preference('dateformat ') | html %]";
- var dateformat_string = "";
+ var dateformat_pref = "[% Koha.Preference('dateformat') | html %]";
var flatpickr_dateformat_string = "";
switch ( dateformat_pref ){
case "us":
- dateformat_string = "mm/dd/yy";
flatpickr_dateformat_string = "m/d/Y";
break;
case "metric":
- dateformat_string = "dd/mm/yy";
flatpickr_dateformat_string = "d/m/Y";
break;
case "dmydot":
- dateformat_string = "dd.mm.yy";
flatpickr_dateformat_string = "d.m.Y";
break;
default:
- dateformat_string = "yy-mm-dd";
flatpickr_dateformat_string = "Y-m-d";
}
var sentmsg = 0;
ShortcutButtonsPlugin({
button: [
{
- label: __("Yesterday")
+ label: _("Yesterday")
},
{
- label: __("Today")
+ label: _("Today")
},
{
- label: __("Tomorrow")
+ label: _("Tomorrow")
}
],
- label: __("or"),
+ label: _("or"),
onClick: (index, fp) => {
let date;
+ let hh = 23, mm = 59;
switch (index) {
case 0:
date = new Date().fp_incr(-1);
break;
case 1:
date = new Date();
+ if ( $(fp.input).data("flatpickr-pastinclusive") === true ) {
+ hh = date.getHours();
+ mm = date.getMinutes();
+ }
break;
case 2:
date = new Date().fp_incr(1);
break;
}
- date.setHours(23, 59, 0, 0);
+ date.setHours(hh, mm, 0, 0);
fp.setDate(date);
}
})
$(document).ready(function(){
$(".flatpickr").each(function(){
let options = {};
+ let refresh_max_date = 0;
+ let disable_buttons = [];
if( $(this).data("flatpickr-futuredate") === true ) {
let original_date = $(this).val();
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'] = "today";
+ 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;
options['dateFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
}
- $(this).flatpickr(options);
+ 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);
+ }
});
});
</script>