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)
const header = taskTemplate.cloneNode(true)
header.setAttribute('role','ett-header')
const ettTotal = header.querySelector('.ett-task-total')
const subHeader = taskTemplate.cloneNode(true)
subHeader.setAttribute('role','ett-subheader')
ettDate.value = ettConfig.date
// add tasks
for ( let t=1; t<=ettConfig.numTasks; t++ ) {
// new header
if ( t == 1 ) {
// add top header - just a specially formatted task
header.classList.add('task-header')
// header title
let headerInput = header.querySelector('.ett-task-name input')
headerInput.value = 'THE MAJOR TASKS FOR TODAY'
headerInput.setAttribute('readonly','readonly')
// header hours
let hoursContainer = header.querySelector('.ett-task-time')
hoursContainer.innerHTML = ''
for ( let h=0; h<ettConfig.numHours; h++ ) {
let newHour = hourTemplate.cloneNode(true)
let hour = ettConfig.startHour+h;
if ( hour > 12 ) {
hour = hour - 12
hour += "PM"
} else if ( hour == 12 ) {
hour += "PM"
} else {
hour += "AM"
// deepcode ignore DuplicateIfBody: <please specify a reason of ignoring this>, deepcode ignore DuplicateIfBody: <please specify a reason of ignoring this>, deepcode ignore DuplicateIfBody: <please specify a reason of ignoring this>
}
newHour.innerHTML = hour
let newBreak = hourBreakTemplate.cloneNode(true)
hoursContainer.appendChild(newBreak)
hoursContainer.appendChild(newHour)
}
let newBreak = hourBreakTemplate.cloneNode(true)
hoursContainer.appendChild(newBreak)
header.setAttribute('id','task-header')
header.setAttribute('data-date',ettConfig.date)
ettTaskContainer.appendChild(header)
// new sub-header
} else if ( t == (ettConfig.numMajor+1) ) {
// add sub header - just a specially formatted task
subHeader.classList.add('task-header')
// header title
let headerInput = subHeader.querySelector('.ett-task-name input')
headerInput.value = 'STUFF THAT "JUST HAPPENED"'
headerInput.setAttribute('readonly','readonly')
// header hours
let hoursContainer = subHeader.querySelector('.ett-task-time')
hoursContainer.innerHTML = ''
for ( let h=0; h<ettConfig.numHours; h++ ) {
let newHour = hourTemplate.cloneNode(true)
let hour = ettConfig.startHour+h;
if ( hour > 12 ) {
hour = hour - 12
hour += "PM"
} else if ( hour == 12 ) {
hour += "PM"
} else {
hour += "AM"
// deepcode ignore DuplicateIfBody: <please specify a reason of ignoring this>, deepcode ignore DuplicateIfBody: <please specify a reason of ignoring this>
}
newHour.innerHTML = hour
let newBreak = hourBreakTemplate.cloneNode(true)
hoursContainer.appendChild(newBreak)
hoursContainer.appendChild(newHour)
}
let newBreak = hourBreakTemplate.cloneNode(true)
hoursContainer.appendChild(newBreak)
subHeader.setAttribute('id','task-subheader')
subHeader.setAttribute('data-date',ettConfig.date)
ettTaskContainer.appendChild(subHeader)
}
// new emergent task
let newTask = taskTemplate.cloneNode(true)
let hourContainer = newTask.querySelector('.ett-task-time')
if ( t in ettConfig.tasks && ettConfig.tasks[t].name )
{
let taskName = newTask.querySelector('.ett-task-name input')
if ( taskName ) {
taskName.value = ettConfig.tasks[t].name
}
}
hourContainer.innerHTML = ''
for ( let hh=0; hh<ettConfig.numHours; hh++ ) {
let newHour = hourTemplate.cloneNode(true)
let h = ettConfig.startHour+hh;
let hourId = 'task-'+t+'-hour-'+h
newHour.setAttribute('id',hourId)
newHour.setAttribute('data-hour',h)
newHour.innerHTML = '';
for ( let b=0; b<4; b++ ) {
let m = (b+1)*15;
let newBubble = bubbleTemplate.cloneNode(true)
newBubble.setAttribute('id',hourId+'-minute-'+m)
newBubble.setAttribute('data-hour-index',b)
newBubble.setAttribute('data-task-index',(4*hh)+b)
if ( t in ettConfig.tasks &&
h in ettConfig.tasks[t].hours &&
m in ettConfig.tasks[t].hours[h] &&
ettConfig.tasks[t].hours[h][m] > 0 )
{
newBubble.setAttribute('data-time',ettConfig.tasks[t].hours[h][m])
}
newHour.appendChild(newBubble)
}
let newBreak = hourBreakTemplate.cloneNode(true)
hourContainer.appendChild(newBreak)
hourContainer.appendChild(newHour)
}
let newBreak = hourBreakTemplate.cloneNode(true)
hourContainer.appendChild(newBreak)
newTask.setAttribute('id','task-'+t)
let indexElement = newTask.querySelector('.ett-task-index')
if ( t < 10 ) {
indexElement.innerHTML = '0'+t
} else {
indexElement.innerHTML = t
}
newTask.setAttribute('data-date',ettConfig.date);
if ( t <= ettConfig.numMajor ) {
newTask.classList.add('ett-major-task')
}
ettTaskContainer.appendChild(newTask);