<commit_before>{% extends 'reports/async/tabular.html' %}
{% load hq_shared_tags %}
{% load report_tags %}
{% load i18n %}

{% block js-inline %} {{ block.super }}
    <script>
    function updateFormCounts() {
        var selectedCount = $('#form-management').find('input.xform-checkbox:checked').length;
        $(".selectedCount").text(selectedCount);
        enable_disable_button(selectedCount);
    }

    function enable_disable_button(count){
        if (count == 0) {
            $("#submitForms").prop('disabled', true);
        }
        else {
            $("#submitForms").prop('disabled', false);
        }
    }

    (function () {
        function applyCheckboxBindings() {
            var $XFormManagement = $('#form-management');
            var $allFormsButton = $XFormManagement.find('input[name="select_all"]');
            var $checkboxes = $XFormManagement.find('input.xform-checkbox');
            var $indicator = $('#count_indicator');

            // bindings for 'all' button
            $XFormManagement.find('a.select-visible').click(function () {
                $allFormsButton.prop('checked', false);
                $checkboxes.prop('checked', true).change();
                return false;
            });

            // bindings for 'none' button
            $XFormManagement.find('a.select-none').click(function(){
                selectNone(); return false;
            });
            function selectNone() {
                $XFormManagement.find('input.xform-checkbox:checked').prop('checked', false).change();
                $allFormsButton.prop('checked', false);
            }

            // bindings for form checkboxes
            $checkboxes.on('change', function(){
                // updates text like '3 of 5 selected'
                updateFormCounts();
                $indicator.show();
            });
            $checkboxes.on('click', function(){
                $allFormsButton.prop('checked', false);
            });

            // bindings for 'Select all' checkboxe
            $allFormsButton.on('click', function(){
                if (this.checked) {
                    $checkboxes.prop('checked', true).change();
                    $indicator.hide();
                    enable_disable_button(1);
                    $(".selectedCount").text({{ total_xForms }});
                }
                else {
                    $indicator.show();
                    $(".selectedCount").text(0);
                    $XFormManagement.find('a.select-none').click();
                    enable_disable_button(0);
                }
            });

            $('#submitForms').click(function() {
                if ($allFormsButton[0].checked) {
                    hqImport('analytix/js/google').track.event('Bulk Archive', 'All', 'Checkbox');
                } else {
                    hqImport('analytix/js/google').track.event('Bulk Archive', 'All', 'Selected Forms');
                }
            })

            $XFormManagement.find('.dataTables_paginate a').mouseup(selectNone);
            $XFormManagement.find('.dataTables_length select').change(selectNone);
        }

        var keepTrying = setInterval(function () {
            if (window.reportTables !== undefined) {
                clearInterval(keepTrying);
                applyCheckboxBindings();
                window.reportTables.fnDrawCallback = applyCheckboxBindings;
            }
        }, 1000);

    }());
    </script>
{% endblock %}

{% block reportcontent %}
    <div id="form-management">
        <p class="alert fade in hide page-level-alert alert-danger" id="errorMessage">
            {% blocktrans %}
                Something went wrong! There was an error. If you see this error repeatedly please report it as issue.
            {% endblocktrans %}
        </p>
        <form method="post"
              action="{% url 'xform_management' domain %}"
              enctype="multipart/form-data">
                {% csrf_token %}
            {% if total_xForms > 0 %}
                <div id ="form_options" class="well form-inline" style="marging: 1em">
                    <div>
                        <button id="submitForms" disabled="true" class="btn {{ mode.button_class }}">{{ mode.button_text }}</button>
                        <label class="checkbox" >
                            <input type="checkbox" name="select_all" value="{{ form_query_string|urlencode }}" style="margin-left: 1em;">
                            {% blocktrans %}Select all {{ total_xForms }} forms{% endblocktrans %}
                        </label>
                    </div>
                    <div id="count_indicator">
                        <span class="label label-default">
                        {% blocktrans %}(<span class="selectedCount ">0</span> forms selected){% endblocktrans %}
                        </span>
                    </div>
                    <input type="hidden" name="mode" value="{{ mode.mode_name }}">
                </div><commit_msg>Rework archive_forms.html<commit_after>{% extends 'reports/async/tabular.html' %}
{% load hq_shared_tags %}
{% load report_tags %}
{% load i18n %}

{% block js-inline %} {{ block.super }}
    <script>

    var managementSelector = '#form-management',
        allFormsButtonSelector = managementSelector + ' input[name="select_all"]',
        checkboxesSelector = managementSelector + ' input.xform-checkbox',
        indicatorSelector = '#count_indicator';

    function updateFormCounts() {
        var selectedCount = $('#form-management').find('input.xform-checkbox:checked').length;
        $(".selectedCount").text(selectedCount);
        enable_disable_button(selectedCount);
    }

    function enable_disable_button(count){
        if (count == 0) {
            $("#submitForms").prop('disabled', true);
        }
        else {
            $("#submitForms").prop('disabled', false);
        }
    }

    function selectNone() {
        $(managementSelector + ' input.xform-checkbox:checked').prop('checked', false).change();
        $(allFormsButtonSelector).prop('checked', false);
    }

    $(function() {
        // bindings for 'all' button
        $(document).on('click', managementSelector + ' a.select-visible', function() {
            $(allFormsButtonSelector).prop('checked', false);
            $(checkboxesSelector).prop('checked', true).change();
            return false;
        });

        // bindings for 'none' button
        $(document).on('click', managementSelector + ' a.select-none', function() {
            selectNone();
            return false;
        });

        // bindings for form checkboxes
        $(document).on('change', checkboxesSelector, function() {
            // updates text like '3 of 5 selected'
            updateFormCounts();
            $(indicatorSelector).show();
        });
        $(document).on('click', checkboxesSelector, function() {
            $(allFormsButtonSelector).prop('checked', false);
        });

        // bindings for 'Select all' checkboxes
        $(document).on('click', allFormsButtonSelector, function() {
            if (this.checked) {
                $(checkboxesSelector).prop('checked', true).change();
                $(indicatorSelector).hide();
                enable_disable_button(1);
            }
            else {
                $(indicatorSelector).show();
                $(".selectedCount").text(0);
                $(managementSelector + ' a.select-none').click();
                enable_disable_button(0);
            }
        });

        // clear checkboxes when changing page
        $(document).on('mouseup', managementSelector + ' .dataTables_paginate a', selectNone);
        $(document).on('change', managementSelector + ' .dataTables_length select', selectNone);

        $(document).on('click', '#submitForms', function() {
            if ($(allFormsButtonSelector)[0].checked) {
                hqImport('analytix/js/google').track.event('Bulk Archive', 'All', 'Checkbox');
            } else {
                hqImport('analytix/js/google').track.event('Bulk Archive', 'All', 'Selected Forms');
            }
        })
    });

    </script>
{% endblock %}

{% block reportcontent %}
    <div id="form-management">
        <p class="alert fade in hide page-level-alert alert-danger" id="errorMessage">
            {% blocktrans %}
                Something went wrong! There was an error. If you see this error repeatedly please report it as issue.
            {% endblocktrans %}
        </p>
        <form method="post"
              action="{% url 'xform_management' domain %}"
              enctype="multipart/form-data">
                {% csrf_token %}
            {% if total_xForms > 0 %}
                <div id ="form_options" class="well form-inline" style="marging: 1em">
                    <div>
                        <button id="submitForms" disabled="true" class="btn {{ mode.button_class }}">{{ mode.button_text }}</button>
                        <label class="checkbox" >
                            <input type="checkbox" name="select_all" value="{{ form_query_string|urlencode }}" style="margin-left: 1em;">
                            {% blocktrans %}Select all {{ total_xForms }} forms{% endblocktrans %}
                        </label>
                    </div>
                    <div id="count_indicator">
                        <span class="label label-default">
                        {% blocktrans %}(<span class="selectedCount ">0</span> forms selected){% endblocktrans %}
                        </span>
                    </div>
                    <input type="hidden" name="mode" value="{{ mode.mode_name }}">
                </div>
{'fraction_non_alphanumeric': 0.14524103831891225, 'fraction_numerical': 0.0030902348578491965, 'mean_word_length': 1.833090166326233, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 49, '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': '1377282', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2382, 'n_words': 478}