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

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


<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="fa fa-envelope-o"></i> E-Mail Marketing </h2>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Edición de suscriptor <strong> <?php echo $Suscriptor->correo_electronico; ?> </strong> </h3> </div>
			<div class="porlets-content">
				<?php echo Form::open(array('route' => 'SysWebEmailMarketingListasSubscriptoresSuscriptorEditar', 'method' => 'post', 'class' => 'form-horizontal', 'id' => 'frmEditar')); ?>

					<?php foreach($CampoLista as $Campo): ?>
						<div class="form-group">
							<label class="col-sm-3 control-label"> <?php echo $Campo->nombre; ?> </label>
							<div class="col-sm-9">
								<?php echo Form::text($Campo->slug, (array_key_exists($Campo->slug, $ValoresCampo))?$ValoresCampo[$Campo->slug]:'',  array('class' => 'form-control', 'placeholder' => '')); ?>

								<span class="text-danger" id="err<?php echo $Campo->slug; ?>"> </span>
							</div>
						</div>
					<?php endforeach; ?>

					<div class="form-group">
						<label class="col-sm-3 control-label"> Etiquetas asociadas (Opcional) </label>
						<div class="col-sm-9">
							<select class="form-control selectpicker" multiple data-live-search="true" data-selected-text-format="count" id="etiquetas" name="etiquetas[]">
								<option value="0" disabled> Seleccione las etiquetas a asociar... </option>
								<?php foreach($Etiquetas as $indice => $Etiqueta): ?>
								<?php $seleccionada = EtiquetaxSuscriptor::where('etiquetas_id', '=', $Etiqueta->id)->where('subscriptores_id', '=', $Suscriptor->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;">
								<?php foreach($Etiquetas as $indice => $Etiqueta): ?>
									<?php if( EtiquetaxSuscriptor::where('etiquetas_id', '=', $Etiqueta->id)->where('subscriptores_id', '=', $Suscriptor->id)->count() == 1 ): ?>
								<span class="label label-info" data-valor="<?php echo $Etiqueta->nombre; ?>">
									<?php echo $Etiqueta->nombre; ?>

								</span> &nbsp;
									<?php endif; ?>
								<?php endforeach; ?>
							</div>
						</div>
					</div>

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

						<?php echo HTML::linkRoute('SysWebEmailMarketingListasSubscriptoresVer', 'Cancelar', array($idL), 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('bootstrap-select/js/bootstrap-select.min.js'); ?>

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

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

<?php $__env->startSection('JSOr'); ?>
$("#etiquetas").on("changed.bs.select", function(e){
	$("#dvEtiquetas").html("");
	$.each(
		$(this).val(),
		function(key, value){
			$("#dvEtiquetas").append(' \
				<span class="label label-info" data-valor="'+$("#op"+value).html()+'"> \
					'+$("#op"+value).html()+' \
				</span> &nbsp; \
			');
		}
	);
});
$("#frmEditar").submit(function(e){
	e.preventDefault();
	$.isLoading({ text: "Cargando..." }); NProgress.start();
	$("#btnEditar").html('<i class="fa fa-spinner fa-spin"></i> Cargando').prop("disabled", true);
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresSuscriptorEditar', array($idL, $Suscriptor->id)); ?>",
		$("#frmEditar").serialize(),
		function(data){
			$.isLoading("hide"); NProgress.done();
			$("#btnEditar").html("Editar").prop("disabled", false);
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.href = "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVer', array($idL)); ?>"; }, 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(""); } });
			}
		},
		"json"
	);
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>