46HRD6U467C6H7IRDKDLCBBBMHA2HUCQXNAXY6PRDQT6OYCIAZZAC
this.data = JSON.parse(JSON.stringify(this.defaultData))
/// pull ETT container elements out of the DOM
this.ettDate = document.getElementById('ett-date')
this.ettTaskContainer = document.getElementById('ett-tasks')
this.ettTemplate = document.getElementById('ett-task-template')
this.taskTemplate = this.ettTemplate.content.firstElementChild.cloneNode(true)
this.hourBreakTemplate = this.taskTemplate.querySelector('.bubble-hour-break').cloneNode(true)
this.hourTemplate = this.taskTemplate.querySelector('.bubble-hour').cloneNode(true)
this.bubbleTemplate = this.taskTemplate.querySelector('.bubble-15m').cloneNode(true)
const taskTemplate = ettTemplate.content.firstElementChild.cloneNode(true)
const hourBreakTemplate = taskTemplate.querySelector('.bubble-hour-break').cloneNode(true)
const hourTemplate = taskTemplate.querySelector('.bubble-hour').cloneNode(true)
const bubbleTemplate = taskTemplate.querySelector('.bubble-15m').cloneNode(true)
self.ettTaskContainer.innerHTML = '';
/// DATE PICKER
const calPopup = document.querySelector('#ett-date');
const datepicker = new Datepicker(calPopup, {
format: 'yyyy-mm-dd'
});
calPopup.addEventListener('focus',ev => {
let dp = ev.target.parentNode.querySelector('.datepicker')
dp.style.marginLeft = '-128px';
dp.style.left = '50%';
})
}
/// PERSISTENCE
document.addEventListener('persist',ev => {
self.data.tasks = {}
let ettTasks = ettTaskContainer.querySelectorAll('[role=ett-task]')
ettTasks.forEach( (ettTaskElement, t) => {
self.data.tasks[t] = ettTaskElement.ett.toPersist()
});
let date = self.data.date || new Date().toLocaleDateString('en-CA')
storage.set(date,self.data)
console.log('PERSIST')
})
this.renderDate = ev => {
console.log('changeDate self.ettDate: ', self.ettDate.value)
let ettDayData = storage.get(self.ettDate.value)
if ( ettDayData && 'date' in ettDayData ) {
console.log('good date: ', self.ettDate.value, ettDayData)
self.data = ettDayData
} else {
console.log('bad date: ', self.ettDate.value)
self.data = JSON.parse(JSON.stringify(this.defaultData))
}
self.data.date = self.ettDate.value
self.render()
/// PERSISTENCE
document.addEventListener('persist',ev => {
self.data.tasks = {}
let ettTasks = self.ettTaskContainer.querySelectorAll('[role=ett-task]')
ettTasks.forEach( (ettTaskElement, t) => {
self.data.tasks[t] = ettTaskElement.ett.toPersist()
});
let date = self.data.date || new Date().toLocaleDateString('en-CA')
storage.set(date,self.data)
console.log('PERSIST',date,self.data)
})
/// SETUP CAL PICKER
const calPopup = document.querySelector('#ett-date');
const datepicker = new Datepicker(calPopup, {
format: 'yyyy-mm-dd'
});
calPopup.addEventListener('focus', ev => {
let dp = ev.target.parentNode.querySelector('.datepicker')
dp.style.marginLeft = '-128px';
dp.style.left = '50%';
})