You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
tea/choose/templates/vote.html

146 lines
3.7 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Список чаев</th>
<th>Выбрали</th>
<th>Проголосовали</th>
<th></th>
</tr>
{% for choice in choices %}
<tr class="{{ choice.class }}">
<td>
<ul>
{% for tea in choice.teas %}
<li>{{ tea }}</li>
{% endfor %}
</ul>
</td>
<td>
<ul>
{% for choice in choice.chosed %}
<li>{{ choice }}</li>
{% endfor %}
</ul>
</td>
<td>
<ul>
{% for vote in choice.voted %}
<li>{{ vote }}</li>
{% endfor %}
</ul>
</td>
<td>
{% if choice.class == 'choice' %}
<button onclick="vote({{ choice.id }})"{% if request.user.username in choice.voted %}disabled{% endif %}>+</button>
{% endif %}
{% if choice.class == 'my_choice' %}
<button onclick="location.href='/choose'">Изменить выбор</button>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
<style>
table {
border: none;
margin-bottom: 20px;
}
table th {
font-weight: bold;
text-align: left;
border: none;
padding: 10px 15px;
background: #d8d8d8;
font-size: 14px;
}
table tr th:first-child {
border-radius: 8px 0 0 8px;
}
table tr th:last-child {
border-radius: 0 8px 8px 0;
width: 35px;
}
table td {
text-align: left;
border: none;
padding: 10px 15px;
font-size: 14px;
vertical-align: top;
}
table tbody tr:nth-child(even) {
background: #f3f3f3;
}
table tr td:first-child {
border-radius: 8px 0 0 8px;
}
table tr td:last-child {
border-radius: 0 8px 8px 0;
}
table tbody tr.my_choice {
background: #fffdcd;
}
ul {
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-inline-start: 10px;
}
</style>
<script>
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
function vote(id) {
const request = new Request(
'confirm-vote',
{
method: 'POST',
headers: {'X-CSRFToken': csrftoken},
mode: 'same-origin',
body: JSON.stringify({vote:id})
}
);
fetch(request).then((response) => response.json())
.then((data) => {
if (data.response == 'ok' || data.response == 'not found'){window.location.reload();}
else {window.alert(data.response)}
})
}
</script>
</html>