<?php $__env->startSection('titulo', 'Modificar Municipio'); ?>

<?php $__env->startSection('botonera'); ?>
	<?php echo $__env->make('componentes.boton-volver-al-listado-de-municipios', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<?php echo $__env->make('componentes.boton-salir-con-aviso', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
	<?php /* modals */ ?>
	<?php echo $__env->make('componentes.modal-salir', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<?php echo $__env->make('componentes.modal-volver-al-listado-de-municipios', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<?php echo $__env->make('alerts.request', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

	<?php echo Form::model($municipio, ['route'=>['municipio.update', $municipio->id], 'method'=>'PUT']); ?>

		<?php echo $__env->make('municipio.forms.municipio', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
		<div class="row">
			<div class="col-xs-12 form-group">
				<?php echo Form::submit('Modificar', ['class'=>'btn btn-primary']); ?>

			</div>
		</div>
	<?php echo Form::close(); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
	<script type="text/javascript">
	$(document).ready(function(){
		var xhr = null;

		// Validar el codigo
		$('input[name=id]').on('keyup change', function(){
			var t=$(this);
			if(xhr) {xhr.abort()};
			xhr = $.ajax({
				headers:{'X-CSRF-TOKEN':'<?php echo e(csrf_token()); ?>'},
				url:'<?php echo e(URL::to("municipio-validar-campos")); ?>',
				method:'post',
				data:{
					id:t.val()
				},
				beforeSend:function(){
					t.parent().removeClass('has-error has-success');
				},
				success:function(r){
					r ? t.parent().removeClass('has-succes').addClass('has-error') : t.parent().removeClass('has-error').addClass('has-success');
				}
			});
		});

		// Validar el nombre
		$('input[name=nombre]').on('keyup change', function(){
			var t=$(this);
			if(xhr) {xhr.abort()};
			xhr = $.ajax({
				headers:{'X-CSRF-TOKEN':'<?php echo e(csrf_token()); ?>'},
				url:'<?php echo e(URL::to("municipio-validar-campos")); ?>',
				method:'post',
				data:{
					nombre:t.val()
				},
				beforeSend:function(){
					t.parent().removeClass('has-error has-success');
				},
				success:function(r){
					r ? t.parent().removeClass('has-succes').addClass('has-error') : t.parent().removeClass('has-error').addClass('has-success');
				}
			});
		});

		// Resaltar campos al eviar el formulario, detectando errores de validación
		<?php if(count($errors) > 0): ?>
			$('input').parent().addClass('has-success');
			<?php foreach($errors->getMessages() as $key => $value): ?>
				$('input[name=<?php echo e($key); ?>]').parent().removeClass('has-success').addClass('has-error');
			<?php endforeach; ?>
		<?php endif; ?>

		<?php echo $__env->make('componentes.script-mostrar-modal-request', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;

	});
	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin-bloqueo-vista', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>