@extends('flatlab::layout')

@section('header_title')
Menus
@endsection

@section('breadcrumbs')
<ul class="breadcrumb">
	<li><a href="/gestion"><i class="fa fa-home"></i> </a></li>
	<li>Menus</li>
</ul>
@endsection
@section('main-content')
<div class="panel">
	<div class="panel-heading">
		<h3>Menus</h3>
	</div>
	<div class="panel-body">
		<div class="adv-table">
			<div class="clearfix">
				<div class="btn-group">
					<button class="btn btn-primary btn-shadow" data-toggle="modal" data-target="#menu-modal" id="nuevo">Nuevo Item de menu</button>
				</div>		
			</div>
			<table class="display hover table table-bordered table-responsive" id="menus">
				<thead>
					<tr>
						<th>Nombre</th>
						<th>Menu</th>
						<th>Padre</th>
						<th>Tipo</th>
						<th>Destino</th>
						<th>Icono</th>
						<th>Permiso</th>
						<th>Orden</th>
						<th>Acciones</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	@include('flatlab::helpers.form-modal',['accion'=>'menu-modal','titulo'=>'Menu','body'=>'<menus></menus	>'])
</div>
@endsection

@push('extra_scripts')

    <script type="text/javascript">

	$(document).ready(function() {

		$('#nuevo').click(function(){
			$('.modal-title').html('Crear Menu')
			Event.$emit('crearMenu');
		});

	    menus = $('#menus').DataTable({
	        "ajax": "{{ route('getMenus') }}",
	        "columns": [
	            {data: 'nombre', name: 'nombre'},
	            {data: 'menu', name: 'menu'},
	            {data: 'padre_id', name: 'padre_id'},
	            {data: 'tipo', name: 'tipo'},
	            {data: 'destino', name: 'destino'},
	            {data: 'icono', name: 'icono'},
	            {data: 'permiso', name: 'permiso'},
	            {data: 'orden', name: 'orden'},
	            {data: 'acciones', name: 'acciones', orderable: false, searchable: false,  className: "nowrap" }
	        ]
	    }).on('click', '.acciones button', function (e) {
	    	e.preventDefault();

	    	var id = $(this).parent().data("id");

	    	if($(this).data("action") == 'editar'){
				$('.modal-title').html('Editar Menu')
				Event.$emit('editarMenu', id);
			}
        	if($(this).data("action") == 'borrar'){
        		$('.modal-title').html('Borrar Menu')
        		Event.$emit('borrarMenu', id);
        	}    
	    	
   		})
	});

	</script> 
@endpush
