DTpicker update

This commit is contained in:
Tom Hubrecht 2021-06-09 20:55:27 +02:00
parent 5afe2df78c
commit 9e37b9f0ae

View file

@ -39,6 +39,7 @@ class DateTimePicker {
this.target.addEventListener('click', () => {
document.documentElement.classList.add('is-clipped');
this.modal.classList.add('is-active');
this.target.blur();
});
if (!['fr', 'en'].includes(config.lang)) {
@ -86,19 +87,19 @@ class DateTimePicker {
} else {
this._beginning.setMonth(this._beginning.getMonth() - 1, 1);
}
case 'months':
this._beginning.setFullYear(this._beginning.getFullYear() - 1);
break;
break;
case 'months':
this._beginning.setFullYear(this._beginning.getFullYear() - 1);
break;
}
this.refreshView();
});
this._menu.addEventListener('click', () => {
let _index = DateTimePicker.views.indexOf(this._view);
_index = Math.min(2, _index + 1);
this._view = DateTimePicker.views[_index];
this.refreshView();
console.log(this._view, _index);
if (this._view == 'days') {
this._view = 'months';
this.refreshView();
}
});
let _selects = this.modal.querySelectorAll('footer select');
@ -147,11 +148,11 @@ class DateTimePicker {
// Création du tableau
const _dayLength = 86400000;
var day = new Date(_beginning.getTime() - _dayLength * ((_beginning.getDay() + 6) % 7));
let day = new Date(_beginning.getTime() - _dayLength * ((_beginning.getDay() + 6) % 7));
const _tbody = _body.querySelector('tbody');
for (let i = 0; i < 6; i++) {
if (i == 0 || day.getMonth() <= _beginning.getMonth()) {
if (i == 0 || (day.getMonth() <= _beginning.getMonth()) && day.getFullYear() <= _beginning.getFullYear()) {
let row = document.createElement('tr');
for (let j = 0; j < 7; j++) {
let cell = document.createElement('td');
@ -197,7 +198,7 @@ class DateTimePicker {
const months = _months[this.config.lang];
this._menu.innerHTML = `<b>${_beginning.getFullYear()}</b>`;
var _body = this.modal.querySelector('.modal-card section .column');
let _body = this.modal.querySelector('.modal-card section .column');
_body.innerHTML = `<table class="table"><tbody></tbody></table>`;
const _tbody = _body.querySelector('tbody');
@ -259,7 +260,7 @@ class DateTimePicker {
}
static dateValue(value) {
let _real = new Date(value.getTime() - 60000 * value.getTimezoneOffset());
const _real = new Date(value.getTime() - 60000 * value.getTimezoneOffset());
return _real.toISOString().replace('T', ' ').replace(/:\d{2}\.\d{3}Z/, '');
}