Ekapp/skolehjem/resources/js/calendar/calendar.js

158 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-06-25 06:28:36 +00:00
// class Calendar {
// constructor() {
//
// }
//
// nextMonth() {
//
// }
//
// previousMonth() {
//
// }
//
// addEvent() {
//
// }
//
// removeEvent() {
//
// }
// }
2020-06-25 11:20:47 +00:00
const moment = require("moment");
2020-06-26 08:52:26 +00:00
// const calendar = document.getElementById("calendar");
// const title = document.getElementById("month");
// calendar.innerHTML = "";
function generateCalendar(weekOffset = 0) {
const week = (moment().week() + weekOffset);
let weekDays = Array.apply(null, Array(7)).map((value, index) => {
return moment(index, "e").locale("da").startOf("week").weekday(index).format("ddd");
});
// weekDays.push(weekDays.shift());
// console.log(week);
// console.log(weekDays);
const calendar = document.getElementById("calendar");
let header = document.createElement("div");
header.classList.add("calendar-table__header", "calendar-table__row");
weekDays.forEach(function (weekDay) {
let headerDay = document.createElement("div");
headerDay.classList.add("calendar-table__col");
headerDay.innerText = weekDay;
header.appendChild(headerDay);
});
let calendarBody = document.createElement("div");
calendarBody.classList.add("calendar-table__body");
let calendarRow = document.createElement("div");
calendarRow.classList.add("calendar-table__row")
weekDays.forEach(function (value, index) {
let date = moment().locale("da").day(value).week(week);
// onDateSelect(date);
let dayHolder = document.createElement("div");
dayHolder.classList.add("calendar-table__col");
let day = document.createElement("div");
day.classList.add("calendar-table__item");
day.innerText = date.date();
dayHolder.appendChild(day);
dayHolder.onclick = function() {
onDateSelect(date);
}
calendarRow.appendChild(dayHolder);
});
calendarBody.appendChild(calendarRow);
calendar.innerHTML = "";
calendar.appendChild(header);
calendar.appendChild(calendarBody);
// const endWeek = moment().endOf("month").week();
// let cal = [];
// for (let week = startWeek; week < endWeek; week++) {
// cal.push({
// week : week,
// days : Array(7).fill(0).map((n, i) => moment().week(week).startOf("week").clone().add(n + i, "day"))
// });
// }
// console.log(cal);
}
// const eventArray = [
2020-06-25 11:20:47 +00:00
//
// ]
2020-06-26 08:52:26 +00:00
function onDateSelect(date) {
const events = document.getElementById("events");
2020-06-25 06:28:36 +00:00
2020-06-26 08:52:26 +00:00
events.innerHTML = "";
2020-06-25 06:28:36 +00:00
2020-06-26 08:52:26 +00:00
for (let hour = 8; hour <= 20; hour++) {
let option = document.createElement("option");
option.text = prependZero(hour);
2020-06-25 06:28:36 +00:00
2020-06-26 08:52:26 +00:00
// let item = document.createElement("li");
// item.classList.add("events__item");
//
// let itemData = document.createElement("div");
//
// let head = document.createElement("span");
// head.classList.add("events__name");
// head.innerText = "Vaskemaskine Tid";
//
// let dat = document.createElement("span");
// dat.classList.add("events__date");
// dat.innerText = "Klokken " + prependZero(hour);
//
// itemData.appendChild(head);
// itemData.appendChild(dat);
// item.appendChild(itemData);
//
// let button = document.createElement("span");
// button.classList.add("events__tag");
// button.innerText = "Book";
//
// item.appendChild(button);
//
// events.appendChild(item);
}
}
2020-06-25 06:28:36 +00:00
2020-06-26 08:52:26 +00:00
function prependZero(value) {
if(value < 10)
return "0" + value;
return value;
2020-06-25 06:28:36 +00:00
}
module.exports = {
2020-06-25 11:20:47 +00:00
generateCalendar
2020-06-25 06:28:36 +00:00
};