<commit_before>{% extends base_template|default:"base.html" %}

{% load i18n towel_form_tags %}

{% block title %}{{ title }} - {{ block.super }}{% endblock %}

{% block content %}
<h2>{{ title }}</h2>

<form method="post" action=".">{% csrf_token %}
{% form_errors form formsets %}

<table>
{% for field in form %}{% form_item field %}{% endfor %}
</table>

<h3>{% trans "Periods" %}
{{ formsets.periods.management_form }}
<table>
    <thead>
        <tr>
            <th>{% trans "Specification" %}</th>
            <th>{% trans "From" %}</th>
            <th>{% trans "Delete" %}</th>
        </tr>
    </thead>
    <tbody>
    {% dynamic_formset formsets.periods "periods" %}
        <tr id="{{ form_id }}" {% if empty %}class="empty"{% endif %}>
            <td>
                {{ form.id }}
                {% form_item_plain form.specification %}
            </td>
            <td>{% form_item_plain form.date_from %}</td>
            <td>{{ form.DELETE }}</td>
        </tr>
    {% enddynamic_formset %}
    </tbody>
    <tfoot>
        <tr><td colspan="3">
        <button type="button" onclick="towel_add_subform('periods')">{% trans "New period" %}</button>
        </td></tr>
    </tfoot>
</table>

<table>
    <tr>
        <td>&nbsp;</td>
        <td>
            <button type="submit">{% trans "Save" %}</button>
            <button type="submit" name="_continue">{% trans "Save and continue editing" %}</button>
            <button type="button" onclick="window.location.assign('../')">{% trans "Cancel" %}</button>
        </td>
    </tr>
</table>
</form>

<style type="text/css">
.empty { display: none; }

.invalid label { color: red; }
.invalid input { border-color: red; }
</style>
{% endblock %}
<commit_msg>Expense report editing: Automatically update working_days via Javascript<commit_after>{% extends base_template|default:"base.html" %}

{% load i18n towel_form_tags %}

{% block title %}{{ title }} - {{ block.super }}{% endblock %}

{% block content %}
<h2>{{ title }}</h2>

<form method="post" action=".">{% csrf_token %}
{% form_errors form formsets %}

<table>
{% for field in form %}{% form_item field %}{% endfor %}
</table>

<h3>{% trans "Periods" %}
{{ formsets.periods.management_form }}
<table>
    <thead>
        <tr>
            <th>{% trans "Specification" %}</th>
            <th>{% trans "From" %}</th>
            <th>{% trans "Delete" %}</th>
        </tr>
    </thead>
    <tbody>
    {% dynamic_formset formsets.periods "periods" %}
        <tr id="{{ form_id }}" {% if empty %}class="empty"{% endif %}>
            <td>
                {{ form.id }}
                {% form_item_plain form.specification %}
            </td>
            <td>{% form_item_plain form.date_from %}</td>
            <td>{{ form.DELETE }}</td>
        </tr>
    {% enddynamic_formset %}
    </tbody>
    <tfoot>
        <tr><td colspan="3">
        <button type="button" onclick="towel_add_subform('periods')">{% trans "New period" %}</button>
        </td></tr>
    </tfoot>
</table>

<table>
    <tr>
        <td>&nbsp;</td>
        <td>
            <button type="submit">{% trans "Save" %}</button>
            <button type="submit" name="_continue">{% trans "Save and continue editing" %}</button>
            <button type="button" onclick="window.location.assign('../')">{% trans "Cancel" %}</button>
        </td>
    </tr>
</table>
</form>

<script type="text/javascript">
$(function() {
    var working_days = $('#{{ form.working_days.auto_id }}');
    var free_days = $('#{{ form.free_days.auto_id }}');

    var holi_days = $('#{{ form.holi_days.auto_id }}');
    var sick_days = $('#{{ form.sick_days.auto_id }}');
    var forced_leave_days = $('#{{ form.forced_leave_days.auto_id }}');

    working_days.attr('readonly', 'readonly');

    var total = parseInt(working_days.val()) + parseInt(free_days.val()) +
        parseInt(holi_days.val()) + parseInt(sick_days.val()) +
        parseInt(forced_leave_days.val());

    function recalculate() {
        var minus = parseInt(free_days.val()) +
            parseInt(holi_days.val()) + parseInt(sick_days.val()) +
            parseInt(forced_leave_days.val());

        working_days.val(total - minus);
    }

    free_days.blur(recalculate);
    holi_days.blur(recalculate);
    sick_days.blur(recalculate);
    forced_leave_days.blur(recalculate);
});
</script>
<style type="text/css">
.empty { display: none; }

.invalid label { color: red; }
.invalid input { border-color: red; border-left: 5px solid red; padding-left: 5px; }

input { border: 1px solid #cfcfcf; padding: 5px 5px 5px 9px; }
input[readonly] { background: #e8e8e8; }
</style>
{% endblock %}

{'fraction_non_alphanumeric': 0.20051635111876076, 'fraction_numerical': 0.004733218588640275, 'mean_word_length': 2.704382470119522, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '401984', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1547, 'n_words': 338}