<?php $__env->startSection('title'); ?> Danh sách bài viết <?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<div class="x_content">

  <h2>Tìm kiếm</h2>

  <div class="form-group">

    <form action="<?php echo e(url('admin/search-news')); ?>" method="POST">

      <div class="item form-group col-md-3 col-sm-12 col-xs-12">

        <div class="col-md-12 col-sm-12 col-xs-12">

          <select name="category_id" id="search_cate" class="form-control">

            <option value="0">Chọn danh mục</option>

            <?php foreach ($cate_news as $key => $value): ?>

              <?php if ($value->parent_id == 0 && $value->id>1): ?>

                <option value="<?php echo e($value->id); ?>" class="form-control"> <?php echo e($value->title); ?> </option>

                <?php echo e(Helper::sub_menu($cate_news,$value->id)); ?>



              <?php endif ?>

            <?php endforeach ?>

          </select>

        </div>

      </div>

      <div class="item form-group col-md-3 col-sm-12 col-xs-12">

        <div class="col-md-12 col-sm-12 col-xs-12">

          <select name="user_id" id="search_user" class="form-control">

            <option value="">Chọn thành viên</option> 

            <?php foreach($list_user as $items): ?>      

            <option value="<?php echo e($items->id); ?>"><?php echo e($items->name); ?></option>

            <?php endforeach; ?>   

          </select>

        </div>

      </div>

      <div class="item form-group col-md-3 col-sm-12 col-xs-12">

        <div class="col-md-9 col-xs-12 col-sm-12">

          <input type="text" name="search_name" placeholder="Tên bài viết" class="form-control">

        </div>

        <div class="col-md-3 col-xs-12 col-sm-12">

          <button type="submit" name="submit_search" class="btn btn-primary"><i class="fa fa-search"></i></button>

        </div>

      </div>

      <?php echo e(csrf_field()); ?>



    </form>

  </div>

</div>

<form name="formbk" method="post" action="">

  <div class="">

    <div class="form-group"> <?php if(Session::get('user')->add_news == 1): ?> <a class="btn btn-success" href="<?php echo e(url('admin/add-news')); ?>">Thêm bài viết</a> <?php endif; ?>

      <?php if(Session::get('user')->edit_news == 1): ?>

      <input class="btn btn-danger" type="submit" name="delall" value="Xóa" onclick="return confirm('Bạn chắc chắn muốn xóa!')">

    <?php endif; ?> </div>

    <div class="clearfix"></div>

    <?php echo $__env->make('errors.note', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

    <div class="row">

      <div class="col-md-12 col-sm-12 col-xs-12">

        <div class="x_panel">

          <div class="x_title">

            <h2>Danh sách bài viết</small></h2>

            <ul class="nav navbar-right panel_toolbox">

              <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a> </li>

              <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>

                <ul class="dropdown-menu" role="menu">

                  <li><a href="#">Settings 1</a> </li>

                  <li><a href="#">Settings 2</a> </li>

                </ul>

              </li>

              <li><a class="close-link"><i class="fa fa-close"></i></a> </li>

            </ul>

            <div class="clearfix"></div>

          </div>

          <div class="x_content table-responsive">

            <table id="datatable" class="table table-striped table-bordered dt-responsive nowrap">

              <thead>

                <tr>

                  <th> 

                    <th><input type="checkbox" name="checkAll" id="check-all" class="flat"></th>

                  </th>

                  <th style="width:3%">ID</th>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <th>Sắp xếp</th>

                  <?php endif; ?>

                  <th>Tiêu đề</th>

                  <th>Ảnh bài viết</th>

                  <th>Danh mục</th>

                  <th>Xuất bản</th>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <th>Nổi bật</th>

                  <?php endif; ?>

                  <th>Ngày đăng</th>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <th>Action</th>

                <?php endif; ?> </tr>

              </thead>

              <tbody id="list_news">



                <?php foreach($list_news as $items): ?>

                <tr class="list_news">

                  <td>

                    <th><input type="checkbox" class="check_del flat" name="check_del[]" value="<?php echo e($items->id); ?>"></th>

                  </td>

                  <td><?php echo e($items->id); ?></td>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <td><input style="width:50px;" type="text" id_news="<?php echo e($items->id); ?>" name="sort" value="<?php echo e($items->sort); ?>"></td>

                  <?php endif; ?>

                  <td><?php echo e($items->title); ?></td>

                  <td><img style="width:100px" class="img-thumbnail" src="<?php if($items->thumb ==""): ?> <?php echo e(url('public/images/noimg.jpg')); ?> <?php else: ?> <?php echo e(url($items->thumb)); ?> <?php endif; ?>"></td>

                  <td><?php if($items->category_id > 0): ?> <?php echo e($items->cate_title); ?> <?php else: ?> Chưa có danh mục <?php endif; ?></td>

                  <td>



                   <label><input type="checkbox" name="publish" class="js-switch" id_news="<?php echo e($items->id); ?>" <?php if($items->

                    publish == 1): ?> checked <?php endif; ?> title="Xuất bản"></label>

                  </td>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <td><div class="form-group">

                   <label> <input type="checkbox" name="home" class="js-switch" id_news="<?php echo e($items->id); ?>" <?php if($items->

                    home == 1): ?> checked <?php endif; ?> title="Nổi bật"></label>

                    <div class="clearfix"></div>

                  </div></td>

                  <?php endif; ?>

                  <div class="clearfix"></div>

                  <td><?php echo e(date('d-m-Y',$items->time+7*3600)); ?></td>

                  <?php if(Session::get('user')->edit_news == 1): ?>

                  <td><a href="<?php echo e(url('admin/edit-news/'.$items->id)); ?>" class="btn btn-warning btn-xs" title="Sửa"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> <a href="<?php echo e(url('admin/del-news/'.$items->id)); ?>" title="Xóa" onclick="return confirm('Bạn chắc chắn muốn xóa!')" class="btn btn-danger btn-xs"><i class="fa fa-times" aria-hidden="true"></i></a> </td>

                <?php endif; ?> </tr>

                <?php endforeach; ?>

              </tbody>



            </table>

            <div class="paging"> <?php echo str_replace('/?','?',$list_news->appends(['gid' => @$_GET['gid']])->render()); ?> </div>

            <div class="text-center loading" style="display: none;"> <img src="<?php echo e(url('public/images/spinner.gif')); ?>" style="max-height: 80px;"> </div>

            <script type="text/javascript">

              function DoCheck(status,FormName,from_)

              {

                var alen=eval('document.'+FormName+'.elements.length');

                alen=(alen>1)?eval('document.'+FormName+'.checkone.length'):0;

                if (alen>0)

                {

                  for(var i=0;i<alen;i++)

                    eval('document.'+FormName+'.checkone[i].checked=status');

                }

                else

                {

                  eval('document.'+FormName+'.checkone.checked=status');

                }

                if(from_>0)

                  eval('document.'+FormName+'.checkall.checked=status');

              }

            </script> 

          </div>

        </div>

      </div>

    </div>

  </div>

  <?php echo e(csrf_field()); ?>



</form>

<script type="text/javascript">

  $(document).ready(function(){

    $('input[name=publish]').click(function(){

      url = "<?php echo e(url('admin/ajax/news_publish')); ?>/";

      id = $(this).attr('id_news');

      _token = $('input[name=_token]').val();

      $.ajax({

        url:url+id,

        type:'GET',

        cache:false,

        data:{'_token':_token,'id':id},

        success:function(data){

          console.log('ok');

        }

      });

    });

    $('input[name=home]').click(function(){

      url = "<?php echo e(url('admin/ajax/news_home')); ?>/";

      id = $(this).attr('id_news');

      _token = $('input[name=_token]').val();

      $.ajax({

        url:url+id,

        type:'GET',

        cache:false,

        data:{'_token':_token,'id':id},

        success:function(data){

        }

      });

    });

    $('input[name=hot]').click(function(){

      url = "<?php echo e(url('admin/ajax/news_hot')); ?>/";

      id = $(this).attr('id_news');

      _token = $('input[name=_token]').val();

      $.ajax({

        url:url+id,

        type:'GET',

        cache:false,

        data:{'_token':_token,'id':id},

        success:function(data){

        }

      });

    });

    $('input[name=focus]').click(function(){

      url = "<?php echo e(url('admin/ajax/news_focus')); ?>/";

      id = $(this).attr('id_news');

      _token = $('input[name=_token]').val();

      $.ajax({

        url:url+id,

        type:'GET',

        cache:false,

        data:{'_token':_token,'id':id},

        success:function(data){

        }

      });

    });

    $('input[name=sort]').keyup(function(){

      url = "<?php echo e(url('admin/ajax/news_sort')); ?>/";

      id = $(this).attr('id_news');

      num = $(this).val();

      _token = $('input[name=_token]').val();

      $.ajax({

        url:url+id+'/'+num,

        type:'GET',

        cache:false,

        data:{'_token':_token,'id':id,'num':num},

        success:function(data){

        }

      });

    });

  })

  // $(window).scroll(function() {

  //  a = $(window).scrollTop() + $(window).height();

  //  b = $(document).height() - $('footer').height();

  //  if(a > b) {

  //    $('.loading').show();

  //    setTimeout(function(){

  //      count = $(".list_news").length;

  //      url = '<?php echo e(url("admin/ajax/list-news/")); ?>/'+count;

  //      // console.log(count);

  //      $.ajax({

  //        url:url,

  //        type:'get',

  //        cache:false,

  //        data:{'count':count},

  //        success:function(result){

  //          $("#list_news").html(result);

  //          $('.loading').hide();

  //        }

  //      });

  //    },750)

  //  }

  // });

  $("#search_cate").change(function(){

    cate = $(this).val();

    url = "<?php echo e(url()); ?>/admin/search-news-cate/"+cate+"?gid="+cate;

    window.location.href = url;

  })

  $("#search_user").change(function(){

    id = $(this).val();

    url = "<?php echo e(url()); ?>/admin/search-news-user/"+id+"?userid="+id;

    window.location.href = url;

  })

</script> 

<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout.layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>