From 4ae14570e9c4bef67b6a1f3961afc2c7fd0043bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pracha=C5=99?= <jan.prachar@gmail.com> Date: Thu, 28 Apr 2022 15:35:51 +0200 Subject: [PATCH] =?UTF-8?q?"Za=C5=A1krtnout=20v=C5=A1e":=20javascript,=20c?= =?UTF-8?q?o=20za=C5=A1krtne=20v=C5=A1echny=20checkboxy=20pro=20zalo=C5=BE?= =?UTF-8?q?en=C3=AD=20=C5=99e=C5=A1en=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mo/web/templates/org_contest_solutions.html | 36 +++++++++++++++++ mo/web/templates/org_contest_task.html | 6 +-- .../templates/parts/org_solution_table.html | 39 +++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/mo/web/templates/org_contest_solutions.html b/mo/web/templates/org_contest_solutions.html index 3e4f392f..3b52c2ea 100644 --- a/mo/web/templates/org_contest_solutions.html +++ b/mo/web/templates/org_contest_solutions.html @@ -6,6 +6,34 @@ {% set edit_create = rights.can_create_solutions() %} {% set edit_both = edit_points and edit_create %} +{% block head %} +<script type="text/javascript"> + checkAllAbove = function() { + var states = []; + return function (e, col) { + e.preventDefault(); + var table = e.target; + while (table.tagName != 'TABLE') { table = table.parentNode; } + var checkboxes = table.querySelectorAll('tr.state-active td:nth-child('+(2+2*(col-1)+1)+') input[type=checkbox]'); + + if (states[col] === true) { + Array.prototype.forEach.call(checkboxes, function(el, i){ + el.checked = false; + }); + e.target.innerHTML = '<span class="glyphicon glyphicon-arrow-up"></span> Zaškrtnout vše'; + states[col] = false; + } else { + Array.prototype.forEach.call(checkboxes, function(el, i){ + el.checked = true; + }); + e.target.innerHTML = '<span class="glyphicon glyphicon-arrow-up"></span> Odškrtnout vše'; + states[col] = true; + } + } + }(); +</script> +{% endblock %} + {% block title %} {{ "Založení řešení" if edit_form else "Tabulka řešení" }} kategorie {{ round.category }} {% if site %}soutěžního místa {{ site.name }}{% else %}{{ contest.place.name_locative() }}{% endif %} {% endblock %} @@ -142,6 +170,13 @@ Přes ikonku <span class="icon">🔍</span> se dostanete na detail, kde můžete <tfoot> <tr><td><td> {% for task in tasks[4*i:4*(i+1)] %} + {% if edit_form %} + <td colspan="4"> + <a class="btn btn-xs btn-default" href="#" onclick="checkAllAbove(event, {{ loop.index }})"> + <span class="glyphicon glyphicon-arrow-up"></span> + Zaškrtnout vše + </a> + {% else %} <td> <a class='btn btn-xs btn-default' href="{{ ctx.url_for('org_generic_batch_download', task_id=task.task_id) }}" title="Stáhnout ZIP řešení úlohy {{ task.code }}"><span class="glyphicon glyphicon-cloud-download"></span></a> <td> @@ -154,6 +189,7 @@ Přes ikonku <span class="icon">🔍</span> se dostanete na detail, kde můžete {% endif %} <td> <a class="btn btn-xs btn-primary" href="{{ ctx.url_for('org_contest_task', task_id=task.task_id) }}" title="Podrobný výpis odevzdaných řešení k úloze {{ task.code }}"><span class="glyphicon glyphicon-search"></span></a> + {% endif %} {% endfor %} {% if last_loop %} <td> diff --git a/mo/web/templates/org_contest_task.html b/mo/web/templates/org_contest_task.html index 4964b57a..9325ff65 100644 --- a/mo/web/templates/org_contest_task.html +++ b/mo/web/templates/org_contest_task.html @@ -33,14 +33,10 @@ <form class="form" method="POST"> {{ edit_form.csrf_token }} {% endif %} -{% with for_user=None, for_task=ctx.task, rows=rows %} +{% with for_user=None, for_task=ctx.task, rows=rows, cancel_url=ctx.url_for('org_contest_task') %} {% include "parts/org_solution_table.html" %} {% endwith %} {% if edit_form %} - <div> - {{ wtf.form_field(edit_form.submit, class="btn btn-primary" ) }} - <a class="btn btn-default" href="{{ ctx.url_for('org_contest_task') }}">Zrušit</a> - </div> </form> {% else %} <p> diff --git a/mo/web/templates/parts/org_solution_table.html b/mo/web/templates/parts/org_solution_table.html index 92ad225e..956981fc 100644 --- a/mo/web/templates/parts/org_solution_table.html +++ b/mo/web/templates/parts/org_solution_table.html @@ -145,6 +145,19 @@ finální (ve výchozím stavu poslední nahrané).{% elif rights.can_upload_sol </div> </tr> {% endfor %} +{% if edit_form %} +<tfoot> + <tr><td><td><td> + <td colspan="3" class="text-center"> + <a class="btn btn-sm btn-default" href="#" onclick="checkAllAbove(event)"> + <span class="glyphicon glyphicon-arrow-up"></span> + Zaškrtnout vše + </a> + <td colspan="2"> + {{ wtf.form_field(edit_form.submit, class="btn btn-primary") }} + <a class="btn btn-default" href="{{ cancel_url }}">Zrušit</a> +</tfoot> +{% endif %} </table> </div> @@ -163,4 +176,30 @@ finální (ve výchozím stavu poslední nahrané).{% elif rights.can_upload_sol i.oninput(); } }); + + checkAllAbove = function() { + var state = false; + return function (e) { + e.preventDefault(); + var table = e.target; + while (table.tagName != 'TABLE') { table = table.parentNode; } + var checkboxes = table.querySelectorAll('tr.state-active input[type=checkbox]'); + + if (state) { + Array.prototype.forEach.call(checkboxes, function(el, i){ + el.checked = false; + el.onchange(); + }); + e.target.innerHTML = '<span class="glyphicon glyphicon-arrow-up"></span> Zaškrtnout vše'; + state = false; + } else { + Array.prototype.forEach.call(checkboxes, function(el, i){ + el.checked = true; + el.onchange(); + }); + e.target.innerHTML = '<span class="glyphicon glyphicon-arrow-up"></span> Odškrtnout vše'; + state = true; + } + } + }(); </script> -- GitLab