<commit_before>$( document ).ready(function() {
    var id, page;

    $('button[data-action=create-questionnaire]').click(function() {
        $.post('/ajax', {action: 'create-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=duplicate]').click(function(event) {
        id = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'duplicate-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });
    $('button[data-action=delete]').click(function(event) {
        if (!confirm('Are you sure you want to delete this questionnaire?')) {
            return false;
        }
        id = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'delete-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    var hiddenId;
    if (hiddenId = $('#questionnaire-id')) {
        id = hiddenId.val();
    }
    if (hiddenId = $('#page-number')) {
        page = hiddenId.val();
    }

    var ajaxStatus = $('#ajax-status');
    var activeCalls = 0;
    var timeout;

    function showAjax() {
        clearInterval(timeout);
        ajaxStatus.show();
        ajaxStatus.children().text('Saving...');
        activeCalls++;
    }

    function clearAjax() {
        activeCalls--;
        if (activeCalls == 0) {
            ajaxStatus.children().text('Saved!');
            timeout = setTimeout(function() {
                ajaxStatus.hide();
            }, 3000);
        }
    }

    function reloadPage() {
        clearAjax();
        location.reload();
    }

    $('#update-title').change(function(event) {
        var text = $(event.target).val();
        $.post('/ajax', {id: id, action: 'update-title', page: page, text: text});
    });

    $('#update-intro').change(function(event) {
        var text = $(event.target).val();
        $.post('/ajax', {id: id, action: 'update-intro', page: page, text: text});
    });

    $('button[data-action=page-duplicate]').click(function(event) {
        page = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'duplicate-page', page: page}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=page-delete]').click(function(event) {
        if (!confirm('Are you sure you want to delete this page?')) {
            return false;
        }
        page = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'delete-page', page: page}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=move-page]').click(function(event) {
        var page = $(event.target).attr('data-id');
        var movement = $(event.target).attr('data-movement');
        $.post('/ajax', {id: id, action: 'move-page', page: page, movement: movement}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=page-create]').click(function() {
        $.post('/ajax', {id: id, action: 'create-page'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });<commit_msg>Page deletion now uses AJAX<commit_after>$( document ).ready(function() {
    var id, page;

    $('button[data-action=create-questionnaire]').click(function() {
        $.post('/ajax', {action: 'create-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=duplicate]').click(function(event) {
        id = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'duplicate-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });
    $('button[data-action=delete]').click(function(event) {
        if (!confirm('Are you sure you want to delete this questionnaire?')) {
            return false;
        }
        id = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'delete-questionnaire'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    var hiddenId;
    if (hiddenId = $('#questionnaire-id')) {
        id = hiddenId.val();
    }
    if (hiddenId = $('#page-number')) {
        page = hiddenId.val();
    }

    var ajaxStatus = $('#ajax-status');
    var activeCalls = 0;
    var timeout;

    function showAjax() {
        clearInterval(timeout);
        ajaxStatus.show();
        ajaxStatus.children().text('Saving...');
        activeCalls++;
    }

    function clearAjax() {
        activeCalls--;
        if (activeCalls == 0) {
            ajaxStatus.children().text('Saved!');
            timeout = setTimeout(function() {
                ajaxStatus.hide();
            }, 3000);
        }
    }

    function reloadPage() {
        clearAjax();
        location.reload();
    }

    $('#update-title').change(function(event) {
        var text = $(event.target).val();
        $.post('/ajax', {id: id, action: 'update-title', page: page, text: text});
    });

    $('#update-intro').change(function(event) {
        var text = $(event.target).val();
        $.post('/ajax', {id: id, action: 'update-intro', page: page, text: text});
    });

    $('button[data-action=page-duplicate]').click(function(event) {
        page = $(event.target).attr('data-id');
        $.post('/ajax', {id: id, action: 'duplicate-page', page: page}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=page-delete]').click(function(event) {
        if (!confirm('Are you sure you want to delete this page?')) {
            return false;
        }

        var row = $(event.target).parents('tr');
        var table = row.parents('table');
        var page = row.attr('data-id');

        $.post('/ajax', {id: id, action: 'delete-page', page: page});
        row.effect('highlight').effect({effect: 'fade', complete: function() {
            row.remove();

            table.children('tbody').children().each(function (index, value) {
                var row2 = $(value);
                row2.attr('data-id', index + 1);
                row2.children().first().text(index + 1);
            });
        }});
    });

    $('button[data-action=move-page]').click(function(event) {
        var page = $(event.target).attr('data-id');
        var movement = $(event.target).attr('data-movement');
        $.post('/ajax', {id: id, action: 'move-page', page: page, movement: movement}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });

    $('button[data-action=page-create]').click(function() {
        $.post('/ajax', {id: id, action: 'create-page'}, function() {
            location.reload();
        });
        $('button').prop('disabled', true);
    });
{'fraction_non_alphanumeric': 0.20693979933110368, 'fraction_numerical': 0.0023690078037904125, 'mean_word_length': 2.2726858185134517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '733672', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2063, 'n_words': 397}