<?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-6">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Añadir un suscriptor </h3> </div>
			<div class="porlets-content">
				<?php echo Form::open(array('route' => array('SysWebEmailMarketingListasSubscriptoresAgregarSubscriptor', $ListaEmail->id), 'method' => 'post', 'class' => 'form-horizontal row-border', 'id' => 'frmAgregar', 'files' => true, 'target' => 'upload_iframe')); ?>

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

							<span class="text-danger" id="err<?php echo $CampoListaEmail->slug; ?>"> </span>
						</div>
					</div>
					<?php endforeach; ?>
					<?php /* VALIDACIÓN MAYOR A 1 PORQUE LA 1 ES LA OBLIGACIÓN DE SELECCIÓN */ ?>
					<?php if(count($slSecuenciasSeguimientos)>1): ?>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Secuencia de segimiento inicial </label>
						<div class="col-sm-9">
							<?php echo Form::select('secuencias_seguimientos_id', $slSecuenciasSeguimientos, null, array('class' => 'form-control selectpicker', 'id' => 'configuraciones_emails_id', 'data-live-search' => 'true')); ?>

							<span class="text-danger" id="errsecuencias_seguimientos_id"> </span>
						</div>
					</div>
					<?php endif; ?>
					<div class="bottom">
						<?php echo Form::button('Guardar', array('class' => 'btn btn-primary', 'id' => 'btnAgregar', 'type' => 'submit')); ?>

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

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

			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Importar suscriptores </h3> </div>
			<div class="porlets-content">
				<p> Importa suscriptores de forma masiva utilizando un archivo CSV, solo debes tomar en cuenta lo siguiente: </p>
				<p> * Descarga la plantilla de tu lista de suscriptores y llena los datos, almacenando esta en formato csv separado por comas </p>
				<p> * Los campos requeridos están sombreados de rojo </p>
				<?php echo Form::open(array('route' => array('SysWebEmailMarketingListasSubscriptoresAgregarImportar', $ListaEmail->id), 'method' => 'post', 'class' => 'form-horizontal row-border', 'id' => 'frmImportar', 'files' => true)); ?>

					<div class="form-group">
						<label class="col-sm-3 control-label"> Archivo CSV </label>
						<div class="col-sm-9">
							<?php echo Form::file('archivocsv', array('class' => '', 'id' => 'archivocsv')); ?>

							<span class="text-warning" style="display: none;" id="imgarchivocsv" class="loading">
								<div class="row">
									<div class="col-md-1">
										<img src="<?php echo asset('Cargando/hourglass.gif'); ?>" style="width: 32px; height: 32px;">
									</div>
									<div class="col-md-11">
										Espere mientras se carga el archivo, recuerde que este proceso puede tardarse unos minutos dependiendo del número de suscriptores en la plantilla para mientras puedes ir por un café
										<i class="fa fa-smile-o"></i> 
									</div>
								</div>
							</span>
							<span class="text-danger" id="errarchivocsv"> <?php echo $errors->first('archivocsv'); ?> </span>
						</div>
					</div>
					<?php /* VALIDACIÓN MAYOR A 1 PORQUE LA 1 ES LA OBLIGACIÓN DE SELECCIÓN */ ?>
					<?php if(count($slSecuenciasSeguimientos)>1): ?>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Secuencia de segimiento inicial </label>
						<div class="col-sm-9">
							<?php echo Form::select('secuencias_seguimientos', $slSecuenciasSeguimientos, null, array('class' => 'form-control selectpicker', 'id' => 'configuraciones_emails_id', 'data-live-search' => 'true')); ?>

							<span class="text-danger" id="errsecuencias_seguimientos"> </span>
						</div>
					</div>
					<?php endif; ?>
					<?php if( $errors->first('MensajeError') ): ?>
					<div class="alert alert-danger">
						<strong> Verifica los siguientes errores: </strong>
						<?php echo $errors->first('MensajeError'); ?>

					</div>
					<?php endif; ?>
					<div class="alert alert-danger" style="display:none;" id="MensajeError">
						<strong> Verifica los siguientes errores: </strong>
						<div id="Errs"> <?php echo $errors->first('MensajeError'); ?> </div>
					</div>
					<div class="bottom">
						<?php echo Form::button('Importar', array('class' => 'btn btn-primary', 'id' => 'btnImportar', 'type' => 'submit')); ?>

						<a href="<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresAgregarPlantilla', array($ListaEmail->id)); ?>" class="btn btn-success"> Plantilla </a>
					</div>
				<?php echo Form::close(); ?>

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

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

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

<?php $__env->startSection('JSOr'); ?>
<?php if(Session::has('message')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('message'); ?>", type: "success" });
<?php endif; ?>
$(".selectpicker").selectpicker();
$("#frmAgregar").submit(function(e){
	$('[id^="err"]').html("");
	$("#btnAgregar").html('<i class="fa fa-spinner fa-spin"></i> Cargando');
	$("button[type='submit']").prop("disabled", true);
	e.preventDefault();
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresAgregarSubscriptor', array($ListaEmail->id)); ?>",
		$("#frmAgregar").serialize(),
		function(data){
			$("button[type='submit']").prop("disabled", false);
			$("#btnAgregar").html("Guardar");
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.href = "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVer', array($ListaEmail->id)); ?>"; }, 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"
	);
});
$("#frmImportar").submit(function(e){
	$('[id^="err"]').html("");
	$("button[type='submit']").prop("disabled", true);
	$("#btnImportar").html('<i class="fa fa-spinner fa-spin"></i> Cargando');
	e.preventDefault();
	var frmImportar = new FormData(document.getElementById("frmImportar"));
	if( $("#archivocsv").val() != "" ){ $("#imgarchivocsv").show(); }
	$.ajax({
		type: "POST",
		url: "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresAgregarImportar', array($ListaEmail->id)); ?>",
		data: frmImportar,
		cache: false,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(data){
			$("button[type='submit']").prop("disabled", false);
			$("#btnImportar").html("Importar");
			$("#imgarchivocsv").hide();
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.href = "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVer', array($ListaEmail->id)); ?>"; }, 3000 );
			}
			else{
				if(typeof data.MensajeError != "undefined"){ $("#Errs").html(data.MensajeError); $("#MensajeError").show(); }else{ $("#MensajeError").hide(); $("#Errs").html(""); }
				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){
			$("input[type='submit']").prop("disabled", false);
			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(); ?>