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

<?php echo HTML::style('DataTables/responsive.dataTables.min.css'); ?>

<style type="text/css">
	@media (max-width: 450px) { .ModalEliminar .modal-dialog { width: auto; } }
	@media (min-width: 451px) { .ModalEliminar .modal-dialog { width: 450px; } }
</style>
<?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><!--/col-md-12-->
</div><!--/row-->

<div class="row">
	<?php /*
	<div class="col-md-12">
		<nav class="navbar navbar-inverse">
			<ul class="nav navbar-nav">
				<li><a href="<?php echo URL::to('templates'); ?>">Ver todos los Templates</a></li>
				<li><a href="<?php echo URL::to('templates/create'); ?>">Crear un Template</a>
			</ul>
		</nav>
	</div>
	*/ ?>
	<div class="col-md-12">
		<?php if(Session::has('message')): ?>
		<div class="alert alert-info"><?php echo Session::get('message'); ?></div>
		<?php endif; ?>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Listado de campañas </div>
			<div class="porlets-content">
				<div class="row">
					<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover display" id="tblCampanhas" width="100%" cellspacing="0">
						<thead>
							<tr>
								<th class="col-md-3"> Nombre </th>
								<th class="col-md-3"> Asunto </th>
								<th class="col-md-3"> Listas de suscriptores </th>
								<th class="col-md-3"> Acciones </th>
							</tr>
						</thead>
					</table>
				</div>
				</div>
			</div>
			<div class="bottom">
				<?php echo HTML::linkRoute('SysWebEmailMarketingCampanhasAgregar', 'Agregar', array(), array('class' => 'btn btn-primary')); ?>

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

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

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

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

<?php echo HTML::script('DataTables/dataTables.responsive.min.js'); ?>

<script type="text/javascript">
	function PruebaEnvio(idC){
		var idC = idC;
		$.post(
			"<?php echo URL::route('SysWebEmailMarketingPruebaEnvioCObtencionCampos'); ?>",
			{idC:idC},
			function(data){
				if(data.success){
					var fielset = "";
					if(data.campos.length > 0){
						var campos = "";
						for(i=0; i<data.campos.length; i++){
							campos += "<div class='form-group'> \
											<label> "+data.campos[i].nombre+" </label> <br> \
											<input type='text' name='"+data.campos[i].slug+"' class='form-control'> \
											<input type='hidden' name='Campos[]' value='"+data.campos[i].slug+"'> \
											<spam id='err"+data.campos[i].slug+"' class='text-danger'> </spam> \
										</div>";
						}
						var fielset = "<fielset> \
											<legend> Campos personalizados del mensaje </legend> \
											"+campos+" \
										</fielset>";
					}
					var mensaje = " \
						<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmPruebaEnvio'> \
									<div class='form-group'> \
										<label> Correo electronico a enviar </label> <br> \
										<input type='text' name='correo_electronico0' class='form-control'> \
										<spam id='errcorreo_electronico0' class='text-danger'> </spam> \
									</div> \
									"+fielset+" \
									<input type='hidden' name='idC' value='"+idC+"'> \
								</form> \
							</div> \
						</div> \
					";
					BootstrapDialog.show({
						title: "Correo de prueba de campaña",
						type: BootstrapDialog.TYPE_DEFAULT,
						message: mensaje,
						draggable: true,
						buttons: [{
							id: "btnEnviar",
							label: "Enviar",
							cssClass: "btn-primary",
							action: function(dialogItself){
								$("#btnEnviar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Enviando');
								$.post(
									"<?php echo URL::route('SysWebEmailMarketingPruebaEnvioCEnviar'); ?>",
									$("#frmPruebaEnvio").serialize(),
									function(data){
										$("#btnEnviar").prop("disabled", false).html("Enviar");
										if(data.success){
											new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
											dialogItself.close();
										}
										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"
								);
							}
						}]
					});
				}
				else{
					if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
				}
			},
			"json"
		);
	}
	function Eliminar(id){
		var id = id;
		var mensaje = "<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmEliminar'> \
									<h2> ¿Seguro que desea eliminar? </h2> \
									<input type='hidden' name='idC' value='"+id+"'> \
								</form> \
							</div> \
						</div>";
					BootstrapDialog.show({
						title: "Eliminar registro",
						type: BootstrapDialog.TYPE_DANGER,
						message: mensaje,
						draggable: true,
						cssClass: "ModalEliminar",
						buttons: [{
							id: "btnEliminar",
							label: "Eliminar",
							cssClass: "btn-danger",
							action: function(dialogItself){
								$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
								$.post(
									"<?php echo URL::route('SysWebEmailMarketingCampanhasEliminar'); ?>",
									{idC:id},
									function(data){
										$("#btnEnviar").prop("disabled", false).html("Eliminar");
										if(data.success){
											new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
											dialogItself.close();
											var table = $("#tblCampanhas").DataTable();
											table.ajax.reload(null, false);
										}
										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"
								);
							}
						}]
					});
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
$("#tblCampanhas").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebEmailMarketingCampanhas'); ?>",
	columns: [
		{data: 'nombre', name: 'nombre'},
		{data: 'asunto', name: 'asunto'},
		{data: 'listas', name: 'listas', "searchable": false, "orderable": false},
		{data: 'acciones', name: 'acciones', "searchable": false, "orderable": false}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	responsive: true,
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
	}
});
<?php if(Session::has('MensajeS')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('MensajeS'); ?>", type: "success" });
<?php endif; ?>
<?php if(Session::has('MensajeE')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('MensajeE'); ?>", type: "error" });
<?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>