92 lines
3.5 KiB
HTML
92 lines
3.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
<link th:href="@{/styles/voting.css}" rel="stylesheet" />
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
|
</head>
|
|
|
|
|
|
<body class="center-screen">
|
|
<script>
|
|
function setColor(button) {
|
|
groupButtons = document.querySelectorAll('[id^=' + button.id.split("_")[0] + ']');
|
|
groupButtons.forEach(button => {
|
|
button.style.background = 'transparent';
|
|
button.style.fontWeight = 'normal';
|
|
});
|
|
button.style.background = "#bb1515";
|
|
button.style.fontWeight = 'bold';
|
|
}
|
|
|
|
function rgbToHex(rgb) {
|
|
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
|
|
var color = (rgb && rgb.length === 4) ? "#" +
|
|
("0" + parseInt(rgb[1], 10).toString(16)).slice(-2) +
|
|
("0" + parseInt(rgb[2], 10).toString(16)).slice(-2) +
|
|
("0" + parseInt(rgb[3], 10).toString(16)).slice(-2) : '';
|
|
|
|
return color;
|
|
}
|
|
|
|
function getVotes() {
|
|
groupButtons = document.querySelectorAll(".inputButton");
|
|
var voteIds = [];
|
|
groupButtons.forEach(button => {
|
|
if (button.style.fontWeight == 'bold') {
|
|
var str = button.id.split("_");
|
|
voteIds.push(str[1].replace(/\D/g, ""));
|
|
}
|
|
});
|
|
input = document.getElementById("voteValues");
|
|
input.value = voteIds;
|
|
}
|
|
|
|
var q = 1,
|
|
qMax = 0;
|
|
|
|
$(function() {
|
|
qMax = $('#votingButtons div.voteDiv').length;
|
|
$('#votingButtons div.voteDiv').hide();
|
|
$('#votingButtons div.voteDiv:nth-child(1)').show();
|
|
$('#btnNext').on('click', function(event) {
|
|
event.preventDefault();
|
|
handleClick();
|
|
});
|
|
});
|
|
|
|
function handleClick() {
|
|
if (q < qMax) {
|
|
$('#votingButtons div.voteDiv:nth-child(' + q + ')').hide();
|
|
$('#votingButtons div.voteDiv:nth-child(' + (q + 1) + ')').show();
|
|
if (q == (qMax - 1)) {
|
|
$('#btnNext').html('Auswahl bestätigen');
|
|
}
|
|
q++;
|
|
} else {
|
|
getVotes();
|
|
document.getElementById("myForm").submit();
|
|
}
|
|
}
|
|
</script>
|
|
<div class="centered">
|
|
<h1>Wähle deine Kandidaten:</h1>
|
|
<div id="votingButtons">
|
|
<div th:each="category,iter : ${categories}" class="voteDiv">
|
|
<h2 class="categoryHeader" th:text="${category.name}"></h2>
|
|
<div th:each="candidate : ${category.candidateList}">
|
|
<button class="inputButton" th:id="|category${category.id}_candidate${candidate.id}|" th:text="${candidate.name}" th:onclick="|setColor(category${category.id}_candidate${candidate.id})|"></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button class="submitButton" id="btnNext" type="submit">Nächste Kategorie</button>
|
|
<form action="#" th:action="@{/processVote}" method="post" id="myForm">
|
|
<input id="voteValues" type="hidden" name="voteValues" value="" />
|
|
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
|
</form>
|
|
</div>
|
|
</body>
|
|
|
|
</html> |