<commit_before>$(document).ready(function () {
    var itemsController = (function () {
        var urlBase = "api/items";
        var itemsTableBody = $("#items-table-body");
        var createItemForm = $("#create-item-form");
        var selectedItemId;
        var itemTemplate = function (id, name) {
            return "" +
                "<tr>" +
                "   <td>" + name + "</td>" +
                "   <td>" +
                "       <button class=\"btn btn-info pull-right view-item-btn\" data-item-id=\"" + id + "\">" +
                "           view" +
                "       </button>" +
                "   </td>" +
                "   <td>" +
                "       <button class=\"btn btn-success pull-right update-item-btn\" data-item-id=\"" + id + "\">" +
                "           update" +
                "       </button>" +
                "   </td>" +
                "   <td>" +
                "       <button class=\"btn btn-warning pull-right delete-item-btn\" data-item-id=\"" + id + "\">" +
                "           delete" +
                "       </button>" +
                "   </td>" +
                "</tr>";
        };

        var init = function () {
            reloadItems();
            bindForms();
            bindButtons();
        };
        var bindForms = function () {
            createItemForm.submit(function (e) {
                e.preventDefault();
                saveItem();
            });

            $("#update-item-form").submit(function (e) {
                e.preventDefault();
                $("#updateItemModal").modal('hide');
                updateItem(selectedItemId);
            });
        };
        var bindButtons = function () {
            itemsTableBody.on('click', '.view-item-btn', function () {
                selectItem($(this).data('item-id'), 'view');
            });
            itemsTableBody.on('click', '.update-item-btn', function () {
                selectItem($(this).data('item-id'), 'update');
            });
            itemsTableBody.on('click', '.delete-item-btn', function () {
                selectItem($(this).data('item-id'), 'delete');
            });

            $("#confirm-item-deletion").click(function () {
                $("#deleteItemModal").modal('hide');
                deleteItem(selectedItemId);
            });
        };
        var selectItem = function (itemId, action) {
            var apiUrl = urlBase + "/" + itemId;
            $.get(apiUrl, function (item) {
                if (item) {
                    selectedItemId = item.id;
                    switch (action) {
                        case 'view':
                            $("#item-name-view").text(item.name);
                            $("#item-description-view").text(item.description);
                            $("#viewItemModal").modal('show');
                            break;
                        case 'update':
                            $("#item-name-update").val(item.name);
                            $("#item-description-update").val(item.description);
                            $("#updateItemModal").modal('show');
                            break;
                        case 'delete':
                            $("#delete-item-name").text(item.name);
                            $("#deleteItemModal").modal('show');
                            break;
                    }
                }
            });
        };
        var reloadItems = function () {
            $.get(urlBase, function (data) {
                itemsTableBody.empty();
                $.each(data, function (i, item) {
                    itemsTableBody.append(itemTemplate(item.id, item.name, item.description));
                });
                if (!data.length) {
                    itemsTableBody.append('<tr><td>No items</td><td></td><td></td><td></td></tr>');
                }
            });
        };
        var saveItem = function () {
            var newItemName = $("#new-item-name");
            var newItemDescription = $("#new-item-description");
            var createItemData = JSON.stringify({
                name: newItemName.val(),
                description: newItemDescription.val()
            });
            $.ajax({
                type: "POST",
                url: urlBase,
                data: createItemData,
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function () {
                    newItemName.val("");
                    newItemDescription.val("");
                    reloadItems();
                }
            });
        };
        var deleteItem = function (itemId) {
            var apiUrl = urlBase + "/" + itemId;
            $.ajax({
                type: "DELETE",
                url: apiUrl,
                success: function () {
                    selectedItemId = null;
                    reloadItems();
                }
            });
        };
        var updateItem = function (itemId) {
            var apiUrl = urlBase + "/" + itemId;
            var newItemName = $("#item-name-update");
            var newItemDescription = $("#item-description-update");
            var updateItemData = JSON.stringify({
                name: newItemName.val(),
                description: newItemDescription.val()
            });
            $.ajax({
                type: "PUT",
                data: updateItemData,
                url: apiUrl,
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function () {
                    selectedItemId = null;
                    reloadItems();
                }
            });
        };<commit_msg>Replace 'success' with 'done' in ajax calls<commit_after>$(document).ready(function () {
    var itemsController = (function () {
        var urlBase = "api/items";
        var itemsTableBody = $("#items-table-body");
        var createItemForm = $("#create-item-form");
        var selectedItemId;
        var itemTemplate = function (id, name) {
            return "" +
                "<tr>" +
                "   <td>" + name + "</td>" +
                "   <td>" +
                "       <button class=\"btn btn-info pull-right view-item-btn\" data-item-id=\"" + id + "\">" +
                "           view" +
                "       </button>" +
                "   </td>" +
                "   <td>" +
                "       <button class=\"btn btn-success pull-right update-item-btn\" data-item-id=\"" + id + "\">" +
                "           update" +
                "       </button>" +
                "   </td>" +
                "   <td>" +
                "       <button class=\"btn btn-warning pull-right delete-item-btn\" data-item-id=\"" + id + "\">" +
                "           delete" +
                "       </button>" +
                "   </td>" +
                "</tr>";
        };

        var init = function () {
            reloadItems();
            bindForms();
            bindButtons();
        };
        var bindForms = function () {
            createItemForm.submit(function (e) {
                e.preventDefault();
                saveItem();
            });

            $("#update-item-form").submit(function (e) {
                e.preventDefault();
                $("#updateItemModal").modal('hide');
                updateItem(selectedItemId);
            });
        };
        var bindButtons = function () {
            itemsTableBody.on('click', '.view-item-btn', function () {
                selectItem($(this).data('item-id'), 'view');
            });
            itemsTableBody.on('click', '.update-item-btn', function () {
                selectItem($(this).data('item-id'), 'update');
            });
            itemsTableBody.on('click', '.delete-item-btn', function () {
                selectItem($(this).data('item-id'), 'delete');
            });

            $("#confirm-item-deletion").click(function () {
                $("#deleteItemModal").modal('hide');
                deleteItem(selectedItemId);
            });
        };
        var selectItem = function (itemId, action) {
            var apiUrl = urlBase + "/" + itemId;
            $.get(apiUrl, function (item) {
                if (item) {
                    selectedItemId = item.id;
                    switch (action) {
                        case 'view':
                            $("#item-name-view").text(item.name);
                            $("#item-description-view").text(item.description);
                            $("#viewItemModal").modal('show');
                            break;
                        case 'update':
                            $("#item-name-update").val(item.name);
                            $("#item-description-update").val(item.description);
                            $("#updateItemModal").modal('show');
                            break;
                        case 'delete':
                            $("#delete-item-name").text(item.name);
                            $("#deleteItemModal").modal('show');
                            break;
                    }
                }
            });
        };
        var reloadItems = function () {
            $.get(urlBase, function (data) {
                itemsTableBody.empty();
                $.each(data, function (i, item) {
                    itemsTableBody.append(itemTemplate(item.id, item.name, item.description));
                });
                if (!data.length) {
                    itemsTableBody.append('<tr><td>No items</td><td></td><td></td><td></td></tr>');
                }
            });
        };
        var saveItem = function () {
            var newItemName = $("#new-item-name");
            var newItemDescription = $("#new-item-description");
            var createItemData = JSON.stringify({
                name: newItemName.val(),
                description: newItemDescription.val()
            });
            $.ajax({
                type: "POST",
                url: urlBase,
                data: createItemData,
                dataType: "json",
                contentType: "application/json; charset=utf-8"
            }).done(function () {
                newItemName.val("");
                newItemDescription.val("");
                reloadItems();
            });
        };
        var deleteItem = function (itemId) {
            var apiUrl = urlBase + "/" + itemId;
            $.ajax({
                type: "DELETE",
                url: apiUrl
            }).done(function () {
                selectedItemId = null;
                reloadItems();
            });
        };
        var updateItem = function (itemId) {
            var apiUrl = urlBase + "/" + itemId;
            var newItemName = $("#item-name-update");
            var newItemDescription = $("#item-description-update");
            var updateItemData = JSON.stringify({
                name: newItemName.val(),
                description: newItemDescription.val()
            });
            $.ajax({
                type: "PUT",
                data: updateItemData,
                url: apiUrl,
                dataType: "json",
                contentType: "application/json; charset=utf-8"
            }).done(function () {
                selectedItemId = null;
                reloadItems();
            });
        };
{'fraction_non_alphanumeric': 0.1490418118466899, 'fraction_numerical': 0.0003484320557491289, 'mean_word_length': 1.1081527726771943, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '521607', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2727, 'n_words': 483}