Files

224 lines
6.3 KiB
Cheetah

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Datefinder</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
/* 7 columns for 7 days */
gap: 10px;
margin: 20px auto;
width: 90%;
}
.day-column {
border: 1px solid #ccc;
background-color: #f9f9f9;
padding: 5px;
}
.day-header {
font-weight: bold;
margin-bottom: 5px;
}
.hour-block {
border: 1px solid #ddd;
padding: 10px;
margin: 2px 0;
cursor: pointer;
background-color: #fff;
text-align: center;
}
.hour-block.clicked {
background-color: #87CEEB;
/* Change color when clicked */
}
#submit-name {
width: 90%;
max-width: 300px;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
#submit-btn {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#submit-btn:disabled {
background-color: #ccc;
color: #666;
cursor: not-allowed;
}
#submit-btn:hover {
background-color: #45a049;
}
#submit-name-label {
color: red;
visibility: hidden;
}
@media (max-width: 768px) {
.calendar {
grid-template-columns: repeat(3, 1fr);
}
.hour-block {
font-size: 12px;
padding: 8px;
}
}
@media (max-width: 480px) {
.calendar {
grid-template-columns: repeat(2, 1fr);
gap: 5px;
}
.day-column {
padding: 5px;
}
.hour-block {
font-size: 10px;
padding: 5px;
}
#submit-btn {
font-size: 14px;
padding: 8px 15px;
}
}
</style>
</head>
<body>
<h1>Datefinder</h1>
<h2>{{ .PollName }}</h2>
<div class="calendar" id="calendar"></div>
<div>
<input id="submit-name" type="text" placeholder="Enter your name" />
<button id="submit-btn" type="submit" onclick="submit">Submit</button>
</div>
<label id="submit-name-label" for="submit-name">Enter Submitter Name!</label>
<script>
// Days of the week
const daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
// Select the calendar container
const calendar = document.getElementById("calendar");
// Create the weekly calendar
daysOfWeek.forEach((day) => {
// Create a column for each day
const dayColumn = document.createElement("div");
dayColumn.classList.add("day-column");
// Add a header for the day
const dayHeader = document.createElement("div");
dayHeader.classList.add("day-header");
dayHeader.textContent = day;
dayColumn.appendChild(dayHeader);
// Add hourly blocks for each day
for (let hour = 0; hour < 24; hour++) {
const hourBlock = document.createElement("div");
hourBlock.classList.add("hour-block");
hourBlock.textContent = `${hour}:00`;
// Add a click event listener to toggle color
hourBlock.addEventListener("click", () => {
hourBlock.classList.toggle("clicked");
});
dayColumn.appendChild(hourBlock);
}
// Append the day column to the calendar
calendar.appendChild(dayColumn);
});
const submitName = document.getElementById("submit-name");
const submitBtn = document.getElementById("submit-btn");
const submitNameLabel = document.getElementById("submit-name-label");
submitBtn.onclick = function () {
if (submitName.value == "") {
submitNameLabel.style.visibility = "visible";
return;
}
submitBtn.disabled = true;
const days = calendar.children;
const choices = Array.from(days).map(day =>
Array.from(day.children)
.slice(1, 25)
.map(hour => hour.classList.contains("clicked"))
);
console.log(`Submitting dates for ${submitName.value}`);
console.log(JSON.stringify(choices));
const url = "/api/submit";
fetch(url, {
method: "POST", // Specify the HTTP method
headers: {
"Content-Type": "application/json", // Inform the server about the data format
},
body: JSON.stringify({
pollId: {{ .PollId }},
username: submitName.value,
choices: choices
}), // Convert the data to JSON string
})
.then(response => {
if (!response.ok) {
console.log(response);
}
})
.then(data => {
calendar.remove();
submitName.remove();
submitBtn.remove();
submitNameLabel.remove();
const textNode = document.createTextNode(
"Your choices have been submitted, thx :)"
);
document.body.appendChild(textNode);
})
.catch(error => {
console.error("Error:", error); // Handle errors
});
};
</script>
</body>
</html>