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