Parameterize route and index.html template to allow serving specific poll
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
|
||||
<body>
|
||||
<h1>Datefinder</h1>
|
||||
<h2>{{ .PollName }}</h2>
|
||||
<div class="calendar" id="calendar"></div>
|
||||
<div>
|
||||
<input id="submit-name" type="text" placeholder="Enter your name" />
|
||||
@@ -1,76 +0,0 @@
|
||||
// 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")
|
||||
|
||||
submitBtn.onclick = function() {
|
||||
if (submitName.value == "") {
|
||||
console.log("Submitter name is missing.")
|
||||
return
|
||||
}
|
||||
|
||||
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 = "http://localhost:8080/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: 1, username: submitName.value, choices: choices }), // Convert the data to JSON string
|
||||
})
|
||||
/*
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok ' + response.statusText);
|
||||
}
|
||||
return response.json(); // Parse the JSON response
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Success:', data); // Handle the response data
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error); // Handle errors
|
||||
});
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user