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