<commit_before>/**
 * Created by Mauriel on 2/9/2016.
 */

function label_ajax_submit() {
    var el = $(this);
    var dataFormID = el.attr("data-form-id");
    var formID = $("form[data-id='" + dataFormID + "']");
    var form = $(formID);
    var datastring = form.serialize();
    var url = form.attr('action');

    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === "success") {
                var action = form.find("input[name='action']");

                if (json_response.action === "CREATE")
                {
                    action.val("DELETE");
                    if (dataFormID == "form-add-to-my-resources")
                    {
                        $("#btnMyResources").removeClass("btn-resource-add");
                        $("#btnMyResources").addClass("btn-resource-remove");
                        $("#btnMyResources").attr("data-original-title", "Remove from my resources");
                    }
                    else if (dataFormID == "form-add-open-with-app")
                    {
                        $("#btnOpenWithApp").removeClass("btn-resource-add");
                        $("#btnOpenWithApp").addClass("btn-resource-remove");
                        $("#btnOpenWithApp").attr("data-original-title", "Remove WebApp from 'Open With' list");
                    }
                }
                else
                {
                    action.val("CREATE");
                    if (dataFormID == "form-add-to-my-resources") {
                        $("#btnMyResources").addClass("btn-resource-add");
                        $("#btnMyResources").removeClass("btn-resource-remove");
                        $("#btnMyResources").attr("data-original-title", "Add to my resources");
                    }
                    else if (dataFormID == "form-add-open-with-app")
                    {
                         $("#btnOpenWithApp").addClass("btn-resource-add");
                         $("#btnOpenWithApp").removeClass("btn-resource-remove");
                         $("#btnOpenWithApp").attr("data-original-title", "Add WebApp to 'Open With' list");
                    }
                }
                $("#btnMyResources").tooltip('show')
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown);
        }
    });
    //don't submit the form
    return false;
}

function change_access_ajax_submit(event) {
    let form = $(this).closest("form");
    let element = $(this);  // The access button that was pressed
    let action = element.attr("data-flag").trim();
    form.find("button").toggleClass("disabled", true);  // Disable buttons while request is being made
    form.find("input[name='flag']").val(action);
    let datastring = form.serialize();
    let url = form.attr('action');

    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === 'success') {
                form.find("button").removeAttr("disabled");
                form.find("button").removeClass("active");
                element.toggleClass("active", true);
                element.attr("disabled", true);
            }
            form.find("button").toggleClass("disabled", false);
        },
        error: function () {
            form.find("button").toggleClass("disabled", false);
        }
    });
    //don't submit the form
    return false;
}

function shareable_ajax_submit(event) {
    var form = $(this).closest("form");
    var datastring = form.serialize();
    var url = form.attr('action');
    var element = $(this);
    var action = $(this).closest("form").find("input[name='t']").val();
    element.attr("disabled", true);
    if (element.prop("checked")) {
        $("#shareable-description").text("Allows others to share the resource without owner’s permission.");
    }
    else {
        $("#shareable-description").text("Prevents others from sharing the resource without owner’s permission.");
    }
    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === 'success') {
                element.attr("disabled", false);
                if (action === "make_not_shareable") {
                    element.closest("form").find("input[name='t']").val("make_shareable");<commit_msg>Loading indicator and code cleanup<commit_after>/**
 * Created by Mauriel on 2/9/2016.
 */

function label_ajax_submit() {
    var el = $(this);
    var dataFormID = el.attr("data-form-id");
    var formID = $("form[data-id='" + dataFormID + "']");
    var form = $(formID);
    var datastring = form.serialize();
    var url = form.attr('action');

    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === "success") {
                var action = form.find("input[name='action']");

                if (json_response.action === "CREATE")
                {
                    action.val("DELETE");
                    if (dataFormID == "form-add-to-my-resources")
                    {
                        $("#btnMyResources").removeClass("btn-resource-add");
                        $("#btnMyResources").addClass("btn-resource-remove");
                        $("#btnMyResources").attr("data-original-title", "Remove from my resources");
                    }
                    else if (dataFormID == "form-add-open-with-app")
                    {
                        $("#btnOpenWithApp").removeClass("btn-resource-add");
                        $("#btnOpenWithApp").addClass("btn-resource-remove");
                        $("#btnOpenWithApp").attr("data-original-title", "Remove WebApp from 'Open With' list");
                    }
                }
                else
                {
                    action.val("CREATE");
                    if (dataFormID == "form-add-to-my-resources") {
                        $("#btnMyResources").addClass("btn-resource-add");
                        $("#btnMyResources").removeClass("btn-resource-remove");
                        $("#btnMyResources").attr("data-original-title", "Add to my resources");
                    }
                    else if (dataFormID == "form-add-open-with-app")
                    {
                         $("#btnOpenWithApp").addClass("btn-resource-add");
                         $("#btnOpenWithApp").removeClass("btn-resource-remove");
                         $("#btnOpenWithApp").attr("data-original-title", "Add WebApp to 'Open With' list");
                    }
                }
                $("#btnMyResources").tooltip('show')
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown);
        }
    });
    //don't submit the form
    return false;
}

function change_access_ajax_submit() {
    let form = $(this).closest("form");
    let element = $(this);  // The access button that was pressed
    form.find("input[name='flag']").val(element.attr("data-flag").trim());

    // Disable buttons while request is being made
    form.find("button").toggleClass("disabled", true);
    form.css("cursor", "progress");

    let datastring = form.serialize();
    let url = form.attr('action');

    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === 'success') {
                form.find("button").removeAttr("disabled");
                form.find("button").removeClass("active");
                element.toggleClass("active", true);
                element.attr("disabled", true);
            }
            form.find("button").toggleClass("disabled", false);
            form.css("cursor", "auto");
        },
        error: function () {
            form.find("button").toggleClass("disabled", false);
            form.css("cursor", "auto");
        }
    });

    return false;   //don't submit the form
}

function shareable_ajax_submit(event) {
    var form = $(this).closest("form");
    var datastring = form.serialize();
    var url = form.attr('action');
    var element = $(this);
    var action = $(this).closest("form").find("input[name='t']").val();
    element.attr("disabled", true);
    if (element.prop("checked")) {
        $("#shareable-description").text("Allows others to share the resource without owner’s permission.");
    }
    else {
        $("#shareable-description").text("Prevents others from sharing the resource without owner’s permission.");
    }
    $.ajax({
        type: "POST",
        url: url,
        dataType: 'html',
        data: datastring,
        success: function (result) {
            var json_response = JSON.parse(result);
            if (json_response.status === 'success') {
                element.attr("disabled", false);
                if (action === "make_not_shareable") {
                    element.closest("form").find("input[name='t']").val("make_shareable");
{'fraction_non_alphanumeric': 0.15847448820534138, 'fraction_numerical': 0.0012470123662059649, 'mean_word_length': 1.810747663551402, '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': '961019', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2478, 'n_words': 498}