@extends('template.layout')
@section('styles')
    <link href="{{ asset('plugins/datatables/datatables.min.css') }}" rel="stylesheet" type="text/css" />
    <link href="{{ asset('plugins/datatables/plugins/bootstrap/datatables.bootstrap.css') }}" rel="stylesheet" type="text/css" />
@endsection
@section('content')
    <h1 class="page-title">
        Campos de Investigaci&oacute;n
    </h1>

    <div class="portlet light bordered">
        <div class="portlet-title">
            <div class="caption">
                <h1 class="caption-subject font-green sbold uppercase"> Listado de Campos de Investigaci&oacute;n</h1>
            </div>
            <div class="actions">
                <div class="btn-group">
                    <button class="btn btn-primary" onclick="myModalShow()">  <i class="fa fa-plus"></i>  Registrar Campo Investigaci&oacute;n</button>
                </div>
            </div>
        </div>
        <div class="portlet-body">
            <div class="Forum-ForumTopicList row" style="margin:20px">
                <table class="table table-hover nowrap dataTable dtr-inline collapsed tbPerdidos"
                       id="tbCampoInvestigacion"
                       width="100%" role="grid" aria-describedby="tbCampoInvestigacion_info">
                    <thead class="thead-default">
                    <tr>
                        <th>N°</th>
                        <th>Titulo</th>
                        <th>Descripci&oacute;n</th>
                        <th>Opciones</th>
                    </tr>
                    </thead>
                    <tbody>
                    @php ($count = 1)
                    @foreach($query as $item)
                        <tr>
                            <td> {{ $count }} </td>
                            <td> {{ $item->descripcion }} </td>
                            <td style="word-break: break-word; white-space: pre-line; text-align: justify;"> {{ $item->detalle }} </td>
                            <td>
                                <button onclick="Editar({{$item->id}})"  class="btn btn-outline btn-circle btn-sm blue">
                                    <i class="fa fa-edit"></i> Editar
                                </button>
                                <button onclick="Eliminar({{$item->id}})" class="btn btn-outline btn-circle dark btn-sm red">
                                    <i class="fa fa-trash-o"></i> Eliminar
                                </button>
                            </td>

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

    <div id="RegistrarCampolModal" class="modal fade" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Registrar Campo de Investigación</h4>
                </div>

                {!! Form::open(array('id' => 'form-validation','route' => array('campoinvestigacion.crear'))) !!}
                <div class="modal-body" id="ModalBody">

                    <div class="form-group">
                        {!! Form::label('titulo', 'Título:', ['class' => 'control-label']) !!}
                        {!! Form::text('titulo', null, ['class' => 'form-control','required'=>'required']) !!}
                    </div>
                    <div class="form-group">
                        {!! Form::label('', 'Descripción:', ['class' => 'control-label']) !!}
                        {!! Form::text('detalle', null, ['class' => 'form-control','required'=>'required']) !!}
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" data-dismiss="modal" class="btn dark btn-outline">Cancelar</button>
                    {!! Form::submit('Guardar', ['class' => 'btn green']) !!}
                </div>
                {!! Form::close() !!}
                @include('alerts.index')

            </div>
        </div>
    </div>

    <div id="EditarCampoModal" class="modal fade" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Editar Campo de Investigación</h4>
                </div>

                <div id="modalContent"></div>

                @include('alerts.index')

            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script src="{{ asset('plugins/datatables/datatables.min.js') }}" type="text/javascript"></script>
    <script src="{{ asset('plugins/datatables/plugins/bootstrap/datatables.bootstrap.js') }}" type="text/javascript"></script>
    <script>
        $('#tbCampoInvestigacion').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": false,
            bInfo: true,
            responsive: true,
            "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},
            ],
            "columns": [
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
            ]
        });

        $("#form-validation").validate({});

        function myModalShow() {
            $('#RegistrarCampolModal').modal('show');
        }

        function Editar($id) {

            $( "#modalContent" ).empty();

            $.ajax({
                url: "{{ url('campoinvestigacion/detalle') }}"+"/"+$id,
                type: 'GET',
                success: function(result) {
                    $('#modalContent').append(result);
                }
            });

            $('#EditarCampoModal').modal('show');

        }

        function Eliminar($id) {

            swal({
                    title: "Esta seguro de eliminarlo?",
                    text: "Una vez eliminado no podrá recuperar el archivo!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Si, eliminar!",
                    cancelButtonText: "No, cancelar",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        window.location.href = "{{ url('campoinvestigacion/eliminar') }}"+"/"+$id;
                    } else {
                        swal("Cancelado", "La información sigue segura.", "error");
                    }
                });


        }

    </script>
@endsection