@include('header')
@include('navigator_menu_principal')

<div class="container">

	<div class="row">
		<div class="col-md-4 h3">Campos de documentos LED</div>
		<div class="col-md-8 text-right">
			<button type="button" class="btn btn-fidelitas btn-primary" id="btnadd" data-toggle="modal" data-target="#modalCampo"><i class="fa fa-plus"></i> Agregar campo</button>
			<button type="button" class="btn btn-fidelitas btn-primary" id="btnaddtable" data-toggle="modal" data-target="#modalCampo"><i class="fa fa-table"></i> Agregar campo tabla</button>
			<button type="button" class="btn btn-fidelitas btn-primary" onclick="location.href='/'">Regresar</button>
		</div>
	</div>

	<table class="table table-condensed table-striped" id="tablaCampos">
	<thead>
		<tr>
			<th>Nombre del campo</th>
			<th>Etiqueta</th>
			<th nowrap="nowrap">Tipo de campo</th>
			<th>Long</th>
			<th>Dec.</th>
			<!-- <th>Validación</th> -->
			<th>Acciones</th>
		</tr>
	</thead>
	<tbody>
		@foreach($campos AS $fld)
		<tr>
			<td>{{$fld->nombre_campo}}</td>			
			<td>{{$fld->etiqueta}}</td>			
			<td class="text-center">
				@if ($fld->tipo_campo == 'T') Texto
				@elseif ($fld->tipo_campo == 'N') Numérico
				@elseif ($fld->tipo_campo == 'D') Fecha
				@elseif ($fld->tipo_campo == 'B') SI/NO
				@elseif ($fld->tipo_campo == 'S') Selección de opciones
				@elseif ($fld->tipo_campo == 'M') Texto largo
				@elseif ($fld->tipo_campo == 'R') Radio
				@elseif ($fld->tipo_campo == 'C') Checkbox
				@elseif ($fld->tipo_campo == 'F') Archivo
				@elseif ($fld->tipo_campo == 'L') Texto fijo
				@elseif ($fld->tipo_campo == 'G') Tabla
				@endif
			</td>			
			<td class="text-center">
				@if ($fld->tipo_campo == 'T' || $fld->tipo_campo == 'N') {{$fld->longitud}} @endif
			</td>			
			<td class="text-center">
				@if ($fld->tipo_campo == 'N') {{$fld->decimales}} @endif
			</td>
			<!-- <td class="text-center">{{$fld->validacion}}</td> -->
			<td class="text-center" nowrap="nowrap">
				<a class="btn btn-primary btn-fidelitas btnaccion" data-campo="{{$fld->campo}}" data-tipo-campo="{{$fld->tipo_campo}}" data-accion="edit" data-toggle="modal" data-target="#modalCampo">Editar</a>
				<a class="btn btn-primary btn-fidelitas btnaccion" data-campo="{{$fld->campo}}" data-tipo-campo="{{$fld->tipo_campo}}" data-accion="delete" data-toggle="modal" data-target="#modalCampo">Borrar</a>
			</td>
		</tr>
		@endforeach
	</tbody>
	<tfoot></tfoot>
	</table>

</div>


<div id="modalCampo" class="modal fade">
    <div class="modal-dialog" style="width:750px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="modalTitle">Campos de documentos LED</h3>
            </div>
            <div class="modal-body" id="campo_edit"></div>
        </div>
    </div>
</div>

<form id="frmCampos" method="post">
	<input type="hidden" name="_token" value="{{csrf_token()}}" id="_token">
</form>

<script language="javascript">
	$(document).ready(function() {

		$('#btnadd').on('click', function() {
			$.ajax({
					method: 'get',
					url: '/led/led-campos-new',
					data: {},
					beforeSend: function() {
						$('#modalTitle').html('Agregar campo');
						$('#campo_edit').html('');
					},
					success: function(data) {
						$('#campo_edit').html(data);
					},
			});

		});

		$('#btnaddtable').on('click', function() {
			$.ajax({
					method: 'post',
					url: '/led/led-campos-col-step',
					data: { '_token' : '{{csrf_token()}}'},
					beforeSend: function() {
						$('#modalTitle').html('Agregar campo tabla');
						$('#campo_edit').html('');
					},
					success: function(data) {
						$('#campo_edit').html(data);
					},
			});

		});


		$('.btnaccion').on('click', function() {
			var id = $(this).data('campo');
			var tipo = $(this).data('tipoCampo');
			var acc = $(this).data('accion');
			
			$.ajax({
					method: 'post',
					url: '/led/led-campos-edit',
					data: { 'accion' : acc, 'campo' : id, 'tipo_campo' : tipo, '_token' : $('#_token').val() },
					beforeSend: function() {
						$('#modalTitle').html('Editar campo');
						$('#campo_edit').html('');
					},
					success: function(data) {
						$('#campo_edit').html(data);
					},


			});

		});

		$('#tablaCampos').DataTable({

							"pagingType": "full_numbers",
							"dom" : "p<'row'>f<t>lp",
							"ordering": true,
							"columns": [ null, null, null, null, null, { "orderable": false } ],
							"searching": true,
							"order": [[ 0, "asc" ]],
							"info":  true,
							"lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100,"Todos"] ],
							"pageLength": 10,
							"language": {
								"lengthMenu": "Mostrar _MENU_ registros por página",
								"zeroRecords": "No hay registros disponibles",
								//"info": "Mostrando página _PAGE_ de _PAGES_",
								//"info": "Total de Registros: _MAX_", 
								"info": "Mostrando  _START_  de  _END_ - <b>Total:</b> _TOTAL_ registros",
								"infoEmpty": "No hay registros disponibles",
								"infoFiltered": "(filtered from _MAX_ total records)",
								"sSearch": "Buscar",
								"oPaginate": {
									"sFirst": "Primera",
									"sPrevious": "Anterior",
									"sNext": "Siguiente",
									"sLast": "Última"
								},
							}


		});



	});
</script>

@include('footer')