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

<style type="text/css">
	.pointer{ cursor:pointer; }
	.Separacion{ display: inline-block; padding: 1px; }
</style>
<?php echo HTML::style('image-picker/image-picker.css'); ?>

<style type="text/css">
	.image_picker_image{ height: 260px !important; width: 200px !important; }
</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>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Editar secuencia de seguimiento </h3> </div>
			<div class="porlets-content">
				<?php echo Form::open(array('route' => array('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientosEditar', $ListaEmail->id, $SecuenciaSeguimiento->id), 'method' => 'post', 'class' => 'form-horizontal row-border', 'id' => 'frmEditar')); ?>

					<div class="form-group">
						<label class="col-sm-3 control-label"> Asunto </label>
						<div class="col-sm-9">
							<?php echo Form::text('asunto', $SecuenciaSeguimiento->asunto,  array('class' => 'form-control', 'placeholder' => '')); ?>

							<span class="text-danger" id="errasunto"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Campos disponibles </label>
						<div class="col-sm-9">
							<?php foreach($Campos as $Campo): ?>
							<?php $label = ($Campo->requerido==1)?'success':'info'; ?>
							<div class="Separacion pointer" onclick="AgregarTexto('<?php echo $Campo->slug; ?>')"> <span class="label label-<?php echo $label; ?>"> <?php echo $Campo->nombre; ?> </span> </div>
							<?php endforeach; ?>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Evaluar vínculos </label>
						<div class="col-sm-9">
							<label class="checkbox-inline">
								<?php $Clic = ($SecuenciaSeguimiento->clic==1)?true:null; ?>
								<?php echo Form::checkbox('clic', 1, $Clic, array('id' => 'clic')); ?>

								<span class="custom-checkbox"></span> Medir clics
							</label>
							<span class="text-danger" id="errconfirmacion"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Mensaje </label>
						<div class="col-sm-9">
							<?php echo Form::textarea('mensaje', str_replace('{ clic }', '', $SecuenciaSeguimiento->mensaje), array('class' => 'form-control ckeditor', 'rows' => '2', 'placeholder' => 'Escriba el mensaje')); ?>

							<span class="text-danger" id="errmensaje"> </span>
						</div>
					</div>
					<div id="hdnmensaje" style="display: none;"></div> <?php /* Div utilizado para modificar el mensaje en caso de realizar una evaluación de vínculos */ ?>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Días despues </label>
						<div class="col-sm-9">
							<?php echo Form::text('dias_despues', $SecuenciaSeguimiento->dias_despues,  array('id' => 'dias_despues')); ?>

							<span class="text-danger" id="errdias_despues"> </span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label"> Tipo de mensaje </label>
						<div class="col-sm-9">
							<label class="checkbox-inline">
								<?php $ST = ($SecuenciaSeguimiento->tipo=='T')?true:null; ?>
								<?php echo Form::checkbox('tipo', 1, $ST, array('id' => 'tipo')); ?>

								<span class="custom-checkbox"></span> Solo texto, no quiero la plantilla HTML
							</label>
							<span class="text-danger" id="errtipo"> </span>
						</div>
					</div>
					<div id="confplantilla" <?php if($ST): ?> style="display: none;" <?php endif; ?>>
						<div class="form-group">
							<label class="col-sm-3 control-label"> Plantilla HTML </label>
							<div class="col-sm-9">
								<?php /* MACRO REALIZADO POR KEVIN MORÁN PUEDE UBICARSE EN /app/start/global.php AL FINAL DEL DOCUMENTO POR SI NECESITA MODIFICARSE */ ?>
								<?php echo Form::slPlantillasMensajesC('color', array('azul' => 'blue', 'verde' => 'green', 'rosado' => 'pink'), $SecuenciaSeguimiento->color); ?>

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

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

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

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

<?php $__env->startSection('JS'); ?>
<?php echo HTML::script('WebPro/plugins/ckeditor-new/ckeditor.js'); ?>

<?php echo HTML::script('TouchSpin/jquery.bootstrap-touchspin.min.js'); ?>

<?php echo HTML::script('image-picker/image-picker.min.js'); ?>

<?php echo HTML::script('SysWeb/SumeClientes/php.js'); ?>

<script type="text/javascript">
	function AgregarTexto(slug){
		var slug = slug;
		slug = "{ "+slug+" }";
		CKEDITOR.instances.mensaje.insertText(slug);
	}
	function DecodificarVinculo(){
		editor = CKEDITOR.instances.mensaje;
		var mensaje = editor.getData();
		$("#hdnmensaje").html(mensaje);
		$("#hdnmensaje").find("a").each(function() {
			var ruta = $(this).attr("href");
			ruta = ruta.replace("{ clic }", "");
			ruta = decode(ruta);
			$(this).attr("href", ruta);
		});
		mensaje = $("#hdnmensaje").html();
		editor.setData(mensaje);
		for(instance in CKEDITOR.instances){ CKEDITOR.instances[instance].updateElement(); }
	}
	function CodificarVinculo(){
		editor = CKEDITOR.instances.mensaje;
		var mensaje = editor.getData();
		$("#hdnmensaje").html(mensaje);
		$("#hdnmensaje").find("a").each(function() {
			var ruta = "{ clic }"+encode($(this).attr("href"));
			$(this).attr("href", ruta);
		});
		mensaje = $("#hdnmensaje").html();
		editor.setData(mensaje);
		for(instance in CKEDITOR.instances){ CKEDITOR.instances[instance].updateElement(); }
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
CKEDITOR.on("instanceReady", function(evt){ if($("#clic").is(":checked")){ DecodificarVinculo(); } });
$("select").imagepicker({ hide_select : true, show_label  : true });
$("#tipo").click(function(){
	if($("#tipo").is(":checked")){
		$("#confplantilla").hide("slow");
		$("#errcolor").html("");
	}
	else{
		$("#confplantilla").show("slow");
	}
});
$("#dias_despues").TouchSpin({
	verticalbuttons: true,
	verticalupclass: "glyphicon glyphicon-plus",
	verticaldownclass: "glyphicon glyphicon-minus",
	initval: <?php echo $SecuenciaSeguimiento->dias_despues; ?>

});
$("#frmEditar").submit(function(e){
	$("#btnEditar").html('<i class="fa fa-spinner fa-spin"></i> Cargando').prop("disabled", true);
	e.preventDefault();
	for(instance in CKEDITOR.instances){ CKEDITOR.instances[instance].updateElement(); }
	//CONVERSIÓN DE VÍNCULOS
	if($("#clic").is(":checked")){ CodificarVinculo(); }
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientosEditar', array($ListaEmail->id, $SecuenciaSeguimiento->id)); ?>",
		$("#frmEditar").serialize(),
		function(data){
			$("#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('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientos', 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(""); } });
				if($("#clic").is(":checked")){ DecodificarVinculo(); }
			}
		},
		"json"
	);
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>