<commit_before>{% extends 'moderate/base.twig' %}

{% block content %}
    <header class="subhead">
        <h1>{{ quiz.getName() }}</h1>
    </header>
    <ul class="nav nav-tabs" id="rounds_tab">
        {% for round in rounds %}
            <li>
                <a href="#round{{ round.getId() }}" data-toggle="tab">{{ round.getName() }}</a>
            </li>
        {% endfor %}
    </ul>
    <div class="tab-content" id="rounds_tab-content">
        {% for round in rounds %}
            <div id="round{{ round.getId() }}" class="tab-pane fade in form-horizontal">
                {% for team in teams %}
                    <div class="control-group">
                        <label class="control-label" for="input-{{ team.getId() }}-{{ round.getId() }}">{{ team.getName() }}</label>
                        <div class="controls">
                            <input type="number" min="0" max="{{ round.getMaxPoints() }}" step="1" id="input-{{ team.getId() }}-{{ round.getId() }}" data-team="{{ team.getId() }}" data-round="{{ round.getId() }}" class="input-xlarge roundScore" value="{% if points[team.getId()][round.getId()] is not defined %}0{% else %}{{ points[team.getId()][round.getId()] }}{% endif %}">
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% endfor %}
    </div>
{% endblock %}

{% block content_script %}
    <script>
    $(document).ready(function () {
        $('#rounds_tab li:first').addClass('active');
        $('#rounds_tab-content .tab-pane:first').addClass('active');

        $('.roundScore').keyup(function (e) {
            if (e.keyCode == 13) {
                var next = $(this).parent().parent().next().find('.roundScore');
                next.focus().select();
                if (next.find('.roundScore').length == 0)
                    $(this).blur();
            }
        }).blur(function () {
            var field = $(this);
            field.parent().parent().removeClass('success').removeClass('error');
            if(parseInt(field.val(),10) > parseInt(field.attr('max'),10)) {
                field.parent().parent().addClass('error');
                return;
            }
            var url = '{{ url('quiz_admin_moderate', {'action': 'update', 'quizid': quiz.getId()})}}'+$(this).data('round') + '/' + $(this).data('team')
            $.ajax({
                url: url,
                type: 'post',
                data: {score: $(this).val()},
                dataType: 'json',
                success: function () {
                    field.parent().parent().addClass('success');
                },
                error: function () {
                    field.parent().parent().addClass('error');
                }
            });
        });
    });
    </script>
{% endblock %}<commit_msg>QuizBundle: Warn when leaving page before scores saved<commit_after>{% extends 'moderate/base.twig' %}

{% block content %}
    <header class="subhead">
        <h1>{{ quiz.getName() }}</h1>
    </header>
    <ul class="nav nav-tabs" id="rounds_tab">
        {% for round in rounds %}
            <li>
                <a href="#round{{ round.getId() }}" data-toggle="tab">{{ round.getName() }}</a>
            </li>
        {% endfor %}
    </ul>
    <div class="tab-content" id="rounds_tab-content">
        {% for round in rounds %}
            <div id="round{{ round.getId() }}" class="tab-pane fade in form-horizontal">
                {% for team in teams %}
                    <div class="control-group">
                        <label class="control-label" for="input-{{ team.getId() }}-{{ round.getId() }}">{{ team.getName() }}</label>
                        <div class="controls">
                            <input type="number" min="0" max="{{ round.getMaxPoints() }}" step="1" id="input-{{ team.getId() }}-{{ round.getId() }}" data-team="{{ team.getId() }}" data-round="{{ round.getId() }}" class="input-xlarge roundScore" value="{% if points[team.getId()][round.getId()] is not defined %}0{% else %}{{ points[team.getId()][round.getId()] }}{% endif %}">
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% endfor %}
    </div>
{% endblock %}

{% block content_script %}
    <script>
    var ajax_requests_pending = 0;
    $(document).ready(function () {
        $('#rounds_tab li:first').addClass('active');
        $('#rounds_tab-content .tab-pane:first').addClass('active');

        $('.roundScore').keyup(function (e) {
            if (e.keyCode == 13) {
                var next = $(this).parent().parent().next().find('.roundScore');
                next.focus().select();
                if (next.find('.roundScore').length == 0)
                    $(this).blur();
            }
        }).blur(function () {
            var field = $(this);
            field.parent().parent().removeClass('success').removeClass('error');
            if(parseInt(field.val(),10) > parseInt(field.attr('max'),10)) {
                field.parent().parent().addClass('error');
                return;
            }
            ajax_requests_pending++;
            var url = '{{ url('quiz_admin_moderate', {'action': 'update', 'quizid': quiz.getId()})}}'+$(this).data('round') + '/' + $(this).data('team')
            $.ajax({
                url: url,
                type: 'post',
                data: {score: $(this).val()},
                dataType: 'json',
                success: function () {
                    field.parent().parent().addClass('success');
                    ajax_requests_pending--;
                },
                error: function () {
                    field.parent().parent().addClass('error');
                    ajax_requests_pending--;
                }
            });
        });
    });

    $(window).on('beforeunload', function() {
        if(ajax_requests_pending > 0)
            return 'Not all scores have been saved. Are you sure you want to leave this page?';
    });
    </script>
{% endblock %}
{'fraction_non_alphanumeric': 0.20039748261013582, 'fraction_numerical': 0.004306061609804571, 'mean_word_length': 1.766376546037563, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, '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': '138289', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1663, 'n_words': 325}