Lines 134-146
Link Here
|
134 |
} |
134 |
} |
135 |
|
135 |
|
136 |
$(document).ready(function(){ |
136 |
$(document).ready(function(){ |
137 |
$(".flatpickr").flatpickr(); |
137 |
$(".flatpickr").each(function(){ |
|
|
138 |
let options = {}; |
139 |
let refresh_max_date = 0; |
140 |
let disable_buttons = []; |
138 |
|
141 |
|
139 |
$(".clear-flatpickr").on("click", function(e){ |
142 |
if( $(this).data("flatpickr-futuredate") === true ) { |
140 |
e.preventDefault(); |
143 |
let original_date = $(this).val(); |
141 |
var element = $(this).data("fp"); |
144 |
if ( original_date ) { |
142 |
if( element ){ |
145 |
original_date = Date_from_syspref( original_date ).getTime(); |
143 |
document.querySelector("#" + element )._flatpickr.clear(); |
146 |
let tomorrow = new Date().fp_incr(1).getTime(); |
|
|
147 |
|
148 |
options['enable'] = [function(date){ |
149 |
date = date.getTime(); |
150 |
if ( date == original_date ) return true; |
151 |
if ( date >= tomorrow) return true; |
152 |
}]; |
153 |
} |
154 |
else { |
155 |
options['minDate'] = new Date().fp_incr(1); |
156 |
} |
157 |
disable_buttons.push(0); /* Yesterday */ |
158 |
disable_buttons.push(1); /* Today */ |
159 |
} |
160 |
if( $(this).data("flatpickr-pastinclusive") === true ) { |
161 |
options['maxDate'] = new Date(); /* Not today or hh:mm will be 00:00 */ |
162 |
refresh_max_date = 1; |
163 |
disable_buttons.push(2); /* Tomorrow */ |
164 |
} |
165 |
if( $(this).data("flatpickr-pastdate") === true ) { |
166 |
options['maxDate'] = new Date().fp_incr(-1).setHours(23, 59, 00, 00); |
167 |
disable_buttons.push(1); /* Today */ |
168 |
disable_buttons.push(2); /* Tomorrow */ |
169 |
} |
170 |
if ( $(this).data('flatpickr-enable-time') === true ) { |
171 |
options['enableTime'] = true; |
172 |
options['dateFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string; |
173 |
} |
174 |
|
175 |
let fp = $(this).flatpickr(options); |
176 |
|
177 |
$(disable_buttons).each(function(index, value){ |
178 |
$(fp.calendarContainer).find(".shortcut-buttons-flatpickr-button[data-index='"+value+"']").prop("disabled", "disabled"); |
179 |
}); |
180 |
|
181 |
if ( refresh_max_date ) { |
182 |
/* Refresh the maxDate every 30 secondes to make sure the user will not |
183 |
be stuck with the minute passed. |
184 |
Adding 1 minute to not introduce a gap. |
185 |
Example: last update at 40s, a new minute passed at 00. |
186 |
Between 00 and 10s the user won't be able click 'Today'. |
187 |
*/ |
188 |
setInterval(() => { |
189 |
let now = new Date(); |
190 |
fp.set("maxDate", now.setMinutes(now.getMinutes() + 1)); |
191 |
}, 30000); |
144 |
} |
192 |
} |
145 |
}); |
193 |
}); |
146 |
}); |
194 |
}); |