<?php $__env->startSection('CSS'); ?>
<?php echo HTML::style('DataTables/dataTables.bootstrap.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"> Suscriptores de la lista <strong> <?php echo $ListaEmail->nombre; ?> </strong>  </h3> </div>
			<div class="porlets-content">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover" id="tblSuscriptores">
						<thead>
							<tr>
								<th class="col-md-9"> Suscriptor </th>
								<th class="col-md-1"> Acciones </th>
								<th> correo_electronico </th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div class="bottom">
				<?php echo HTML::linkRoute('SysWebEmailMarketingListasSubscriptoresAgregarSubscriptor', 'Agregar', array($ListaEmail->id), 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'); ?>

<script type="text/javascript">
	function Info(id){
		var id = id;
		if( $("#Info"+id).hasClass("in") ){
			$("#Campos"+id).html("");
			$("#tblSubscriptor"+id).DataTable().destroy();

		}
		else{
			$("#CargandoCampos"+id).show();
			$.post(
				"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVerCampos', array($ListaEmail->id)); ?>",
				{idS:id,idL:<?php echo $ListaEmail->id; ?>},
				function(data){
					if(data.success){
						$("#CargandoCampos"+id).hide();
						if( data.SuscriptorCampoValor.length > 0 ){
							var Campos = '<dl>';
							for(i=0;i<data.SuscriptorCampoValor.length;i++){
								if(data.SuscriptorCampoValor[i].value==''){ Valor = '&nbsp;'; }else{ Valor = data.SuscriptorCampoValor[i].value; }
								Campos += '<dt>'+data.SuscriptorCampoValor[i].nombre+'</dt><dd>'+Valor+'</dd>';
							}
							Campos += '</dl>';
							$("#Campos"+id).html(Campos);
						}
					}
					else{
						if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
					}
				},
				"json"
			);
			$("#tblSubscriptor"+id).DataTable({
				"processing": true,
				"serverSide": true,
				"iDisplayLength": 5,
				"aLengthMenu": [[5], [5]],
				"ajax": "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVerActividad', array('idS')); ?>".replace("idS", id),
				columns: [
					{data: 'asunto', name: 'asunto', "searchable": true, "orderable": true},
					{data: 'fecha_enviado', name: 'fecha_enviado', "searchable": false, "orderable": false},
					{data: 'fecha_abierto', name: 'fecha_abierto', "searchable": false, "orderable": false},
					{data: 'fecha_clic', name: 'fecha_clic', "searchable": false, "orderable": false}
				],
				"language": {
					"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
				},
				"fnDrawCallback": function( oSettings ) {
					$(".tooltips").tooltip();
				}
			});
		}
	}
	function Eliminar(id){
		var id = id;
		var idL = <?php echo $ListaEmail->id; ?>;
		var mensaje = "<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmEliminar'> \
									<h2> ¿Seguro que desea eliminar? </h2> \
									<input type='hidden' name='idL' value='"+idL+"'> \
									<input type='hidden' name='idS' 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('SysWebEmailMarketingListasSubscriptoresSuscriptorEliminar'); ?>",
									{idS:id,idL:idL},
									function(data){
										$("#btnEnviar").prop("disabled", false).html("Eliminar");
										if(data.success){
											new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
											dialogItself.close();
											var table = $("#tblSuscriptores").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'); ?>
$("#tblSuscriptores").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresVer', array($ListaEmail->id)); ?>",
	columns: [
		{data: 'suscriptor', name: 'suscriptor', "searchable": false, "orderable": false},
		{data: 'acciones', name: 'acciones', "searchable": false, "orderable": false},
		{data: 'correo_electronico', name: 'correo_electronico', "visible": false, "orderable": false}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"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(); ?>