<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
    <div class="admin-title">
        <h1><?= $this->config->item('icons')['hr']; ?>
            <?php echo html_entity_decode($title); ?></h1>
    </div>
    <div class="content">
        <div class="row">
            <div class="panel_s">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-12">
                            <?php $this->load->view('hr/documents/header', ['active' => 'categories']); ?>

                            <?php if (has_permission('hr', '', 'create')) { ?>
                                <div class="form-group">
                                    <button href="<?php echo admin_url('hr/documents/createCategory'); ?>"
                                            class="btn btn-info mg-r-5" data-toggle="modal"
                                            data-target="#modal-category">
                                        <i class="plus-icon-new fa-sharp fa-solid fa-plus"></i> <?php //INACTIVE:echo _l('hr_new_category'); ?>
                                    </button>
                                </div>
                            <?php } ?>
                            <?php
                            $table_data = [
                                _l('name'),
                                _l('action'),
                            ];

                            render_datatable($table_data, 'categories');
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('hr/modals/documentCategory'); ?>
<?php show_footer(); ?><?php init_tail(); ?>
<script>
    notsearchable = [1];
    notsortable = [1];
    initDataTable('.table-categories', admin_url + 'hr/tables_hr/table_document_categories', notsearchable, notsortable, 'undefined', [0, 'desc']);
    $(document).ready(function () {
        $(document).on('click', '.btn_edit_category', function (event) {
            event.preventDefault();
            var $btn = $(this),
                id = parseInt($btn.data('id'));

            $.ajax({
                url: '<?php echo admin_url('hr/documents/getCategory/')?>',
                type: "POST",
                data: {id: id}
            }).done(function (response) {
                if (response.status) {
                    $('#category_id').val(response.category.id);
                    $('#name').val(response.category.name);
                    $('#modal-category').modal('show');
                }
            }).fail(function (response) {
                alert(data.responseText);
            }).always(function () {

            });
        });
    });
</script>
</body>
</html>
