<!-- Thông báo lỗi -->
<?php MyHelper::loadView('backend/cms_partials/error_message_view') ?>
<div class="row">
    <?php echo form_open(base_url().'backend/cmsSetting/listAccessController'); ?>
    <div class="col-lg-2">
        <input
            class="form-control" type="text"
            name="input-account"
            id="input-name"
            placeholder="Tên chức năng..."/>
    </div>
    <div class="col-lg-1">
        <button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
    </div>
    <?php echo form_close(); ?>
</div>
<!-- /.row -->
<div class="space-6"></div>
<div class="row" >
    <div style="text-align: center" id="data-loading">
        <i class="fa fa-refresh fa-spin bigger-200"></i> Đang tải dữ liệu...
    </div>
    <div id="div-mo-list">
        <table class="table table-striped table-bordered table-hover">
            <thead></thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<div class="row">
    <a href="<?php echo base_url().'backend/cmsSetting/addAccessController'?>">
        <button class="btn btn-sm btn-primary">+ Thêm mới</button>
    </a>
</div>

<script type="text/javascript">
    //Thuc hien viec ve bieu do
    $(document).ready(function() {
        var url = '<?php echo base_url()."backend/cmsSetting/listAccessControllerAjax"; ?>';

        // Tìm kiếm theo cú pháp
        var oldTimeout2 = '';
        $('#input-name').keyup(function(){
            clearTimeout(oldTimeout2);
            oldTimeout2 = setTimeout(function(){
                loadDataByAjaxFromInput(url);
            }, 1000);
        });
        // Xóa bộ lọc
        $('#delete-filter').click(function(){
            $("#input-name").val('');
            changePagination('0');
            return false;

        });
        changePagination('0');

    });
    //Ham chung cho cac input
    function loadDataByAjaxFromInput(url){
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var filterByName = $("#input-name").val();
        //Ajax ve bieu do
        $.ajax({
            type: "POST",
            url: url,
            data: {
                csrf_name: csrf_value,
                filterByName: filterByName,
            },
            dataType: "text",
            cache: false,
            success: function(data){
                $('#div-mo-list').html(data);
                $('#data-loading').hide();
            }
        });
    }
    //Ham chung cho cac SelectBox
    function loadDataByAjaxFromSelectBox(id, url){
        $('#'+id).change(function(){
            var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
            var filterByName = $("#input-name").val();
            //Ajax ve bieu do
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    csrf_name: csrf_value,
                    filterByName: filterByName,
                },
                dataType: "text",
                cache: false,
                success: function(data){
                    $('#div-mo-list').html(data);
                    $('#data-loading').hide();
                }
            });
        });
    }

    function changePagination(pageId) {
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var url = '<?php echo base_url()."backend/cmsSetting/listAccessControllerAjax"; ?>';
        var filterByName = $("#input-name").val();
        //Ajax ve bieu do
        $.ajax({
            type: "POST",
            url: url,
            data: {
                csrf_name: csrf_value,
                filterByName: filterByName,
                pageId: pageId
            },
            dataType: "text",
            cache: false,
            success: function(data){
                $('#div-mo-list').html(data);
                $('#data-loading').hide();
            }
        });
    }

</script>