<!-- Thông báo lỗi -->
<?php MyHelper::loadView('backend/cms_partials/error_message_view') ?>
<div class="row">
    <div class="col-lg-4">
        <select class="form-control" name="input-date-picker" id="input-date-picker">
        <?php foreach ($week_list as $key => $week): ?>
            <option value = "<?php echo $key; ?>"><?php echo $week; ?></option>
        <?php endforeach; ?>
        </select>
    </div>
    <div class="col-lg-1">
        <a href="" id="btn-export">
            <button class="btn btn-sm btn-warning"><i class="fa fa-download"></i> Export ra Excel</button>
        </a>
    </div>
</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>
    <?php MyHelper::loadView(
        'backend/cms_ranking/partials/title_report_violation',
        'Lưu ý: BXH từ tuần 14/2020 sử dụng dữ liệu mới'
    )?>
    <div class="col-lg-12">
        <div id="div-response"></div>
    </div>
</div>
<!-- modal báo cáo trùng bài hát -->
<?php MyHelper::loadView('backend/cms_ranking/partials/report_violation_modal')?>
<script type="text/javascript">
    //Thuc hien viec ve bieu do$data
    $(document).ready(function() {
        var url = '<?php echo base_url("backend/cmsRanking/listByWeeklyAjax"); ?>';
        // Tìm kiếm theo cú pháp
        var oldTimeout2 = '';
        $('#input-date-picker').change(function(){
            updateExportLink();
            clearTimeout(oldTimeout2);
            oldTimeout2 = setTimeout(function(){
                loadDataByAjaxFromInput(url);
            }, 250);
        });

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

    function loadDataByAjaxDateRange(dtFrom, dtTo, url){
        $('#data-loading').show();
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var fByName = $("#input-date-picker").val();
        // ajax
        $.ajax({
            type: "POST",
            url: url,
            data: {
                csrf_name: csrf_value,
                fByName: fByName
            },
            dataType: "text",
            cache: false,
            success: function(data){
                $('#div-response').html(data);
                $('#data-loading').hide();
            }
        });
    }

    function changePagination(pageId) {
        $('#data-loading').show();
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var url = '<?php echo base_url("backend/cmsRanking/listByWeeklyAjax"); ?>';
        var fByName = $("#input-date-picker").val();
        //Ajax ve bieu do\
        $.ajax({
            type: "POST",
            url: url,
            data: {
                csrf_name: csrf_value,
                fByName: fByName,
                pageId: pageId
            },
            dataType: "text",
            cache: false,
            success: function(data){
                $('#div-response').html(data);
                $('#data-loading').hide();
            }
        });
    }
    
    function updateExportLink() {
        var href = '<?php echo base_url("backend/cmsRanking/exportReport/weekly"); ?>/' + $("#input-date-picker").val();
        $('#btn-export').attr('href', href);
    }

</script>
<!-- tải js xử lý cáo báo sai sót -->
<?php MyHelper::loadView('backend/cms_ranking/partials/js_process_report', 'WEEKLY')?>