<commit_before>window.TaskBox = (function($) {
return function(context, type) {
    'use strict';

    function submitTask(type, action, data, callback) {
        var url = '/tasks/' + type;

        if (data.id)
            url += '/' + data.id;

        $.ajax({
            url: url,
            type: action,
            dataType: 'html',
            data: JSON.stringify(data),
            contentType: 'application/json; charset=utf-8',
            success: callback
        });
    }

    var taskBox = {
        completeTask: function(e) {
            var $taskRow = $(this).closest('.task-row');

            var data = {
                id: $taskRow.data('id'),
                isComplete: $(this).prop('checked')
            };

            var action = type === 'one-shot' ? 'DELETE' : 'PUT';

            submitTask(type, action, data, function() {
                if (action === 'DELETE')
                    $taskRow.remove();
            });
        },

        beginEdit: function() {
            var $this = $(this);

            $this.parents('.view-panel')
                .hide()
                .siblings('.edit-panel')
                .show()
                .children('.name-input')
                .val($this.text());
        },

        endEdit: function() {
            var $this = $(this);

            if (!$this.val())
                return taskBox.cancelEdit.call(this);

            var data = {
                id: $this.closest('.task-row').data('id'),
                name: $this.val()
            };

            submitTask(type, 'PUT', data, function() {
                $this.parents('.edit-panel')
                    .hide()
                    .siblings('.view-panel')
                    .show()
                    .children('.name-label')
                    .text($(this).val());
            });
        },

        cancelEdit: function() {
            $(this).parents('.edit-panel')
                .hide()
                .siblings('.view-panel')
                .show();
        },

        editKeypress: function(e) {
            switch (e.which) {
                case 13:
                    e.preventDefault();
                    $(this).blur();
                    break;

                case 27:
                    e.preventDefault();
                    $(this).val('');
                    $(this).blur();
                    break;
            }
        },

        deleteTask: function() {
            var $taskRow = $(this).parents('.task-row');
            var data = {id: $taskRow.data('id')};

            submitTask(type, 'DELETE', data, function() {
                $taskRow.remove();
            });
        },

        beginAdd: function() {
            var $this = $(this);

            $this.parents('.view-panel')
                .hide()
                .siblings('.edit-panel')
                .show()
                .children('.name-input')
                .val('');
        },

        endAdd: function() {
            var $this = $(this);

            if (!$this.val())
                return taskBox.hideAdd.call(this);

            var data = {
                name: $this.val(),<commit_msg>Issues #1-3 Fixed<commit_after>window.TaskBox = (function($) {
return function(context, type) {
    'use strict';

    function submitTask(type, action, data, callback) {
        var url = '/tasks/' + type;

        if (data.id)
            url += '/' + data.id;

        $.ajax({
            url: url,
            type: action,
            dataType: 'html',
            data: JSON.stringify(data),
            contentType: 'application/json; charset=utf-8',
            success: callback
        });
    }

    var taskBox = {
        completeTask: function(e) {
            var $taskRow = $(this).closest('.task-row');

            var data = {
                id: $taskRow.data('id'),
                isComplete: $(this).prop('checked')
            };

            var action = type === 'one-shot' ? 'DELETE' : 'PUT';

            submitTask(type, action, data, function() {
                if (action === 'DELETE')
                    $taskRow.remove();
            });
        },

        beginEdit: function() {
            var $this = $(this);

            $this.parents('.view-panel')
                .hide()
                .siblings('.edit-panel')
                .show()
                .children('.name-input')
                .val($this.text())
                .focus();
        },

        endEdit: function() {
            var $this = $(this);

            if (!$this.val())
                return taskBox.cancelEdit.call(this);

            var data = {
                id: $this.closest('.task-row').data('id'),
                name: $this.val()
            };

            submitTask(type, 'PUT', data, function() {
                $this.parents('.edit-panel')
                    .hide()
                    .siblings('.view-panel')
                    .show()
                    .children('.name-label')
                    .text($this.val());
            });
        },

        cancelEdit: function() {
            $(this).parents('.edit-panel')
                .hide()
                .siblings('.view-panel')
                .show();
        },

        editKeypress: function(e) {
            switch (e.which) {
                case 13:
                    e.preventDefault();
                    $(this).blur();
                    break;

                case 27:
                    e.preventDefault();
                    $(this).val('');
                    $(this).blur();
                    break;
            }
        },

        deleteTask: function() {
            var $taskRow = $(this).parents('.task-row');
            var data = {id: $taskRow.data('id')};

            submitTask(type, 'DELETE', data, function() {
                $taskRow.remove();
            });
        },

        beginAdd: function() {
            var $this = $(this);

            $this.parents('.view-panel')
                .hide()
                .siblings('.edit-panel')
                .show()
                .children('.add-input')
                .val('')
                .focus();
        },

        endAdd: function() {
            var $this = $(this);

            if (!$this.val())
                return taskBox.hideAdd.call(this);

            var data = {
                name: $this.val(),
{'fraction_non_alphanumeric': 0.1554825590489598, 'fraction_numerical': 0.0018770530267480056, 'mean_word_length': 1.0441176470588236, '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': '315221', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1607, 'n_words': 315}