Movie-Me-Now/templates/questionnaire.html
2025-04-02 13:49:04 -05:00

84 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Movie Questionnaire</title>
<style>
/* Styling for the slideshow */
#movie-container {
text-align: center;
margin-top: 30px;
}
#movie-poster {
width: 200px;
margin: 20px;
}
.rating-buttons button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<h1 style="text-align: center;">Rate Movies</h1>
<form id="questionForm" method="POST">
<!-- Container where hidden inputs will be added for the round -->
<div id="hiddenFields"></div>
<div id="movie-container">
<img id="movie-poster" src="" alt="Movie Poster">
<h2 id="movie-title"></h2>
<p id="movie-description"></p>
</div>
<div class="rating-buttons" style="text-align: center;">
<button type="button" onclick="recordRating('like')">Like</button>
<button type="button" onclick="recordRating('dislike')">Dislike</button>
<button type="button" onclick="recordRating('not seen')">Not Seen</button>
</div>
</form>
<script>
// Movies for the current round are passed from the server.
const movies = {{ movies | tojson }};
let currentIndex = 0;
let movieRatings = {}; // To store ratings for this batch
function showMovie(index) {
if (index >= movies.length) {
// All movies rated in this round—append hidden fields and submit the form.
const container = document.getElementById("hiddenFields");
movies.forEach(movie => {
// Hidden input for movie id
const movieIdInput = document.createElement("input");
movieIdInput.type = "hidden";
movieIdInput.name = "movie_id";
movieIdInput.value = movie.id;
container.appendChild(movieIdInput);
// Hidden input for its rating
const ratingInput = document.createElement("input");
ratingInput.type = "hidden";
ratingInput.name = "rating_" + movie.id;
ratingInput.value = movieRatings[movie.id] || "not seen";
container.appendChild(ratingInput);
});
document.getElementById("questionForm").submit();
return;
}
const movie = movies[currentIndex];
document.getElementById("movie-poster").src = movie.poster;
document.getElementById("movie-poster").alt = movie.title;
document.getElementById("movie-title").textContent = movie.title + " (" + movie.year + ")";
document.getElementById("movie-description").textContent = movie.description;
}
function recordRating(rating) {
movieRatings[movies[currentIndex].id] = rating;
currentIndex++;
showMovie(currentIndex);
}
showMovie(currentIndex);
</script>
</body>
</html>