@extends('template.layout')

@section('content')

    <h1 class="page-title">
        Listado de Personal
    </h1>

    <div class="portlet light bordered">

        <div class="portlet-title">

            <div class="actions">
                <div class="btn-group">
                    <a class="btn blue btn-outline sbold " href="{{url('personal/crear')}}"> Registrar
                        nuevo miembro
                    </a>
                </div>
            </div>
        </div>

        <div class="portlet-body">
            <div class="Forum-ForumTopicList row" style="margin:30px; padding: 10px 30px 10px 10px;">
                <table class="table table-hover nowrap dataTable dtr-inline collapsed tbPersonal"
                       id="tbPersonal"
                       width="100%" role="grid" aria-describedby="tbPersonal_info">
                    <thead class="thead-default">
                    <tr>
                        <th>N°</th>
                        <th>Nombre</th>
                        <th>DNI</th>
                        <th>Roles</th>
                        <th>Estado</th>
                        <th>Opciones</th>
                    </tr>
                    </thead>
                    <tbody>
                    @php ($count = 1)
                    @foreach($users as $item)
                        <tr>
                            <td> {{ $count }} </td>
                            <td style=" word-break: break-word; white-space: pre-line; text-align: justify;"> {{ $item->apellido_paterno }} {{ $item->apellido_materno }}, {{ $item->nombres }} </td>
                            <td> {{ $item->dni }} </td>
                            <td style="word-break: break-word; white-space: pre-line; text-align: justify;"> {{ $item->Roles }} </td>
                            <td>
                                <div class="onoffswitch">
                                    @if($item->estado == 1)
                                        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox chk"
                                               id="switch_{{ $item->id }}" checked="checked">
                                    @else
                                        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox chk"
                                               id="switch_{{ $item->id }}">
                                    @endif
                                    <label class="onoffswitch-label" for="switch_{{ $item->id }}"
                                           style="margin-bottom:0">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </td>
                            <td>

                                <button onclick="Editar({{$item->id}})"
                                        class="btn btn-outline btn-circle btn-sm purple">
                                    <i class="fa fa-edit"></i> Editar
                                </button>

                                <button onclick="Eliminar({{$item->id}})"
                                        class="btn btn-outline btn-circle dark btn-sm black">
                                    <i class="fa fa-trash-o"></i> Eliminar
                                </button>

                            </td>

                        </tr>
                        @php ($count++)
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>

    </div>


@endsection

@section('scripts')
    <script>

        $('#tbPersonal').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": true,
            bInfo: true,
            responsive: false,
            "autoWidth": true,
            "language": {
                "lengthMenu": "Mostrar _MENU_ Entradas",
                "zeroRecords": "No se encontraron registros",
                "info": "Mostrando la página _PAGE_ de _PAGES_",
                "infoEmpty": "No hay registros disponibles",
                "infoFiltered": "(filtrado de _MAX_ registros totales)",
                "search": "Buscar: ",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                },
            },
            "order": [],
            "aoColumns": [
                {"bSearchable": false},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},
                {"bSearchable": false},
                {"bSearchable": false},
            ],
            "columns": [
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
                {"orderable": false},
                {"orderable": false},
            ],
//            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [0, 1, 2,3,4]
                    },
                    title: 'Personal Administrativo'
                }, {
                    extend: 'pdf',
                    exportOptions: {
                        columns: [0, 1, 2,3,4]
                    },
                    pageSize: 'LEGAL',
                    customize: function (doc) {
                        //pageMargins [left, top, right, bottom]
                        doc.pageMargins = [120, 20, 20, 20];
                    },
                    title: 'Personal Administrativo'
                }


            ]
        });

        $('.chk').click(function () {
           var aux = this.id;
           var aux1 = aux.split("_");
           var id = aux1[1];

            $.ajax({
                url: "{{url('personal/cambiarestado')}}" + "/" + id,
                context: document.body
            }).always(function() {
                swal("Se cambio el estado del usuario!");
                });
        });

        function Editar($id) {
            window.location.href = "{{url('personal/edit')}}" + "/" + $id;
        }

        function Eliminar($id) {

            swal({
                    title: "Esta seguro de eliminar el usuario?",
                    text: "Una vez eliminado no se recuperará el usuario!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Si",
                    cancelButtonText: "No",
                    closeOnConfirm: false
                },
                function(){
                    window.location.href =  "{{url('personal/eliminar')}}" + "/" + $id;
                });

        }

    </script>
@endsection