in webui/js/source/datepicker.js [569:676]
function drawCalendarPicker(obj, date) {
obj.focus()
// Default to NOW for calendar.
let now = new Date()
// if called with an existing date (YYYY-MM-DD),
// convert it to a JS date object and use that for
// rendering the calendar
if (date) {
let ar = date.split(/-/)
now = new Date(ar[0], parseInt(ar[1]) - 1, ar[2])
}
let mat = now
// Go to first day of the month
mat.setDate(1)
obj.innerHTML = "<h3>" + MONTHS[mat.getMonth()] + ", " + mat.getFullYear() + ":</h3>"
let tm = mat.getMonth()
// -- Nav buttons --
// back-a-year button
let a = document.createElement('a')
fixupPicker(a)
a.setAttribute("onclick", "drawCalendarPicker(this.parentNode, '" + (mat.getFullYear() - 1) + '-' + (mat.getMonth() + 1) + '-' + mat.getDate() + "');")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("class", "glyphicon glyphicon-fast-backward");
obj.appendChild(a)
// back-a-month button
a = document.createElement('a')
fixupPicker(a)
a.setAttribute("onclick", "drawCalendarPicker(this.parentNode, '" + mat.getFullYear() + '-' + (mat.getMonth()) + '-' + mat.getDate() + "');")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("class", "glyphicon glyphicon-step-backward");
obj.appendChild(a)
// forward-a-month button
a = document.createElement('a')
fixupPicker(a)
a.setAttribute("onclick", "drawCalendarPicker(this.parentNode, '" + mat.getFullYear() + '-' + (mat.getMonth() + 2) + '-' + mat.getDate() + "');")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("class", "glyphicon glyphicon-step-forward");
obj.appendChild(a)
// forward-a-year button
a = document.createElement('a')
fixupPicker(a)
a.setAttribute("onclick", "drawCalendarPicker(this.parentNode, '" + (mat.getFullYear() + 1) + '-' + (mat.getMonth() + 1) + '-' + mat.getDate() + "');")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("class", "glyphicon glyphicon-fast-forward");
obj.appendChild(a)
obj.appendChild(document.createElement('br'))
// Table containing the dates of the selected month
let table = document.createElement('table')
table.setAttribute("border", "1")
table.style.margin = "0 auto"
// Add header day names
let tr = document.createElement('tr');
for (let m = 0; m < 7; m++) {
let td = document.createElement('th')
td.innerHTML = DAYS_SHORTENED[m]
tr.appendChild(td)
}
table.appendChild(tr)
// Until we hit the first day in a month, add blank days
tr = document.createElement('tr');
let weekday = mat.getDay()
if (weekday == 0) {
weekday = 7
}
weekday--;
for (let i = 0; i < weekday; i++) {
let td = document.createElement('td')
tr.appendChild(td)
}
// While still in this month, add day then increment date by 1 day.
while (mat.getMonth() == tm) {
weekday = mat.getDay()
if (weekday == 0) {
weekday = 7
}
weekday--;
if (weekday == 0) {
table.appendChild(tr)
tr = document.createElement('tr');
}
let td = document.createElement('td')
// onclick for setting the calendarPicker's parent to this val.
td.setAttribute("onclick", "setCalendarDate('" + mat.getFullYear() + '-' + (mat.getMonth() + 1) + '-' + mat.getDate() + "');")
td.innerHTML = mat.getDate()
mat.setDate(mat.getDate() + 1)
tr.appendChild(td)
}
table.appendChild(tr)
obj.appendChild(table)
}