weiter gehts

This commit is contained in:
rxf
2023-05-01 18:49:46 +02:00
parent 32bf325a68
commit 0e6563bc4e
3 changed files with 61 additions and 19 deletions

View File

@@ -1,14 +1,16 @@
document.addEventListener('DOMContentLoaded', async function () {
const DateTime = luxon.DateTime;
const filename = 'data/data.json'
let curdate = ''
const dt = DateTime.now()
const dt1 = dt.plus({month:1})
curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL y')}`
document.querySelector('#curmon').innerHTML = curdate
curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL_y')}`
document.querySelector('#curmon').innerHTML = curdate.replace('_',' ')
let ret = await getData(filename)
// initSchema('2023-05-01')
let ret = await getData()
fillSchema(ret.data)
document.querySelector('#sptab').addEventListener('click', markField);
@@ -17,9 +19,7 @@ document.addEventListener('DOMContentLoaded', async function () {
let field = e.target;
field.setAttribute('aria-label','x');
field.setAttribute('disabled','disabled');
let lastDate = parseInt(field.innerHTML)
let month = curdate.split('/')[0]
let data = {curdate: curdate.slice(0, -5), last: lastDate}
let data = {curdate: curdate}
let setArray = []
let fields = document.querySelectorAll('#sptab button')
for (i = 0; i < fields.length; i++) {
@@ -31,22 +31,24 @@ document.addEventListener('DOMContentLoaded', async function () {
}
data.data = setArray
storeData(data)
if (e.srcElement.id === 'bt35') {
showNextMonth(e.srcElement.innerHTML)
}
}
function fillSchema(data) {
const setArray = data.data
for(let i = 1, k = 1; i < 36; i++, k++) {
if (i === 18) {
i++
}
let sel = '#bt'+i
if(setArray[0].day === 'undefined') {
document.querySelector(sel).innerHTML = k
for(let i = 0; i < 35; i++) {
let sel = '#bt'+(i+1)
let day = DateTime.fromISO(setArray[i].day).toFormat('d')
document.querySelector(sel).setAttribute('innerHTML', day)
if (setArray[i].day !== '') {
if (setArray[i].status) {
document.querySelector(sel).setAttribute('aria-label', 'x')
document.querySelector(sel).setAttribute('disabled', 'disabled')
}
} else {
document.querySelector(sel).innerHTML = setArray[i-1].day
}
if(setArray[i-1].status) {
document.querySelector(sel).setAttribute('aria-label', 'x')
document.querySelector(sel).setAttribute('disabled', 'disabled')
}
}
}
@@ -67,4 +69,30 @@ document.addEventListener('DOMContentLoaded', async function () {
return response.json()
}
function showNextMonth() {
const dt = DateTime.now()
const dt1 = dt.plus({month:1})
curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL_y')}`
document.querySelector('#curmon').innerHTML = curdate.replace('_',' ')
fillSchema(ret.data)
}
function initSchema(startdate) {
let setArray = []
let ld0 = DateTime.fromISO(startdate)
for(let i = 0; i < 35; i++) {
let elem = {status: false}
if (i === 17) {
elem.day = ''
} else {
let ld = ld0.plus({day: i})
elem.day = ld.toFormat('y-LL-dd')
}
setArray.push(elem)
}
let data = {curdate: startdate, data: setArray}
storeData(data)
}
});