<?php $__env->startSection('content'); ?>
    <h1 class="page-title">
        Autores
    </h1>
    <div class="portlet light portlet-fit portlet-datatable bordered">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject sbold uppercase"> Gestión de Autores </span>
            </div>
            <div class="actions">
                <a class="btn btn-primary Nuevo" data-toggle="modal" href="">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-xs"> Agregar Autor </span>
                </a>
            </div>
        </div>
        <div class="portlet-body">
            <div class="Forum-ForumTopicList row" style="margin:20px">
                <table class="table table-hover nowrap dataTable dtr-inline collapsed tbEncuestas" id="tbEncuestas"
                       width="100%" role="grid" aria-describedby="tbEncuestas_info">
                    <thead class="thead-default">
                    <tr>
                        <th>Nombres</th>
                        <th>Opciones</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $autores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $autor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td style="white-space:pre-line"><?php echo e($autor->nombres); ?></td>
                            <td>
                                <button id="Autor_<?php echo e($autor->id); ?>" class="Editar btn btn-outline btn-circle btn-sm blue">
                                    <i class="fa fa-pencil-square-o"></i> Editar
                                </button>
                                <button id="Autor_<?php echo e($autor->id); ?>" class="Eliminar btn btn-outline btn-circle btn-sm red">
                                    <i class="fa fa-trash-o"></i> Eliminar
                                </button>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div id="CrearModal"></div>
    <div id="EditarModal"></div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script>
        $('a.Nuevo').on('click', function () {
            this.blur();
            $.ajax({
                url: "<?php echo e(url('autor/crear')); ?>",
                type: "GET",
                success: function (result) {
                    $('#CrearModal').html(result).find('.modal').modal({
                        show: true
                    });
                }
            });

            return false;
        });

        $('button.Editar').on('click', function () {
            this.blur();
            var id = $(this).attr('id').replace('Autor_', '');
            $.ajax({
                url: "<?php echo e(url('autor/editar')); ?>",
                type: "GET",
                data: {
                    id: id
                },
                cache: false,
                success: function (result) {
                    $('#EditarModal').html(result).find('.modal').modal({
                        show: true
                    });
                }
            });

            return false;
        });

        $('button.Eliminar').click(function () {
            var id = $(this).attr('id').replace('Autor_', '');
            swal({
                    title: 'Está seguro de eliminar este Autor?',
                    text: "Una vez borrado no se podrá recuperar",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Sí',
                    cancelButtonText: 'Cancelar'
                },
                function (isConfirm) {
                    if (isConfirm) {
                        EliminarTramite(id);
                    }
                })
        });

        function EliminarTramite(id) {
            $.ajax({
                url: "<?php echo e(url('autor/eliminar')); ?>",
                type: "POST",
                data: {
                    id: id
                },
                success: function (result) {
                    if (result === "TRUE") {
                            window.location.href = "<?php echo e(url('autor')); ?>";

                    }
                    else {
                        window.location.href = "<?php echo e(url('autor')); ?>";
                    }
                }
            });
        }
        $('#tbEncuestas').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": false,
            bInfo: true,
            responsive:true,
            "autoWidth": false,
            "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": true },
                { "bSearchable": true }
            ],
            "columns": [
                { "orderable": false },
                { "orderable": false }
            ]
        });
    </script>
<?php $__env->stopSection(); ?>

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