@extends('flatlab::layout')

@section('header_title')
    Permisos
@endsection
@section('breadcrumbs')
<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="{{ route('gestion.index') }}"><i class="fa fa-home"></i> </a></li>
        <li  class="breadcrumb-item active" aria-current="page">Permisos</li>
    </ol>
</nav>
@endsection
@section('main-content')
<div class="card">
    <div class="card-header">
        <i class="fa fa-lock"></i> Permisos
    </div>
    <div class="card-body">
        <div class="adv-table table-responsive">
            <div class="clearfix">
                <div class="btn-group">
                    <button class="btn btn-primary btn-shadow" data-toggle="modal" data-target="#permiso-modal" id="nuevo">Nuevo Permiso</button>
                </div>
            </div>
            <table class="display nowrap hover table table-bordered " id="permisos">
                <thead>
                    <tr>
                        <th>Permiso</th>
                        <th>Roles</th>
                        <th>Acciones</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
@include('flatlab::helpers.form-modal',['accion'=>'permiso-modal','titulo'=>'Permiso','body'=>'<permisos></permisos>'])
@endsection
@push('extra_scripts')
   <script type="text/javascript">
    $(document).ready(function() {
        $('#nuevo').click(function(){
            $('.modal-title').html('Crear Permiso')
			Event.$emit('crearPermiso');
		});

        permisos = $('#permisos').DataTable({
            "ajax": "{{ route('getPermisos') }}",
            "columns": [
                {data: 'name', name: 'name'},
                {data: 'roles', name: 'roles'},
                {data: 'acciones', name: 'acciones', orderable: false, searchable: false,  className: "text-center nowrap" }
            ]
        }).on('click', '.acciones button', function (e) {
            e.preventDefault();
            var permiso = $(this).parent().data("permiso");
            if($(this).data("action") == 'editar'){
				$('.modal-title').html('Editar Permiso')
				Event.$emit('editarPermiso', permiso);
            }
            if($(this).data("action") == 'borrar'){
                $('.modal-title').html('Borrar Permiso')
                Event.$emit('borrarPermiso', permiso.id);
            }
        })
    });
    </script>
@endpush
