Commit 0fc2ac6d authored by uoure's avatar uoure
Browse files

Delete scripts.js

parent 14a53971
var select = new Object();
var reservationData;
function onLoad() {
resetSelection();
disableJSInfo();
loadOpeningDates();
initCanvasClickListener();
}
function resetSelection() {
select.startH = -1;
select.endH = -1;
}
function disableJSInfo() {
document.getElementById("js-info").style.display = "none";
}
function loadOpeningDates() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var dropdown = document.getElementById("reservationDate")
var data = JSON.parse(this.responseText);
data.forEach(function(date) {
var option = document.createElement("option");
option.text = date;
dropdown.add(option);
});
loadReservations();
}
};
xhttp.open("GET", "getOpeningDates.php", true);
xhttp.send();
}
function loadReservations() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
reservationData = JSON.parse(this.responseText);
document.getElementById("eventNameField").innerHTML = reservationData["event"];
resetSelection();
updateCanvas();
}
};
xhttp.open("GET", "getReservations.php?date=" + document.getElementById("reservationDate").value, true);
xhttp.send();
}
function updateCanvas() {
var openTime = reservationData.open.split(':');
var closeTime = reservationData.close.split(':');
var canvas = document.getElementById("reservations");
var ctx = canvas.getContext('2d');
canvas.width = (closeTime[0] - openTime[0]) * 2 * 25 + (closeTime[1] - openTime[1]) / 30 * 25 + 30;
ctx.canvas.height = reservationData.tables * 80 + 30;
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i=1; i <= reservationData.tables; i++) {
drawTableUsage(ctx, i, openTime, closeTime, reservationData.reservations["T" + i]);
}
}
function drawTableUsage(ctx, tablenr, openTime, closeTime, reservations) {
var sectionWidth = 25;
var sectionHeight = 40;
var graphHeight = 80;
var offsetX = 10;
var offsetY = 30 + (tablenr - 1) * graphHeight;
var sections = (closeTime[0] - openTime[0]) * 2 + (closeTime[1] - openTime[1]) / 30;
reservationData["sections"] = sections;
if (ctx.canvas.width < sections * 25 + 30) {
ctx.canvas.width = sections * 25 + 30;
}
if (ctx.canvas.height < tablenr * graphHeight + 30) {
ctx.canvas.height = tablenr * graphHeight + 30;
}
// draw green area
ctx.fillStyle = "#27ae60";
ctx.fillRect(offsetX, offsetY, sections * sectionWidth, sectionHeight);
// draw reserved area
if (typeof reservations !== "undefined") {
reservations.forEach(function(reservation) {
var start = reservation.start.split(':');
var end = reservation.end.split(':');
ctx.fillStyle = "#CD5C5C";
ctx.fillRect(offsetX + (start[0] - openTime[0]) * 2 * sectionWidth + (start[1] - openTime[1]) / 30 * sectionWidth, offsetY, (end[0] - start[0]) * 2 * sectionWidth + (end[1] - start[1]) / 30 * sectionWidth, sectionHeight);
});
}
// todo draw last time
// draw selection
if (select.table == tablenr) {
if (select.startH != -1) {
ctx.fillStyle = "#f1c40f";
if(select.endH != -1) {
ctx.fillRect(offsetX + (select.startH - openTime[0]) * 2 * sectionWidth + (select.startM - openTime[1]) / 30 * sectionWidth, offsetY, (select.endH - select.startH) * 2 * sectionWidth + (select.endM - select.startM) / 30 * sectionWidth, sectionHeight);
} else {
ctx.fillRect(offsetX + (select.startH - openTime[0]) * 2 * sectionWidth + (select.startM - openTime[1]) / 30 * sectionWidth, offsetY, sectionWidth, sectionHeight);
}
}
}
// draw lines
ctx.fillStyle = "#000000";
ctx.strokeRect(offsetX, offsetY, sections * sectionWidth, sectionHeight);
ctx.beginPath();
for (var i=1; i < sections; i++) {
ctx.moveTo(i * sectionWidth + offsetX, offsetY);
ctx.lineTo(i * sectionWidth + offsetX, offsetY + sectionHeight);
}
ctx.stroke();
// draw timeline
ctx.fillText("Tisch " + tablenr, offsetX, offsetY - 10);
for (var i=0; i < sections/2; i++) {
ctx.fillText((parseInt(openTime[0])+i)+":"+openTime[1], i * 2 * sectionWidth + offsetX - 10, offsetY + sectionHeight + 10);
}
ctx.fillText(closeTime[0]+":"+closeTime[1], sections * sectionWidth + offsetX - 10, offsetY + sectionHeight + 10);
}
function initCanvasClickListener() {
document.getElementById("reservations").addEventListener("mousedown", function(e) {
var rect = document.getElementById("reservations").getBoundingClientRect();
var x = e.clientX - rect.left;
var y = e.clientY - rect.top;
var tablenr = getTableFromLocation(y, 30, 80);
if (tablenr == -1) {
return;
}
var section = getSectionFromLocation(x, 10, 25);
if (section < 1 || section > reservationData["sections"]) {
return;
}
var openTime = reservationData.open.split(':');
var closeTime = reservationData.close.split(':');
if (select.startH != -1) {
if(select.endH != -1) {
select.endH = -1;
selectStart(tablenr, section, openTime, closeTime);
} else {
selectEnd(tablenr, section, openTime, closeTime);
}
} else {
selectStart(tablenr, section, openTime, closeTime);
}
updateCanvas();
});
}
function getTableFromLocation(y, offset, graphHeight) {
var tablenr = (y + offset) / graphHeight;
if (Math.abs(tablenr - Math.round(tablenr)) < 0.25) {
return Math.round(tablenr);
}
return -1;
}
function getSectionFromLocation(x, offset, sectionWidth) {
return Math.ceil((x - offset) / sectionWidth);
}
function selectStart(tablenr, section, openTime, closeTime) {
select.table = tablenr;
select.startH = parseInt(openTime[0]) + Math.floor((section - 1)/2);
select.startM = parseInt(openTime[1]) + ((section - 1) % 2) * 30;
if (typeof reservationData.reservations["T" + select.table] !== "undefined") {
for (var i = 0; i < reservationData.reservations["T" + select.table].length; i++) {
var res = reservationData.reservations["T" + select.table][i];
var start = res.start.split(":");
var end = res.end.split(":");
// start between reservation
if ((select.startH - start[0]) * 60 + select.startM - start[1] >= 0 && (select.startH - end[0]) * 60 + select.startM - end[1] < 0) {
resetSelection();
}
}
}
}
function selectEnd(tablenr, section, openTime, closeTime) {
if (select.table != tablenr) {
alert("Du kannst nur einen Tisch reservieren");
return;
}
select.endH = parseInt(openTime[0]) + Math.floor(section/2);
select.endM = parseInt(openTime[1]) + (section % 2) * 30;
if ((select.endH - select.startH) * 60 + select.endM - select.startM <= 0) {
alert("Das Ende muss später als der Anfang liegen!");
select.endH = -1;
return;
}
if (typeof reservationData.reservations["T" + select.table] !== "undefined") {
for (var i = 0; i < reservationData.reservations["T" + select.table].length; i++) {
var res = reservationData.reservations["T" + select.table][i];
var start = res.start.split(":");
var end = res.end.split(":");
// start between reservation
if ((select.startH - start[0]) * 60 + select.startM - start[1] >= 0 && (select.startH - end[0]) * 60 + select.startM - end[1] < 0
// end between reservation
|| (select.endH - start[0]) * 60 + select.endM - start[1] > 0 && (select.endH - end[0]) * 60 + select.endM - end[1] <= 0
// reservation between start and end
|| (select.startH - start[0]) * 60 + select.startM - start[1] <= 0 && (select.endH - end[0]) * 60 + select.endM - end[1] >= 0) {
alert("Dieser Zeitraum ist schon reserviert!");
resetSelection();
}
}
}
}
function validateReservation() {
if (document.getElementById("Vname").value == "") {
alert("Vorname muss ausgefüllt sein!");
return false;
}
if (document.getElementById("Nname").value == "") {
alert("Nachname muss ausgefüllt sein!");
return false;
}
if (document.getElementById("Addr").value != "" && document.getElementById("Plz").value == "") {
alert("Postleitzahl muss ausgefüllt sein!");
return false;
}
if (document.getElementById("Addr").value == "" && document.getElementById("Plz").value != "") {
alert("Adresse muss ausgefüllt sein!");
return false;
}
if (document.getElementById("Addr").value == "" && document.getElementById("Tel").value == "" && document.getElementById("Email").value == "") {
alert("Das Gesundheitsamt fordert eine Möglichkeit zur Kontaktaufnahme");
return false;
}
if (!document.getElementById("accept").checked) {
alert("Ohne die Speicherung der Daten ist ein Besuch im Z10 nicht möglich!");
return false;
}
if (select.startH == -1 || select.endH == -1) {
alert("Es muss eine gültige Zeitspanne ausgewählt sein");
return false;
}
if (select.endH - select.startH + select.endM - select.startM < 0) {
}
document.getElementById("startTime").value = select.startH + ":" + select.startM;
document.getElementById("endTime").value = select.endH + ":" + select.endM;
document.getElementById("table").value = select.table;
document.getElementById("date").value = document.getElementById("reservationDate").value;
return true;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment