Web M&M
https://mam.matfyz.cz
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.
150 lines
5.2 KiB
150 lines
5.2 KiB
{% extends "base.html" %}
|
|
{% load static %}
|
|
{% load deadliny %}
|
|
|
|
{% block content %}
|
|
|
|
{# FIXME: Necopypastovat! Tohle je zkopírované ze static/odevzdavatko/dynamic_formsets.js #}
|
|
<script type='text/javascript'>
|
|
// Credit https://medium.com/all-about-django/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
|
|
function updateElementIndex(el, prefix, ndx) {
|
|
var id_regex = new RegExp('(' + prefix + '-\\d+)');
|
|
var replacement = prefix + '-' + ndx;
|
|
if ($(el).attr("for")) {
|
|
$(el).attr("for", $(el).attr("for").replace(id_regex, replacement));
|
|
}
|
|
if (el.id) {
|
|
el.id = el.id.replace(id_regex, replacement);
|
|
}
|
|
if (el.name) {
|
|
el.name = el.name.replace(id_regex, replacement);
|
|
}
|
|
}
|
|
|
|
// Credit https://medium.com/all-about-django/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
|
|
function deleteForm(prefix, btn) {
|
|
var total = parseInt($('#id_' + prefix + '-TOTAL_FORMS').val());
|
|
if (total >= 1){
|
|
btn.closest('tr').remove();
|
|
var forms = $('.hodnoceni');
|
|
var formCount = forms.length - 1; // There is one extra such form hidden as template!
|
|
$('#id_' + prefix + '-TOTAL_FORMS').val(formCount);
|
|
for (var i=0; i<formCount; i++) {
|
|
$(forms.get(i)).find(':input').each(function() {
|
|
updateElementIndex(this, prefix, i);
|
|
});
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Credit: https://simpleit.rocks/python/django/dynamic-add-form-with-add-button-in-django-modelformset-template/
|
|
$(document).ready(function(){
|
|
$('#pridat_hodnoceni').click(function() {
|
|
var form_idx = $('#id_form-TOTAL_FORMS').val();
|
|
var new_form = $('#empty_form').html().replace(/__prefix__/g, form_idx);
|
|
$('#form_set').append(new_form);
|
|
// Newly created form has not the binding between remove button and remove function
|
|
// We need to add it manually
|
|
$('.smazat_hodnoceni').click(function(){
|
|
deleteForm("form",this);
|
|
});
|
|
$('#id_form-TOTAL_FORMS').val(parseInt(form_idx) + 1);
|
|
});
|
|
$('.smazat_hodnoceni').click(function(){
|
|
deleteForm("form",this);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
|
|
<p>Řešené problémy: {{ object.problem.all | join:", " }}</p>
|
|
|
|
<p>Řešitelé: {% for r in object.resitele.all %} {{ r }} (<a href="mailto:{{ r.osoba.email }}?subject={{ "Oprava řešení M&M " | urlencode }}{{ object.problem.all.0.hlavni_problem | urlencode }}">{{ r.osoba.email }}</a>)
|
|
{% if forloop.revcounter0 != 0 %}, {% endif %} {% endfor %}</p>
|
|
|
|
{# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #}
|
|
<p>Forma: {{ object.get_forma_display }}</p>
|
|
|
|
<p>Doručeno {{ object.cas_doruceni }}, deadline: {{object.cas_doruceni | deadline_html }}</p>
|
|
|
|
{# Soubory: #}
|
|
<h3>Přílohy:</h3>
|
|
{% if object.prilohy.all %}
|
|
<table class="dosla_reseni">
|
|
<tr><th>Soubor</th><th>Řešitelova poznámka</th><th>Datum</th></tr>
|
|
{% for priloha in object.prilohy.all %}
|
|
<tr>
|
|
<td><a href="{{ priloha.soubor.url }}" download>{{ priloha.split | last }}</a></td>
|
|
<td>{{ priloha.res_poznamka }}</td>
|
|
<td>{{ priloha.vytvoreno }}</td></tr>
|
|
{# TODO: Orgo-poznámka, ideálně jako formulář #}
|
|
{% endfor %}
|
|
</table>
|
|
{% else %}
|
|
<p>Žádné přílohy</p>
|
|
{% endif %}
|
|
|
|
<form method=post onsubmit="return zkontroluj_hodnoceni();">
|
|
{# Poznámka #}
|
|
<h3>Poznámka:</h3>
|
|
<p>{{ poznamka_form.poznamka }}</p>
|
|
|
|
{# Hodnocení: #}
|
|
<h3>Hodnocení:</h3>
|
|
<table>
|
|
{% csrf_token %}
|
|
{{ form.management_form }}
|
|
</table>
|
|
<table id="form_set">
|
|
<tr><th>Problém</th><th>Body</th><th>Číslo pro body</th></tr>
|
|
{% for subform in form %}
|
|
<tbody>
|
|
<tr class="hodnoceni">
|
|
<td>{{ subform.problem }}</td>
|
|
<td>{{ subform.body }}</td>
|
|
<td>{{ subform.cislo_body }}</td>
|
|
<td><a href="#" class="smazat_hodnoceni" id="id_{{subform.prefix}}-jsremove"><img src="{% static "odevzdavatko/cross.png" %}" alt="Smazat"></a></td>
|
|
</tr>
|
|
</tbody>
|
|
{% endfor %}
|
|
</table>
|
|
|
|
|
|
<a href="#"> <img src="{% static "odevzdavatko/plus.png" %}" id="pridat_hodnoceni" alt="Přidat hodnocení"></a> </br>
|
|
<input type=submit value="Uložit"></form>
|
|
|
|
<table id="empty_form" style="display: none;">
|
|
<tr class="hodnoceni">
|
|
<td>{{ form.empty_form.problem }}</td>
|
|
<td>{{ form.empty_form.body }}</td>
|
|
<td>{{ form.empty_form.cislo_body }}</td>
|
|
<td><a href="#" class="smazat_hodnoceni" id="id_{{subform.prefix}}-jsremove"><img src="{% static "odevzdavatko/cross.png" %}" alt="Smazat"></a></td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
<script type="text/javascript">
|
|
function zkontroluj_hodnoceni() {
|
|
const pocet = $('.hodnoceni').length;
|
|
if (pocet === 1) { {# vydím pouze plusko #}
|
|
const vysledek = confirm("Odstranil jsi všechny problémy tohoto řešení. Nepůjde tedy dohledat přes problémy, co řeší, tj. například v došlých řešeních. Přesto odeslat?");
|
|
if (!vysledek) {
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function problem_is_empty(elem, index, array) {return elem.firstElementChild.children.length !== 1 && elem.firstElementChild.children[1].textContent === "";}
|
|
|
|
if ($('.hodnoceni').toArray().some(problem_is_empty)) {
|
|
alert("Neuloženo! Nezadal jsi problém, ke kterému posíláš hodnocení. Pokud je toto hodnocení navíc, smaž ho prosím křížkem a znovu odešli.")
|
|
event.preventDefault()
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
</script>
|
|
|
|
{% endblock %}
|
|
|