<?php $__env->startSection('CSS'); ?>
<?php echo HTML::style('bootstrap-select/css/bootstrap-select.min.css'); ?>

<?php echo HTML::style('Intl-Tel-Input/17.0.3/css/intlTelInput.min.css'); ?>

<style>
	.iti {
		display: block;
	}
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="icons-web-site" style="font-size: 30px !important;"></i> Sitio Web </h2>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Editar usuario de sitio web </h3> </div>
			<div class="porlets-content">
				<?php echo Form::open(array('route' => array('SysWebSWebUsuariosEditar',$UsuarioSW->id), 'method' => 'post', 'class' => 'form-horizontal row-border', 'id' => 'frmEditar', 'files' => true, 'target' => 'upload_iframe')); ?>

					<div class="form-group">
						<label class="col-sm-3 control-label"> Nombre de usuario </label>
						<div class="col-sm-9">
							<?php echo Form::text('nombre_de_usuario', $UsuarioSW->nombre_de_usuario,  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errnombre_de_usuario"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Correo electrónico </label>
						<div class="col-sm-9">
							<?php echo Form::text('correo_electronico', $UsuarioSW->correo_electronico,  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errcorreo_electronico"> </span>
						</div>
					</div>
					<div class="form-group">
						<label for="slEtiquetas" class="col-sm-3 control-label"> Etiquetas a asignar </label>
						<div class="col-sm-9">
							<select class="form-control selectpicker" data-live-search="true" multiple data-selected-text-format="count" title="Seleccione las etiquetas a asociar..." id="etiquetas" name="etiquetas[]"> \
								<?php foreach( $Etiquetas as $Etiqueta ): ?>
									<?php $seleccionada = EtiquetaxUsuarioSW::where('etiquetas_id', '=', $Etiqueta->id)->where('usuarios_sitios_web_id', '=', $UsuarioSW->id)->count(); ?>
									<option value="<?php echo $Etiqueta->id; ?>" <?php if( $seleccionada == 1 ): ?> selected <?php endif; ?> id="op<?php echo $Etiqueta->id; ?>"> <?php echo $Etiqueta->nombre; ?> </option>
								<?php endforeach; ?>
							</select>
							<span class="text-danger" id="erretiquetas"> </span>
							<div id="dvEtiquetas" style="padding-top: 10px;"></div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Teléfono (opcional) </label>
						<div class="col-sm-9">
							<?php echo Form::text('telefono', '',  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errtelefono"> </span>
						</div>
					</div>
					<div class="form-group">
						<label  class="col-sm-3 control-label"> Pais (opcional) </label>
						<div class="col-sm-9">
							<select class="form-control crs-country seleccionado" id="pais" name="country" data-region-id="estado" data-default-option="Seleccione un país" data-whitelist="US,MX,CU,DM,DO,PR,BZ,GT,SV,HN,NI,CR,PA,VE,EC,CO,PE,BO,CL,PY,UY,AR,ES,GQ" data-value="shortcode" style="font-size: 13px; padding: 7.5px 11px !important;" data-default-value="<?php echo $Cliente->pais; ?>">
							</select>
							<span id="errcountry" class="text-danger"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Estado/Provincia/Depertamento (opcional) </label>
						<div class="col-sm-9">
							<select class="form-control" id="estado" name="estado" data-blank-option="Seleccione su estado" data-default-option="Seleccione su estado/provincia/departamento" style="font-size: 13px; padding: 7.5px 11px !important;">
							</select>
							<span id="errestado" class="text-danger"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Ciudad (opcional) </label>
						<div class="col-sm-9">
							<?php echo Form::text('ciudad', '',  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errciudad"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Codigo postal (opcional) </label>
						<div class="col-sm-9">
							<?php echo Form::text('postal', '',  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errpostal"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Dirección (opcional) </label>
						<div class="col-sm-9">
							<?php echo Form::text('direccion', '',  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errdireccion"> </span>
						</div>
					</div>
					<?php /* <div class="form-group">
						<label class="col-sm-3 control-label"> Contraseña </label>
						<div class="col-sm-9">
							<?php echo Form::text('contrasenha', $UsuarioSW->contrasenha,  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errcontrasenha"> </span>
						</div>
					</div> */ ?>
					<div class="bottom">
						<?php echo Form::button('Editar', array('class' => 'btn btn-warning', 'id' => 'btnEditar', 'type' => 'submit')); ?>

						<?php echo HTML::linkRoute('SysWebSWebUsuarios', 'Cancelar', array(), array('class' => 'btn btn-default')); ?>

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

		</div>
		
	</div>
</div><!--/row end-->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JS'); ?>
<?php /* HTML::script('WebPro/plugins/ckeditor-new/ckeditor.js') */ ?>
<?php echo HTML::script('Alphanum/jquery.alphanum.min.js'); ?>

<?php echo HTML::script('bootstrap-select/js/bootstrap-select.min.js'); ?>

<?php echo HTML::script('bootstrap-select/js/i18n/defaults-es_CL.min.js'); ?>

<?php echo HTML::script('Intl-Tel-Input/17.0.3/js/intlTelInput-jquery17-0-16.min.js'); ?>

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

<?php $__env->startSection('JSOr'); ?>
var datosPerfil = <?php echo $UsuarioSW->datos_perfil; ?>;

console.log(datosPerfil)
$('[name="telefono"]').intlTelInput({
	utilsScript: "<?php echo asset('Intl-Tel-Input/17.0.3/js/utils17-0-16.min.js'); ?>"
});
setTimeout(function(){
	$('[name="country"]').selectpicker();
	$('[name="estado"]').selectpicker();
},500)
$('[name="country"]').change(function(){
	setTimeout(function(){
		$('[name="estado"]').selectpicker("refresh");
	},500)
});
$('[name="telefono"]').intlTelInput("setCountry", "<?php echo $Cliente->pais; ?>");
if(datosPerfil != ""){
	$('[name="country"]').val(datosPerfil.pais);
	$('[name="country"]').attr("data-default-value", datosPerfil.pais);
	$('[name="estado"]').val(datosPerfil.estado);
	$('[name="estado"]').attr("data-default-value",datosPerfil.estado);
	$('[name="ciudad"]').val(datosPerfil.ciudad);
	$('[name="telefono"]').val(datosPerfil.telefono);
	$('[name="postal"]').val(datosPerfil.codigo_postal);
	$('[name="direccion"]').val(datosPerfil.direccion);
}
$("#frmEditar").submit(function(e){
	$.isLoading({ text: "Cargando..." }); NProgress.start();
	$("#btnEditar").html('<i class="fa fa-spinner fa-spin"></i> Cargando').prop("disabled", true);
	e.preventDefault();
	$(this).find("input").each(function(){
		$(this).val($(this).val().trim());
	});
	var frmEditar = new FormData(document.getElementById("frmEditar"));
	$.ajax({
		type: "POST",
		url: "<?php echo URL::route('SysWebSWebUsuariosEditar', array($UsuarioSW->id)); ?>",
		data: frmEditar,
		cache: false,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(data){
			$.isLoading("hide"); NProgress.done();
			$("#btnEditar").html("Guardar").prop("disabled", false);
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.href = "<?php echo URL::route('SysWebSWebUsuarios'); ?>"; }, 3000 );
			}
			else{
				if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
				$.each(data.errMensajes, function(key, value){ if(value != ''){ $("#err"+key).html(value); } else{ $("#err"+key).html(""); } });
			}
		},
		error: function(jqXHR, textStatus, errorThrown){
			new PNotify({ title: "Error", text: textStatus + " " + errorThrown, type: "error" });
		}
	});
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>