<div class="index_batchjob">
    <ul class="nav justify-content-center">
        <li class="nav-item"><?= $viewDatas['service']->getHelper()->getListButton('create', '', $viewDatas) ?></li>
        <li class="nav-item"><?= form_checkbox(array("id" => "batchjobuids_checkbox")) ?>ALL</li>
        <?php foreach ($viewDatas['control']['batchjob_fields'] as $field): ?>
            <?= $viewDatas['service']->getHelper()->getListFilter($field, null, $viewDatas, ['data-batchjob' => 'true']) ?>&nbsp;
        <?php endforeach ?>
        <?php foreach ($viewDatas['control']['batchjob_buttions'] as $action => $label): ?>
            <li class="nav-item"><?= $viewDatas['service']->getHelper()->getListButton($action, $label, $viewDatas) ?></li>
        <?php endforeach ?>
    </ul>
    <div class=" index_pagination"><?= $viewDatas['pagination'] ?></div>
</div>
<script>
    //이 스크립트를 사용하려면 Form 안에 아래 Tag필요
    // <input type = "hidden"name = "batchjob_uids"id = "batchjob_uids"value = "" >
    function submitBatchJob() {
        var validate = false;
        //batchjob용 선택사항 검증
        <?php foreach ($viewDatas['control']['batchjob_fields'] as $field): ?>
            var element = document.querySelector('[name="<?= $field ?>"][data-batchjob="true"]');
            if (element && element.value !== "") {
                validate = true;
            }
        <?php endforeach ?>
        if (!validate) {
            alert('변경할 항목을 선택하셔야합니다.');
            return false;
        }
        //적용받는 uids가 한개라도 선택되었다면 true
        var batchjobUids = [];
        var checkboxes = document.querySelectorAll('input[name="batchjob_uids[]"]:checked');
        checkboxes.forEach(function(checkbox) {
            batchjobUids.push(checkbox.value);
        });
        if (batchjobUids.length === 0) {
            alert('적용할 리스트를 선택하셔야합니다.');
            return false;
        }
        document.getElementById('batchjob_uids').value = batchjobUids.join(',');
        return true;
    }

    function submitBatchJobDelete() {
        var batchjobUids = [];
        var checkboxes = document.querySelectorAll('input[name="batchjob_uids[]"]:checked');
        checkboxes.forEach(function(checkbox) {
            batchjobUids.push(checkbox.value);
        });
        if (batchjobUids.length === 0) {
            alert('적용할 리스트를 선택하셔야합니다.');
            return false;
        }
        document.getElementById('batchjob_uids').value = batchjobUids.join(',');
        return true;
    }
</script>