diff --git a/mo/web/templates/parts/org_solution_js.html b/mo/web/templates/parts/org_solution_js.html new file mode 100644 index 0000000000000000000000000000000000000000..80d9fc73d08ace119de07a1301964a7ef50b21c8 --- /dev/null +++ b/mo/web/templates/parts/org_solution_js.html @@ -0,0 +1,41 @@ +{# Společný JavaScript a checkbox povolující zakládání pro tabulky řešení #} + +{% if edit %} +<script type="text/javascript"> + window.addEventListener("load", function() { + for (const ch of document.querySelectorAll("input[type=checkbox]")) { + ch.onchange(); + } + for (const i of document.querySelectorAll("input[type=text]")) { + i.oninput(); + } + }); + + function update_disabled_fields(allow_create) { + for (const i of document.querySelectorAll("input[type=text]")) { + if (i.dataset.sol == "0") { + i.disabled = !allow_create; + } + } + } +</script> +{% endif %} + +{% if edit_create %} +<div class="form-group"><div class="checkbox"> + <label> + <input + type="checkbox" + name="create_sols" + onchange="update_disabled_fields(this.checked)" + value="y" + {% if not edit_create %} + disabled + {% elif not ctx.contest.online_submit %} + checked + {% endif %} + > + Zakládat nová řešení + </label> +</div></div> +{% endif %} diff --git a/mo/web/templates/parts/org_solution_table.html b/mo/web/templates/parts/org_solution_table.html index 83e28d1b21cda86e59821f55c8d8f96cec96f6fa..3b3252ade5a68c87daadd5ebb007002567c557fa 100644 --- a/mo/web/templates/parts/org_solution_table.html +++ b/mo/web/templates/parts/org_solution_table.html @@ -148,43 +148,4 @@ finální (ve výchozím stavu poslední nahrané).{% elif rights.can_upload_sol {% endfor %} </table> -{% if edit %} -<script type="text/javascript"> - window.addEventListener("load", function() { - for (const ch of document.querySelectorAll("input[type=checkbox]")) { - ch.onchange(); - } - for (const i of document.querySelectorAll("input[type=text]")) { - i.oninput(); - } - }); - - function update_disabled_fields(allow_create) { - for (const i of document.querySelectorAll("input[type=text]")) { - if (i.dataset.sol == "0") { - i.disabled = !allow_create; - } - } - } -</script> -{% endif %} - -{% if edit_create %} -<div class="form-group"><div class="checkbox"> - <label> - <input - type="checkbox" - name="create_sols" - onchange="update_disabled_fields(this.checked)" - tabindex={{ tabindex.value }} autofocus - value="y" - {% if not edit_create %} - disabled - {% elif not contest_online_submit %} - checked - {% endif %} - > - Zakládat nová řešení - </label> -</div></div> -{% endif %} +{% include "parts/org_solution_js.html" %}