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);
|
2020-06-26 11:07:57 +00:00
|
|
|
|
|
|
|
document.getElementById("title").innerText = week;
|
|
|
|
|
2020-06-26 08:52:26 +00:00
|
|
|
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");
|
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
let calendarBody = document.createElement("div");
|
|
|
|
calendarBody.classList.add("calendar-table__body");
|
|
|
|
|
|
|
|
let calendarRow = document.createElement("div");
|
|
|
|
calendarRow.classList.add("calendar-table__row")
|
|
|
|
|
2020-06-26 08:52:26 +00:00
|
|
|
weekDays.forEach(function (weekDay) {
|
|
|
|
let headerDay = document.createElement("div");
|
|
|
|
headerDay.classList.add("calendar-table__col");
|
|
|
|
|
|
|
|
headerDay.innerText = weekDay;
|
|
|
|
|
|
|
|
header.appendChild(headerDay);
|
|
|
|
|
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
let date = moment().locale("da").day(weekDay).week(week);
|
2020-06-26 08:52:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2020-06-26 10:51:05 +00:00
|
|
|
}
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
function onDateSelect(date) {
|
|
|
|
let events;
|
|
|
|
let machinez;
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
let container = document.getElementById("event-container");
|
2020-06-26 08:52:26 +00:00
|
|
|
|
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
if(document.getElementById("washing-machines") != undefined)
|
|
|
|
machinez = document.getElementById("washing-machines");
|
|
|
|
else {
|
|
|
|
let span = document.createElement("span");
|
|
|
|
span.classList.add("events__title");
|
|
|
|
span.innerText = "Maskiner";
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
let select = document.createElement("select");
|
|
|
|
select.classList.add("events__title");
|
|
|
|
select.id = "washing-machines";
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
container.appendChild(span);
|
|
|
|
container.appendChild(select);
|
2020-06-25 11:20:47 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
machinez = document.getElementById("washing-machines");
|
|
|
|
}
|
|
|
|
if(document.getElementById("events") != undefined)
|
|
|
|
events = document.getElementById("events");
|
|
|
|
else {
|
|
|
|
let span = document.createElement("span");
|
|
|
|
span.classList.add("events__title");
|
|
|
|
span.innerText = "Tider";
|
|
|
|
|
|
|
|
let select = document.createElement("select");
|
|
|
|
select.classList.add("events__title");
|
|
|
|
select.id = "events";
|
|
|
|
|
|
|
|
container.appendChild(span);
|
|
|
|
container.appendChild(select);
|
|
|
|
|
|
|
|
events = document.getElementById("events");
|
|
|
|
}
|
|
|
|
|
|
|
|
// events.innerHTML = "";
|
|
|
|
|
|
|
|
const machines = [
|
|
|
|
"Maskine 1",
|
|
|
|
"Maskine 2"
|
|
|
|
]
|
|
|
|
|
|
|
|
for (let i = 0; i < machines.length; i++) {
|
|
|
|
let option = document.createElement("option");
|
|
|
|
option.text = machines[i];
|
2020-06-25 06:28:36 +00:00
|
|
|
|
2020-06-26 10:51:05 +00:00
|
|
|
machinez.appendChild(option);
|
|
|
|
}
|
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-26 10:51:05 +00:00
|
|
|
events.appendChild(option);
|
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
|
|
|
};
|