2020-06-25 11:20:47 +00:00
|
|
|
const moment = require("moment");
|
|
|
|
|
2020-06-26 08:52:26 +00:00
|
|
|
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-07-28 07:21:41 +00:00
|
|
|
calendarRow.id = "calenderRow";
|
2020-06-26 10:51:05 +00:00
|
|
|
|
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() {
|
2020-07-28 07:21:41 +00:00
|
|
|
onDateSelect(date, dayHolder);
|
2020-06-26 08:52:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-07-28 07:21:41 +00:00
|
|
|
function onDateSelect(date, dayHolder) {
|
2020-06-26 10:51:05 +00:00
|
|
|
let events;
|
|
|
|
let machinez;
|
2020-06-29 08:14:47 +00:00
|
|
|
let buttonz;
|
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-07-28 07:21:41 +00:00
|
|
|
NodeList.prototype.forEach = Array.prototype.forEach
|
|
|
|
var children = document.getElementById("calenderRow").childNodes;
|
|
|
|
|
|
|
|
children.forEach(function(item){
|
|
|
|
item.classList.remove("selected");
|
|
|
|
});
|
|
|
|
|
|
|
|
dayHolder.classList.add("selected");
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-06-29 08:14:47 +00:00
|
|
|
|
2020-07-28 12:26:32 +00:00
|
|
|
axios({
|
|
|
|
method: 'get',
|
|
|
|
url: '/washing-reservationsapi',
|
|
|
|
data: { date: date }
|
|
|
|
}).then(function (response) {
|
|
|
|
var data = response.data();
|
|
|
|
console.log(data);
|
|
|
|
});
|
2020-06-26 08:52:26 +00:00
|
|
|
|
2020-07-28 12:26:32 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'get',
|
|
|
|
url: "/washing-reservationsapi",
|
|
|
|
data: {'date': date},
|
|
|
|
success:function (data) {
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
/*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";
|
|
|
|
|
|
|
|
let select = document.createElement("select");
|
|
|
|
select.classList.add("events__title");
|
|
|
|
select.id = "washing-machines";
|
|
|
|
|
|
|
|
container.appendChild(span);
|
|
|
|
container.appendChild(select);
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
if(document.getElementById("create-reservation") != undefined)
|
|
|
|
buttonz = document.getElementById("create-reservation");
|
|
|
|
else {
|
|
|
|
let button = document.createElement("button");
|
|
|
|
|
|
|
|
button.id = "create-reservation";
|
|
|
|
button.innerText = "Reserver";
|
|
|
|
|
|
|
|
container.appendChild(button);
|
|
|
|
|
|
|
|
buttonz = document.getElementById("events");
|
|
|
|
}
|
|
|
|
|
|
|
|
const machines = [
|
|
|
|
"Maskine 1",
|
|
|
|
"Maskine 2"
|
|
|
|
]
|
|
|
|
|
|
|
|
machinez.innerHTML = "";
|
|
|
|
for (let i = 0; i < machines.length; i++) {
|
|
|
|
let option = document.createElement("option");
|
|
|
|
option.text = machines[i];
|
|
|
|
|
|
|
|
machinez.appendChild(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
events.innerHTML = "";
|
|
|
|
for (let hour = 8; hour <= 20; hour++) {
|
|
|
|
|
|
|
|
let option = document.createElement("option");
|
|
|
|
option.text = prependZero(hour);
|
|
|
|
|
|
|
|
events.appendChild(option);
|
|
|
|
}*/
|
|
|
|
},
|
|
|
|
error:function (data) {
|
|
|
|
console.log("FEJL");
|
|
|
|
console.log(data);
|
|
|
|
}
|
|
|
|
});
|
2020-06-26 08:52:26 +00:00
|
|
|
}
|
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
|
|
|
}
|