@extends('webprofile.backend.layouts.master')

@section('title')
  {{ $title }}
@stop

@section('breadcrumbs')
<li><a href="{{ url('home') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.user')</li>
@stop

@section('content')
<!-- page start-->
<div class="row">
    <div class="col-lg-12">
        <!-- START DEFAULT DATATABLE -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{!! $title !!}</h3>
                <a class="btn btn-info" href="{{URL::to('webprofile/user/create')}}" style="margin: 0cm 0px 0cm 10px;">@lang('label.create')</a>
                <ul class="panel-controls">
                    <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
                </ul>
            </div>
            <div class="panel-body">
                <table class="table datatable table-hover" id="berita">
                    <thead>
                        <tr>
                            <th width="7%">@lang('label.number')</th>
                            <th width="20%">@lang('label.name')</th>
                            <th width="30%">Email</th>
                            <th width="18%">Role</th>
                            <th width="10%">Status</th>
                            <th align="center" width="15%">@lang('label.action')</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php $no = 1;?>
                    @foreach($users as $value)
                      @if ($value->name != 'Aan Choesni Herlingga')
                        <tr style="cursor:pointer">
                            <td align="center"><?php echo $no; ?></td>
                            <td>{!! $value->name !!}</td>
                            <td>{!! $value->email !!}</td>
                            <td>
                              @if($value->role == 'admin')
                                Administrator
                              @endif
                              @if($value->role == 'laman')
                                Pengelola Laman
                              @endif
                            </td>
                            <td style="text-align: center;">
                                @if($value->is_active == 1)
                                  <i class="fa fa-check" style="color: green"></i>
                                @endif
                                @if($value->is_active == 0)
                                  <i class="fa fa-times" style="color: red"></i>
                                @endif
                              </td>
                              <td style="text-align:center;">
                                  @if($value->is_active == 0)
                                    <button class="btn btn-success btn-xs" id="btn_status" data-file="{{$value->id}}"><i class="fa fa-check"></i></button>
                                    {!! Form::model($value, ['route' => ['user.status', $value->id], 'method'=>'patch', 'id' => 'status_'.$value->id, 'style' => 'display: none;']) !!}
                                    {!! Form::hidden('is_active', 1) !!}
                                    {{ csrf_field() }}
                                    {{ Form::close() }}
                                  @endif
                                  @if($value->is_active == 1)
                                    <button class="btn btn-danger btn-xs" id="btn_status" data-file="{{$value->id}}"><i class="fa fa-times"></i></button>
                                    {!! Form::model($value, ['route' => ['user.status', $value->id], 'method'=>'patch', 'id' => 'status_'.$value->id, 'style' => 'display: none;']) !!}
                                    {!! Form::hidden('is_active', 0) !!}
                                    {{ csrf_field() }}
                                    {{ Form::close() }}
                                  @endif

                                  <a href="{{ route('user.edit', ['data'=>Crypt::encrypt($value->id)]) }}" class="btn btn-warning btn-xs"><i class="fa fa-pencil"></i></a>

                                  <button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$value->id}}"><i class="fa fa-trash-o"></i></button>
                                  {{ Form::open(['url'=>route('user.destroy', ['data'=>Crypt::encrypt($value->id)]), 'method'=>'delete', 'id' => $value->id, 'style' => 'display: none;']) }}
                                  {{ csrf_field() }}
                                  {{ Form::close() }}
                                </td>
                           <?php $no++;?>
                        </tr>
                      @endif
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        <!-- END DEFAULT DATATABLE -->
    </div>
</div>
<!-- page end-->
@stop

@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/datatables/jquery.dataTables.min.js') !!}
<script>
  $('button#btn_delete').on('click', function(e){
    e.preventDefault();
    var data = $(this).attr('data-file');

    swal({
      title             : "Apakah Anda Yakin?",
      text              : "Anda akan menghapus data ini!",
      type              : "warning",
      showCancelButton  : true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText : "Yes",
      cancelButtonText  : "No",
      closeOnConfirm    : false,
      closeOnCancel     : false
    },
    function(isConfirm){
      if(isConfirm){
        swal("Terhapus","Data berhasil dihapus", "success");
        setTimeout(function() {
          $("#"+data).submit();
        }, 1000); // 1 second delay
      }
      else{
        swal("Dibatalkan","Data batal dihapus", "error");
      }
    }
  );});

  $('button#btn_status').on('click', function(e){
      e.preventDefault();
      var data = $(this).attr('data-file');

      swal({
        title             : "Apakah Anda yakin?",
        text              : "Data ini dipakai!",
        type              : "warning",
        showCancelButton  : true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText : "Yes",
        cancelButtonText  : "No",
        closeOnConfirm    : false,
        closeOnCancel     : false
      },
      function(isConfirm){
        if(isConfirm){
          swal("Dipakai","Data dipakai", "success");
          setTimeout(function() {
            $("#status_"+data).submit();
          }, 1000); // 1 second delay
        }
        else{
          swal("cancelled","Dibatalkan", "error");
        }
      }
  );});
</script>
@stop
