
<!--Data table-->
<script src="/public/lib/dataTable/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="/public/lib/dataTable/js/dataTable.bootstrap.min.js" type="text/javascript"></script>
<link href="/public/lib/dataTable/js/dataTables.bootstrap.css" rel="stylesheet" type="text/css"/>

<section class="mainPage">
    <h1 class="textMain">
       <?=$this->Get_Lang->gl('home_slider',$adminLang)?>
    </h1>

    <div class="addingBar addBtn">
        <div class="btn-group" role="group" aria-label="...">
            <a href="/admin/add_edit_home_slider/" class="btn btn-primary right">
                <i class="fa fa-plus" aria-hidden="true"></i>
                <?=$this->Get_Lang->gl('add',$adminLang)?>
            </a>
        </div>
    </div>
    
    <div class="detailsCont">

        <div class="col-md-12 theDataTable">
            <div class="row">
                <div id="no-more-tables">

                    <table id="dataTable" class="col-md-12 table-bordered table-striped table-condensed cf">
                        <thead class="cf">
                            <tr>
                                <th><?=$this->Get_Lang->gl('the_photo',$adminLang)?></th>
                                <?php foreach ($databaseLang as $key => $value) { ?>
                                <th><?=$this->Get_Lang->gl("the_title",$adminLang)?> - <?=$value->theName?></th>
                                <?php } ?>
                                <th style="width:10%;"><?=$this->Get_Lang->gl('action',$adminLang)?></th>
                            </tr>
                        </thead>
                        <tbody>


                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>


<script>

    $(document).ready(function () {
        var theVal = 0;
        
        $(".langId").on("change", function(){
            theVal =  $('.langId').val();
           dtBuilder();
        });
        
       $(".nav>li>a.homeSlider").addClass("active");

       $(".sidebar-dropdown.one").addClass("active");
       $(".sidebar-wrapper .sidebar-menu ul li a.homeSlider").addClass("active");
       $(".sidebar-dropdown.one .sidebar-submenu").fadeIn(); 
        var dTableVar;
        function dtBuilder() {
            var options = {
                ajaxUrl: "/admin/ajax/getHomeSlider",
                innerFunc: function () {
                    $(".deleteButton").click(function () {
                        mText = "<?=$this->Get_Lang->gl('ru_sure_delete',$adminLang)?>";
                        mTitle = "<?=$this->Get_Lang->gl('delete',$adminLang)?>";
                        mCancelLabel = "<?=$this->Get_Lang->gl('cancel',$adminLang)?>";
                        mOkLabel = "<?=$this->Get_Lang->gl('delete',$adminLang)?>";
                        modalConfirm($(this), mText, mTitle, mCancelLabel, mOkLabel, function () {
                            $(".paginate_button.active").trigger("click");
                            dtBuilder();
                        });
                    });
                }
            };
            var dtOpt = {
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": options.ajaxUrl,
                "sPaginationType": "full_numbers",
                //"aaSorting": [],
                "bSort": false,
                //"sDom": '',
                //"lengthMenu": [[100, -1], [100, "All"]],
                "fnDrawCallback": function () {
                    if (options.innerFunc)
                        options.innerFunc.call();
                },
                "fnServerData": function (sSource, aoData, fnCallback, oSettings) {
                     aoData.push( { "name": "langId", "value":theVal } );
                    oSettings.jqXHR = $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                <?php if($adminLang == 1){ ?>
                "language": {
                        "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Arabic.json"
                    }
                <?php }else if($adminLang == 3){ ?>
                    "language": {
                        "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Turkish.json"
                    }
                <?php } ?>
            };
            if (dTableVar)
                dTableVar.fnDestroy();

                dTableVar = $("#dataTable").dataTable(dtOpt);

            $("#searchTable").keyup(function () {
                var val = $(this).val();
                dTableVar.fnFilter(val);
            });
        }

        dtBuilder();
        $(".dtFilters select, .dtFilters input").change(function () {
            dtBuilder();
        });


    });

</script>
