mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-23 00:01:16 +00:00
236 lines
12 KiB
Django/Jinja
236 lines
12 KiB
Django/Jinja
{% extends "core/base.jinja" %}
|
|
|
|
{% block title %}
|
|
{{ object.title }}
|
|
{% endblock %}
|
|
|
|
{% block head %}
|
|
{{ super() -}}
|
|
<link rel="stylesheet" href="{{ scss('election/css/election.scss') }}">
|
|
{%- endblock %}
|
|
|
|
{% block content %}
|
|
<h3 class="election__title">{{ election.title }}</h3>
|
|
<p class="election__description">{{ election.description }}</p>
|
|
<hr>
|
|
<section class="election_details">
|
|
<p>
|
|
{%- if election.is_vote_active %}
|
|
{% trans %}Polls close {% endtrans %}
|
|
{%- elif election.is_vote_finished %}
|
|
{% trans %}Polls closed {% endtrans %}
|
|
{%- else %}
|
|
{% trans %}Polls will open {% endtrans %}
|
|
<time datetime="{{ election.start_date }}">{{ election.start_date|localtime|date(DATETIME_FORMAT)}}</time>
|
|
{% trans %} at {% endtrans %}<time>{{ election.start_date|localtime|time(DATETIME_FORMAT)}}</time>
|
|
{% trans %}and will close {% endtrans %}
|
|
{%- endif %}
|
|
<time datetime="{{ election.end_date }}">{{ election.end_date|localtime|date(DATETIME_FORMAT)}}</time>
|
|
{% trans %} at {% endtrans %}<time>{{ election.end_date|localtime|time(DATETIME_FORMAT)}}</time>
|
|
</p>
|
|
{%- if election.has_voted(user) %}
|
|
<p class="election__elector-infos">
|
|
{%- if election.is_vote_active %}
|
|
<span>{% trans %}You already have submitted your vote.{% endtrans %}</span>
|
|
{%- else %}
|
|
<span>{% trans %}You have voted in this election.{% endtrans %}</span>
|
|
{%- endif %}
|
|
</p>
|
|
{%- endif %}
|
|
</section>
|
|
<section class="election_vote">
|
|
<form action="{{ url('election:vote', election.id) }}" method="post" class="election__vote-form" name="vote-form" id="vote-form">
|
|
{% csrf_token %}
|
|
<table class="election_table">
|
|
{%- set election_lists = election.election_lists.all() -%}
|
|
<caption></caption>
|
|
<thead class="lists">
|
|
<tr>
|
|
<th class="column" style="width: {{ 100 / (election_lists.count() + 1) }}%">{% trans %}Blank vote{% endtrans %}</th>
|
|
{%- for election_list in election_lists %}
|
|
<th class="column" style="width: {{ 100 / (election_lists.count() + 1) }}%">
|
|
<span>{{ election_list.title }}</span>
|
|
{% if user.can_edit(election_list) and election.is_vote_editable -%}
|
|
<a href="{{ url('election:delete_list', list_id=election_list.id) }}">❌</a>
|
|
{% endif %}
|
|
</th>
|
|
{%- endfor %}
|
|
</tr>
|
|
</thead>
|
|
{%- set role_list = election.roles.order_by('order').all() %}
|
|
{%- for role in role_list %}
|
|
{%- set count = [0] %}
|
|
{%- set role_data = election_form.data.getlist(role.title) if role.title in election_form.data else [] %}
|
|
<tbody data-max-choice="{{role.max_choice}}" class="role{{ ' role_error' if role.title in election_form.errors else '' }}{{ ' role__multiple-choices' if role.max_choice > 1 else ''}}">
|
|
<tr>
|
|
<td class="role_title">
|
|
<div class="role_text">
|
|
<h4>{{ role.title }}</h4>
|
|
<p class="role_description">{{ role.description }}</p>
|
|
{%- if role.max_choice > 1 and not election.has_voted(user) and election.can_vote(user) %}
|
|
<strong>{% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %}</strong>
|
|
{%- endif %}
|
|
|
|
{%- if election_form.errors[role.title] is defined %}
|
|
{%- for error in election_form.errors.as_data()[role.title] %}
|
|
<strong class="error">{{ error.message }}</strong>
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
</div>
|
|
{% if user.can_edit(role) and election.is_vote_editable -%}
|
|
<div class="role_buttons">
|
|
<a href="{{url('election:update_role', role_id=role.id)}}">✏️</a>
|
|
<a href="{{url('election:delete_role', role_id=role.id)}}">❌</a>
|
|
{%- if role == role_list.last() %}
|
|
<button disabled><i class="fa fa-arrow-down"></i></button>
|
|
<button disabled><i class="fa fa-caret-down"></i></button>
|
|
{%- else %}
|
|
<button type="button" onclick="window.location.replace('?role={{ role.id }}&action=bottom');"><i class="fa fa-arrow-down"></i></button>
|
|
<button type="button" onclick="window.location.replace('?role={{ role.id }}&action=down');"><i class="fa fa-caret-down"></i></button>
|
|
{%- endif %}
|
|
{% if role == role_list.first() %}
|
|
<button disabled><i class="fa fa-caret-up"></i></button>
|
|
<button disabled><i class="fa fa-arrow-up"></i></button>
|
|
{% else %}
|
|
<button type="button" onclick="window.location.replace('?role={{ role.id }}&action=up');"><i class="fa fa-caret-up"></i></button>
|
|
<button type="button" onclick="window.location.replace('?role={{ role.id }}&action=top');"><i class="fa fa-arrow-up"></i></button>
|
|
{% endif %}
|
|
</div>
|
|
{%- endif -%}
|
|
</td>
|
|
</tr>
|
|
<tr class="role_candidates">
|
|
<td class="list_per_role" style="width: 100%; max-width: {{ 100 / (election_lists.count() + 1) }}%">
|
|
{%- if role.max_choice == 1 and election.can_vote(user) %}
|
|
<div class="radio-btn">
|
|
<input id="id_{{ role.title }}_{{ count[0] }}" type="radio" name="{{ role.title }}" value {{ '' if role_data in election_form else 'checked' }} {{ 'disabled' if election.has_voted(user) else '' }}>
|
|
<label for="id_{{ role.title }}_{{ count[0] }}">
|
|
<span>{% trans %}Choose blank vote{% endtrans %}</span>
|
|
</label>
|
|
</div>
|
|
{%- set _ = count.append(count.pop() + 1) %}
|
|
{%- endif %}
|
|
{%- if election.is_vote_finished %}
|
|
{%- set results = election_results[role.title]['blank vote'] %}
|
|
<div class="election__results">
|
|
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ "%.2f" % results.percent }} %)</strong>
|
|
</div>
|
|
{%- endif %}
|
|
</td>
|
|
{%- for election_list in election_lists %}
|
|
<td class="list_per_role" style="width: 100%; max-width: {{ 100 / (election_lists.count() + 1) }}%">
|
|
<ul class="candidates">
|
|
{%- for candidature in election_list.candidatures.filter(role=role) %}
|
|
<li class="candidate">
|
|
{%- if election.can_vote(user) %}
|
|
<input id="id_{{ role.title }}_{{ count[0] }}" type="{{ 'checkbox' if role.max_choice > 1 else 'radio' }}" {{ 'checked' if candidature.id|string in role_data else '' }} {{ 'disabled' if election.has_voted(user) else '' }} name="{{ role.title }}" value="{{ candidature.id }}">
|
|
<label for="id_{{ role.title }}_{{ count[0] }}">
|
|
{%- endif %}
|
|
<figure>
|
|
{%- if user.is_subscriber_viewable %}
|
|
{% if candidature.user.profile_pict %}
|
|
<img class="candidate__picture" src="{{ candidature.user.profile_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}">
|
|
{% else %}
|
|
<img class="candidate__picture" src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}">
|
|
{% endif %}
|
|
{%- endif %}
|
|
<figcaption class="candidate__details">
|
|
<h5>{{ candidature.user.first_name }} <em>{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</h5>
|
|
{%- if not election.is_vote_finished %}
|
|
<q class="candidate_program">{{ candidature.program | markdown or '' }}</q>
|
|
{%- endif %}
|
|
</figcaption>
|
|
{%- if user.can_edit(candidature) -%}
|
|
{%- if election.is_vote_editable -%}
|
|
<div class="edit_btns">
|
|
<a href="{{url('election:update_candidate', candidature_id=candidature.id)}}">{% trans %}✏️{% endtrans %}</a>
|
|
<a href="{{url('election:delete_candidate', candidature_id=candidature.id)}}">{% trans %}❌{% endtrans %}</a>
|
|
</div>
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
</figure>
|
|
{%- if election.can_vote(user) %}
|
|
</label>
|
|
{%- set _ = count.append(count.pop() + 1) %}
|
|
{%- endif %}
|
|
{%- if election.is_vote_finished %}
|
|
{%- set results = election_results[role.title][candidature.user.username] %}
|
|
<div class="election__results">
|
|
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ "%.2f" % results.percent }} %)</strong>
|
|
</div>
|
|
{%- endif %}
|
|
</li>
|
|
{%- endfor %}
|
|
</ul>
|
|
</td>
|
|
{%- endfor %}
|
|
</tr>
|
|
</tbody>
|
|
{%- endfor %}
|
|
</table>
|
|
</form>
|
|
</section>
|
|
<section class="buttons">
|
|
{%- if (election.can_candidate(user) and election.is_candidature_active) or (user.can_edit(election) and election.is_vote_editable) %}
|
|
<a class="button" href="{{ url('election:candidate', election_id=object.id) }}">{% trans %}Candidate{% endtrans %}</a>
|
|
{%- endif %}
|
|
{%- if election.is_vote_editable %}
|
|
<a class="button" href="{{ url('election:create_list', election_id=object.id) }}">{% trans %}Add a new list{% endtrans %}</a>
|
|
{%- endif %}
|
|
{%- if user.can_edit(election) %}
|
|
{% if election.is_vote_editable %}
|
|
<a class="button" href="{{ url('election:create_role', election_id=object.id) }}">{% trans %}Add a new role{% endtrans %}</a>
|
|
{% endif %}
|
|
<a class="button" href="{{ url('election:update', election_id=object.id) }}">{% trans %}Edit{% endtrans %}</a>
|
|
{%- endif %}
|
|
{%- if user.is_root %}
|
|
<a class="button" href="{{ url('election:delete', election_id=object.id) }}">{% trans %}Delete{% endtrans %}</a>
|
|
{%- endif %}
|
|
</section>
|
|
{%- if not election.has_voted(user) and election.can_vote(user) %}
|
|
<section class="buttons">
|
|
<button class="button button_send" form="vote-form">{% trans %}Submit the vote !{% endtrans %}</button>
|
|
</section>
|
|
{%- endif %}
|
|
{% endblock %}
|
|
|
|
{% block script %}
|
|
{{ super() }}
|
|
<script src="{{ static('core/js/shorten.min.js') }}"></script>
|
|
<script type="text/javascript">
|
|
$('.role_description').shorten({
|
|
moreText: "{% trans %}Show more{% endtrans %}",
|
|
lessText: "{% trans %}Show less{% endtrans %}",
|
|
showChars: 50
|
|
});
|
|
$('.candidate_program').shorten({
|
|
moreText: "{% trans %}Show more{% endtrans %}",
|
|
lessText: "{% trans %}Show less{% endtrans %}",
|
|
showChars: 200
|
|
});
|
|
</script>
|
|
<script type="text/javascript">
|
|
document.querySelectorAll('.role__multiple-choices').forEach(setupRestrictions);
|
|
|
|
function setupRestrictions(role) {
|
|
var selectedChoices = [];
|
|
role.querySelectorAll('input').forEach(setupRestriction);
|
|
|
|
function setupRestriction(choice) {
|
|
if (choice.checked)
|
|
selectedChoices.push(choice);
|
|
choice.addEventListener('change', onChange);
|
|
|
|
function onChange() {
|
|
if (choice.checked)
|
|
selectedChoices.push(choice);
|
|
else
|
|
selectedChoices.splice(selectedChoices.indexOf(choice), 1);
|
|
while (selectedChoices.length > role.dataset.maxChoice)
|
|
selectedChoices.shift().checked = false;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
{% endblock %}
|