function clickElementDelete(self) {
    handleSelectDelete();
}

function handleSelectDelete() {
    var listCheckBox = document.querySelectorAll(".cb-delete");
    var htmlData = "";
    var countChecked = 0;
    listCheckBox.forEach(function (checkbox) {
        if (checkbox.checked) {
            htmlData += '<input type="hidden" name="article_id[]" value="' + checkbox.value + '">';
            countChecked++;
        }
    })
    var formDeleteMulti = document.querySelector(".data-delete");
    formDeleteMulti.innerHTML = htmlData;

    document.querySelector("#cb-select-all").checked = (countChecked === listCheckBox.length);
}

function handleSelectAll(checked) {
    var listCheckBox= document.querySelectorAll(".cb-delete");
    listCheckBox.forEach(function (checkbox) {
        checkbox.checked = checked;
    })
}

function selectAll(self) {
    handleSelectAll(self.checked);
    handleSelectDelete();
}

function submitDelete(self) {
    if (! confirm("削除してよろしいですか？")) {
        return false;
    }
    var $elmForm = $(self);
    var url = $elmForm.attr("action");
    var method = $elmForm.attr("method");
    var formData = new FormData($elmForm[0]);

    $.ajax({
        url: url,
        method: method,
        data: formData,
        processData: false,
        contentType: false,
        success: function (resp) {
            window.location.reload(true);
        },
        error: function (err) {
            console.log(err);
        }
    })
    return false;
}

