<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
?>
<?php echo $this->form ?>
<script type="text/javascript">
    //<![CDATA[
    Jsw.onReady(function () {
        document.querySelectorAll('.checkbox').forEach(function (checkboxElement) {
            checkboxElement.checked = true;
            checkboxElement.addEventListener('change', function () {
                var list = Jsw.getComponent('database-issue-list');
                var selected = list.getSelectedItemsIds();
                var button = document.getElementById('btn-send');
                if (selected.length) {
                    button.disabled = false;
                    button.classList.remove('disabled');
                } else {
                    button.disabled = true;
                    button.classList.add('disabled');
                }
            });
        });

        document.getElementById('btn-send').addEventListener('click', function (event) {
            event.preventDefault();

            var list = Jsw.getComponent('database-issue-list');
            var beginOffset = Element.cumulativeOffset(event.target);
            var progressBar = Jsw.getComponent('asyncProgressBarWrapper');
            progressBar.fly(beginOffset,
                <?php echo $this->jsLmsg('smb.components.lists.databases.taskRepairDatabase'); ?>,
                function () {
                    Jsw.redirectPost('/database/repair-tables/id/' + document.getElementById('databaseId').value, {
                        tables: list.getSelectedItemsIds(),
                        taskId: document.getElementById('taskId').value
                    });
                }
            );
        });
    });
    //]]>
</script>
