2020-10-27 23:54:35 +01:00
{% extends "base.html" %}
2021-03-30 19:23:13 +02:00
{% load static %}
2021-03-30 23:01:58 +02:00
{% load deadliny %}
2020-10-27 23:54:35 +01:00
{% block content %}
2021-10-08 10:36:59 +02:00
{# FIXME: Necopypastovat! Tohle je zkopírované ze static/odevzdavatko/dynamic_formsets.js #}
2021-02-09 22:48:49 +01:00
< 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');
2021-03-30 19:41:08 +02:00
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 + + ) {
2021-02-09 22:48:49 +01:00
$(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() {
2021-02-16 23:49:42 +01:00
var form_idx = $('#id_form-TOTAL_FORMS').val();
2021-02-09 22:48:49 +01:00
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(){
2021-02-16 23:49:42 +01:00
deleteForm("form",this);
2021-02-09 22:48:49 +01:00
});
2022-10-11 13:56:56 +02:00
// Copy deadline
if (form_idx !== "0") {
$('#id_form-' + form_idx + '-deadline_body')[0].value = $('#id_form-' + (form_idx - 1) + '-deadline_body')[0].value
}
2021-02-16 23:49:42 +01:00
$('#id_form-TOTAL_FORMS').val(parseInt(form_idx) + 1);
2021-02-09 22:48:49 +01:00
});
$('.smazat_hodnoceni').click(function(){
2021-02-16 23:49:42 +01:00
deleteForm("form",this);
2021-02-09 22:48:49 +01:00
});
});
< / script >
2020-12-02 01:12:50 +01:00
< p > Řešené problémy: {{ object.problem.all | join:", " }}< / p >
2021-09-19 19:16:37 +02:00
< 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 > )
2021-09-11 11:18:15 +02:00
{% if forloop.revcounter0 != 0 %}, {% endif %} {% endfor %}< / p >
2020-12-02 01:12:50 +01:00
{# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #}
2021-03-30 23:01:58 +02:00
< p > Forma: {{ object.get_forma_display }}< / p >
2022-10-09 11:50:27 +02:00
< p > Doručeno {{ object.cas_doruceni }}, deadline: {{object.deadline_reseni | deadline_html }}< / p >
2020-12-02 01:12:50 +01:00
{# Soubory: #}
< h3 > Přílohy:< / h3 >
{% if object.prilohy.all %}
2021-09-20 01:28:08 +02:00
< table class = "dosla_reseni" >
2020-12-02 01:12:50 +01:00
< 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 %}
2021-09-26 22:56:15 +02:00
< form method = post onsubmit = "return zkontroluj_hodnoceni();" >
2021-09-14 19:02:47 +02:00
{# Poznámka #}
< h3 > Poznámka:< / h3 >
2021-09-20 04:17:04 +02:00
< p > {{ poznamka_form.poznamka }}< / p >
2021-09-14 19:02:47 +02:00
2020-12-02 01:12:50 +01:00
{# Hodnocení: #}
< h3 > Hodnocení:< / h3 >
2021-09-20 04:17:04 +02:00
< table >
2021-01-19 19:25:39 +01:00
{% csrf_token %}
2021-02-09 22:48:49 +01:00
{{ form.management_form }}
2021-09-11 11:17:46 +02:00
< / table >
2021-02-09 22:48:49 +01:00
< table id = "form_set" >
2022-10-01 14:41:47 +02:00
< tr > < th > Problém< / th > < th > Body< / th > < th > Deadline pro body< / th > < / tr >
2021-02-09 22:48:49 +01:00
{% for subform in form %}
2021-09-26 22:56:15 +02:00
< tbody >
2021-02-09 22:48:49 +01:00
< tr class = "hodnoceni" >
< td > {{ subform.problem }}< / td >
< td > {{ subform.body }}< / td >
2022-10-01 14:41:47 +02:00
< td > {{ subform.deadline_body }}< / td >
2021-10-08 10:36:59 +02:00
< td > < a href = "#" class = "smazat_hodnoceni" id = "id_{{subform.prefix}}-jsremove" > < img src = "{% static " odevzdavatko / cross . png " % } " alt = "Smazat" > < / a > < / td >
2021-02-09 22:48:49 +01:00
< / tr >
2021-09-26 22:56:15 +02:00
< / tbody >
2021-02-09 22:48:49 +01:00
{% endfor %}
< / table >
2021-10-08 10:36:59 +02:00
< a href = "#" > < img src = "{% static " odevzdavatko / plus . png " % } " id = "pridat_hodnoceni" alt = "Přidat hodnocení" > < / a > < / br >
2021-03-30 19:23:13 +02:00
< input type = submit value = "Uložit" > < / form >
2021-02-16 23:11:40 +01:00
2021-02-09 22:48:49 +01:00
< table id = "empty_form" style = "display: none;" >
< tr class = "hodnoceni" >
< td > {{ form.empty_form.problem }}< / td >
< td > {{ form.empty_form.body }}< / td >
2022-10-01 14:41:47 +02:00
< td > {{ form.empty_form.deadline_body }}< / td >
2021-12-14 00:16:29 +01:00
< td > < a href = "#" class = "smazat_hodnoceni" id = "id_{{form.empty_form.prefix}}-jsremove" > < img src = "{% static " odevzdavatko / cross . png " % } " alt = "Smazat" > < / a > < / td >
2021-02-09 22:48:49 +01:00
< / tr >
< / table >
2021-09-26 22:56:15 +02:00
< script type = "text/javascript" >
function zkontroluj_hodnoceni() {
2021-11-01 21:51:36 +01:00
const pocet = $('.hodnoceni').length;
2021-09-26 22:56:15 +02:00
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;
}
}
2021-11-15 22:45:45 +01:00
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;
}
2021-09-26 22:56:15 +02:00
return true;
}
< / script >
2020-10-27 23:54:35 +01:00
{% endblock %}