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

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

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

<style type="text/css">
	@media (max-width: 450px) { .ModalEliminar .modal-dialog { width: auto; } }
	@media (min-width: 451px) { .ModalEliminar .modal-dialog { width: 450px; } }
	.mdAvatar .modal-dialog .modal-content .modal-header{ background-color: #363B3F; }
</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">
	<div class="col-md-3">
		<div class="block-web">
			<div class="header">
				<h3 class="content-header">Vincular tipo de evento</h3>
			</div>
			<div class="porlets-content">
				<form id="frmAgegarTipoDeEvento">
					<div class="form-group mb-2">
						<label>Nombre del tipo de evento en calendly</label>
						<select name="slEventosDeCalendly" id="slEventosDeCalendly" class="form-control selectpicker" data-live-search="true" title="Selecciona el tipos de eventos a asociar a la lista de suscriptores...">
							<?php foreach( $tipoEventoYCampos as $indice => $tipoEvento ): ?>
							<option value="<?php echo $tipoEvento['idDelEvento']; ?>"><?php echo $tipoEvento['evento']; ?></option>
							<?php endforeach; ?>
						</select>
						<span class="text-danger" id="errslEventosDeCalendly"> </span>
						<input type="hidden" name="nombreEvento" value="">
					</div>
					<div class="form-group mb-2">
						<label>Etiquetas a asociar (Opcional)</label>
						<select class="form-control selectpicker" multiple data-live-search="true" data-selected-text-format="count" id="etiquetas" name="etiquetas[]" title="Seleccione las etiquetas a asociar...">
						<?php foreach($Etiquetas as $indice => $Etiqueta): ?>
						<option value="<?php echo $Etiqueta->id; ?>" id="op<?php echo $Etiqueta->id; ?>"> <?php echo $Etiqueta->nombre; ?> </option>
						<?php endforeach; ?>
						</select>
						<span class="text-danger" id="erretiquetas"> </span>
					</div>
					<?php if( $ListaEmail->gestion_clientes == 'P' ): ?>
					<div class="form-group mb-2">
						<label>Producto o servicio a asociar</label>
						<select class="form-control selectpicker" data-live-search="true" id="producto" name="producto" title="Seleccione un producto o servicio para asociar al suscribirse...">
							<?php foreach($ProductosServicio as $indice => $ProductoServicio): ?>
							<option value="<?php echo $ProductoServicio->id; ?>" id="opP<?php echo $ProductoServicio->id; ?>"> <?php echo $ProductoServicio->nombre; ?> </option>
							<?php endforeach; ?>
						</select>
						<span class="text-danger" id="errproducto"> </span>
					</div>
					<?php endif; ?>
					<input type="hidden" name="accion" value="agregar">
					<button type="submit" class="btn btn-primary" id="btnAgregar">Agregar</button>
					<a href="<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresEditar', array($ListaEmail->id)); ?>" class="btn btn-default" id="btnRegresar">Regresar</a>
				</form>
			</div>
		</div>
	</div>
	<div class="col-md-9">
		<div class="block-web">
			<div class="header">
				<h3 class="content-header">
					Listado de tipos de eventos vinculados
					<div data-toggle="buttons" class="button-group pull-right">
						<a class="refresh tooltips" data-toggle="tooltip" data-original-title="Actualizar registros" onclick="Actualizar()" href="javascript:Actualizar()" style="color: rgba(0, 0, 0, 0.3)">
							<i class="fa fa-repeat"> </i>
						</a>
					</div>
				</h3>
			</div>
			<div class="porlets-content">
				<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="tblTiposEventosAsociados">
					<thead>
						<tr>
							<th>Tipo de evento de Calendly</th>
							<th>Etiquetas asociadas</th>
							<?php if( $ListaEmail->gestion_clientes == 'P' ): ?>
							<th>Producto/Servicio asociado</th>
							<?php endif; ?>
							<th>Acciones</th>
						</tr>
					</thead>
				</table>
				</div>
			</div>
		</div>
	</div>
</div>
<?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'); ?>

<?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('country-region-selector/crs.min.js'); ?>

<?php echo HTML::script('Alphanum/jquery.alphanum.min.js'); ?>


<script type="text/javascript">
	function Actualizar(){
		var table = $("#tblTiposEventosAsociados").DataTable();
		table.ajax.reload(null, false);
	}
	function Eliminar(id){
		var mensaje = "<div class='row'> \
			<div class='col-xs-12'> \
				<form id='frmEliminar'> \
					<h2> ¿Seguro que desea eliminar? </h2> \
					<input type='hidden' name='idEDC' value='"+id+"'> \
				</form> \
				<span class='text-danger' id='erretiquetaEd' style='padding-left: 59px;'></span> \
			</div> \
		</div>";
		BootstrapDialog.show({
			title: "Eliminar registro",
			type: BootstrapDialog.TYPE_DANGER,
			message: mensaje,
			draggable: true,
			closeByBackdrop: false,
			cssClass: "ModalEliminar mdAvatar",
			onshown: function(dialogItself){
				$("body").addClass("modal-open");
			},
			buttons: [{
				id: "btnEliminar",
				label: "Eliminar",
				cssClass: "btn-danger btn-block btn-lg",
				action: function(dialogItself){
					$.isLoading({ text: "Cargando..." }); NProgress.start();
					$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresEditarEventosDeCalendly', array($ListaEmail->id)); ?>",
						{accion: "eliminar", idEDC: id},
						function(data){
							$.isLoading("hide"); NProgress.done();
							$("#btnEliminar").prop("disabled", false).html("Eliminar");
							if(data.success){
								$("#tblTiposEventosAsociados").DataTable().ajax.reload(false, false);
								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"
					);
				}
			}],
			onhidden: function(dialogItself){
				$("body").removeClass("modal-open");
			}
		});
	}
</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('JSOr'); ?>
$("#slEventosDeCalendly").on("changed.bs.select", function(e, clickedIndex, isSelected, previousValue){
	var valor = $("#slEventosDeCalendly").selectpicker("val");
	var nombreEvento = $('#slEventosDeCalendly option[value="'+valor+'"]').html();
	$('[name="nombreEvento"]').val( nombreEvento );
});
var tblTiposEventosAsociados = $("#tblTiposEventosAsociados").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresEditarEventosDeCalendly', array($ListaEmail->id)); ?>",
	columns: [
		{data: "nombreTipoDeEvento", name: "nombreTipoDeEvento"},
		{data: "etiquetas", "searchable": false, "orderable": false},
		<?php if( $ListaEmail->gestion_clientes == 'P' ): ?>
		{data: "nombre", name: "nombre", "searchable": false, "orderable": false},
		<?php endif; ?>
		{data: "acciones", name: "acciones", "searchable": false, "orderable": false, "class": "text-center"}
	],
	dom: "<'row'<'col-sm-3'l><'col-sm-3'f><'col-sm-6'p>>" +
		"<'row'<'col-sm-12'tr>>" +
	"<'row'<'col-sm-5'i><'col-sm-7'p>>",
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"fnDrawCallback": function(oSettings){
		$(".tooltips").tooltip();
	},
	autoWidth: false,
	responsive: true
});
$("#frmAgegarTipoDeEvento").submit(function(e){
	e.preventDefault();
	$.isLoading({ text: "Cargando..." }); NProgress.start();
	$("#btnAgregar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Agregando');
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresEditarEventosDeCalendly', array($ListaEmail->id)); ?>",
		$("#frmAgegarTipoDeEvento").serialize(),
		function(data){
			$.isLoading("hide"); NProgress.done();
			$("#btnAgregar").prop("disabled", false).html("Agregar");
			if(data.success){
				tblTiposEventosAsociados.ajax.reload(false, 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(""); } });
			}
			$("#etiqueta").val("");
		},
		"json"
	);
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>