<commit_before>var todoList = document.getElementById("todo-list");
var todoListPlaceholder = document.getElementById("todo-list-placeholder");
var form = document.getElementById("todo-form");
var todoTitle = document.getElementById("new-todo");
var error = document.getElementById("error");
var counter = document.getElementById("count-label");

form.onsubmit = function(event) {
    var title = todoTitle.value;
    createTodo(title, function() {
        reloadTodoList();
    });
    todoTitle.value = "";
    event.preventDefault();
};

function createTodo(title, callback) {
    var createRequest = new XMLHttpRequest();
    createRequest.open("POST", "/api/todo");
    createRequest.setRequestHeader("Content-type", "application/json");
    createRequest.send(JSON.stringify({
        title: title
    }));
    createRequest.onload = function() {
        if (this.status === 201) {
            callback();
        } else {
            error.textContent = "Failed to create item. Server returned " + this.status + " - " + this.responseText;
        }
    };
}
function updateTodo(id, title, callback) {
    var updateRequest = new XMLHttpRequest();
    updateRequest.open("PUT", "/api/todo" + id);
    updateRequest.setRequestHeader("Content-type", "application/json");
    updateRequest.send(JSON.stringify({
        title: title
    }));
    updateRequest.onload = function() {
        if (this.status === 200) {
            callback();
        } else {
            error.textContent = "Failed to update item. Server returned " + this.status + " - " + this.responseText;
        }
    };
}

function getTodoList(callback) {
    var createRequest = new XMLHttpRequest();
    createRequest.open("GET", "/api/todo");
    createRequest.onload = function() {
        if (this.status === 200) {
            callback(JSON.parse(this.responseText));
        } else {
            error.textContent = "Failed to get list. Server returned " + this.status + " - " + this.responseText;
        }
    };
    createRequest.send();
}

function deleteTodo(event) {
    if (event && event.target) {
        var id = event.target.getAttribute("data-id");
        var deleteRequest = new XMLHttpRequest();
        deleteRequest.open("DELETE", "/api/todo/" + id);
        deleteRequest.onload = function() {
            if (this.status !== 200) {
                error.textContent = "Failed to Delete. Server returned " + this.status + " - " + this.responseText;
            }
        };
        deleteRequest.send();
        reloadTodoList();
    }
}

function markDone(event) {
    if (event && event.target) {
        var id = event.target.getAttribute("data-id");
        var updateRequest = new XMLHttpRequest();
        updateRequest.open("PUT", "/api/todo/" + id);
        updateRequest.setRequestHeader("Content-type", "application/json");
        updateRequest.send(JSON.stringify({
            isComplete: true
        }));
        updateRequest.onload = function() {
            if (this.status === 200) {
                reloadTodoList();
            } else {
                error.textContent = "Failed to update item. Server returned " + this.status + " - " + this.responseText;
            }
        };
    }
}

function reloadTodoList() {
    while (todoList.firstChild) {
        todoList.removeChild(todoList.firstChild);
    }
    todoListPlaceholder.style.display = "block";
    getTodoList(function(todos) {
        todoListPlaceholder.style.display = "none";
        var itemsNotDone = 0;
        todos.forEach(function(todo) {
            var listItem = document.createElement("li");
            listItem.textContent = todo.title;
            var deleteButton = document.createElement("button");
            deleteButton.textContent = ("Delete");
            deleteButton.className = "delete";
            deleteButton.setAttribute("data-id", todo.id);
            deleteButton.onclick = deleteTodo;
            if (todo.isComplete) {
                listItem.className = "isDone";
            }
            else {
                itemsNotDone++;
                var doneButton = document.createElement("button");
                doneButton.textContent = ("Mark as Done");
                doneButton.className = "markDone";
                doneButton.setAttribute("data-id", todo.id);
                doneButton.onclick = markDone;
                listItem.appendChild(doneButton);
            }
            if (itemsNotDone === 1) {
                counter.textContent = "There is " + itemsNotDone + "task remaining";
            }else {
                counter.textContent = "There are " + itemsNotDone + " tasks remaining";
            }
            listItem.appendChild(deleteButton);
            todoList.appendChild(listItem);
        });
    });
}
<commit_msg>8 delete all completed items<commit_after>var todoList = document.getElementById("todo-list");
var todoListPlaceholder = document.getElementById("todo-list-placeholder");
var form = document.getElementById("todo-form");
var todoTitle = document.getElementById("new-todo");
var error = document.getElementById("error");
var counter = document.getElementById("count-label");

form.onsubmit = function(event) {
    var title = todoTitle.value;
    createTodo(title, function() {
        reloadTodoList();
    });
    todoTitle.value = "";
    event.preventDefault();
};

function createTodo(title, callback) {
    var createRequest = new XMLHttpRequest();
    createRequest.open("POST", "/api/todo");
    createRequest.setRequestHeader("Content-type", "application/json");
    createRequest.send(JSON.stringify({
        title: title
    }));
    createRequest.onload = function() {
        if (this.status === 201) {
            callback();
        } else {
            error.textContent = "Failed to create item. Server returned " + this.status + " - " + this.responseText;
        }
    };
}
function updateTodo(id, title, callback) {
    var updateRequest = new XMLHttpRequest();
    updateRequest.open("PUT", "/api/todo" + id);
    updateRequest.setRequestHeader("Content-type", "application/json");
    updateRequest.send(JSON.stringify({
        title: title
    }));
    updateRequest.onload = function() {
        if (this.status === 200) {
            callback();
        } else {
            error.textContent = "Failed to update item. Server returned " + this.status + " - " + this.responseText;
        }
    };
}

function getTodoList(callback) {
    var createRequest = new XMLHttpRequest();
    createRequest.open("GET", "/api/todo");
    createRequest.onload = function() {
        if (this.status === 200) {
            callback(JSON.parse(this.responseText));
        } else {
            error.textContent = "Failed to get list. Server returned " + this.status + " - " + this.responseText;
        }
    };
    createRequest.send();
}

function deleteTodoEvent(event) {
    if (event && event.target) {
        var id = event.target.getAttribute("data-id");
        if (id){
            deleteTodo(id), reloadTodoList();
        }
    }
}

function deleteTodo(id, callback) {
    var deleteRequest = new XMLHttpRequest();
    deleteRequest.open("DELETE", "/api/todo/" + id);
    deleteRequest.onload = function() {
        if (this.status !== 200) {
            error.textContent = "Failed to Delete. Server returned " + this.status + " - " + this.responseText;
        }else {
            if(callback){
                callback();
            }
        }
    };
    deleteRequest.send();
}



function markDone(event) {
    if (event && event.target) {
        var id = event.target.getAttribute("data-id");
        var updateRequest = new XMLHttpRequest();
        updateRequest.open("PUT", "/api/todo/" + id);
        updateRequest.setRequestHeader("Content-type", "application/json");
        updateRequest.send(JSON.stringify({
            isComplete: true
        }));
        updateRequest.onload = function() {
            if (this.status === 200) {
                reloadTodoList();
            } else {
                error.textContent = "Failed to update item. Server returned " + this.status + " - " + this.responseText;
            }
        };
    }
}

function clearAll(todos) {
    return function() {
        todos.forEach(function (todo) {
            if (todo.isComplete) {
                deleteTodo(todo.id);
            }
        });
        reloadTodoList();
    }
}

function reloadTodoList() {
    while (todoList.firstChild) {
        todoList.removeChild(todoList.firstChild);
    }
    todoListPlaceholder.style.display = "block";
    getTodoList(function(todos) {
        todoListPlaceholder.style.display = "none";
        var itemsNotDone = 0;
        var completedItems = 0;
        todos.forEach(function(todo) {
            var listItem = document.createElement("li");
            listItem.textContent = todo.title;
            var deleteButton = document.createElement("button");
            deleteButton.textContent = ("Delete");
            deleteButton.className = "delete";
            deleteButton.setAttribute("data-id", todo.id);
            deleteButton.onclick = deleteTodoEvent;
            if (todo.isComplete) {
                listItem.className = "isDone";
                completedItems++;
            }
            else {
                itemsNotDone++;
                var doneButton = document.createElement("button");
                doneButton.textContent = ("Mark as Done");
                doneButton.className = "markDone";
                doneButton.setAttribute("data-id", todo.id);
                doneButton.onclick = markDone;
                listItem.appendChild(doneButton);
            }
            counter.textContent = (itemsNotDone === 1 ? "There is " +
                itemsNotDone + " task remaining" : "There are " +
                itemsNotDone + " tasks remaining");
            if (completedItems > 0) {
                var deleteDone = document.createElement("button");
                deleteDone.textContent = "Delete All Completed";
                deleteDone.onclick = clearAll(todos);
                counter.appendChild(deleteDone);
            }
            listItem.appendChild(deleteButton);
            todoList.appendChild(listItem);
        });

    });
}

{'fraction_non_alphanumeric': 0.13020121117405745, 'fraction_numerical': 0.003613987106856808, 'mean_word_length': 2.187733499377335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5124697', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2744, 'n_words': 535}