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

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

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

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

<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="fa fa-server"></i> Gestión de servidores de AWS SES </h2>
	</div><!--/col-md-12-->
</div><!--/row-->

<div class="row">
	<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"> Agregar servidor de AWS SES </h3>
			</div>
			<div class="porlets-content">
				<form id="frmAgregar">
					<div class="form-group">
						<label for="nombre">Nombre</label>
						<input type="text" class="form-control" id="nombre" name="nombre" placeholder="Nombre del servidor">
						<span class="text-danger" id="errnombre"></span>
					</div>
					<div class="form-group">
						<label for="clientes_id">Asignadar al cliente</label>
						<select class="form-control selectpicker with-ajax" data-live-search="true" name="clientes_id" id="clientes_id">
							<!-- <option value="0" selected>Es de la plataforma</option> -->
						</select>
						<span class="text-danger" id="errclientes_id"></span>
					</div>
					<div class="form-group">
						<label for="key">Key</label>
						<input type="text" class="form-control" id="key" name="key" placeholder="">
						<span class="text-danger" id="errkey"></span>
					</div>
					<div class="form-group">
						<label for="secret">Secret</label>
						<input type="text" class="form-control" id="secret" name="secret" placeholder="">
						<span class="text-danger" id="errsecret"></span>
					</div>
					<div class="form-group">
						<label for="region">Region</label>
						<input type="text" class="form-control" id="region" name="region" placeholder="">
						<span class="text-danger" id="errregion"></span>
					</div>
					<div class="form-group">
						<label for="region">Bounce Topic Name</label>
						<input type="text" class="form-control" id="bounceTopic" name="bounceTopic" placeholder="">
						<span class="text-danger" id="errbounceTopic"></span>
					</div>
					<div class="form-group">
						<label for="region">Complain Topic Name</label>
						<input type="text" class="form-control" id="complainTopic" name="complainTopic" placeholder="">
						<span class="text-danger" id="errcomplainTopic"></span>
					</div>
					<div class="form-group">
						<label for="region">Delivery Topic Name</label>
						<input type="text" class="form-control" id="deliveryTopic" name="deliveryTopic" placeholder="">
						<span class="text-danger" id="errdeliveryTopic"></span>
					</div>
					<div class="form-group">
						<label for="region">SNS Topic</label>
						<input type="text" class="form-control" id="SnsTopic" name="SnsTopic" placeholder="">
						<span class="text-danger" id="errSnsTopic"></span>
					</div>
					<div class="form-group">
						<label for="estado">Estado</label>
						<select class="form-control selectpicker" name="estado">
							<option value="1" selected>Activo</option>
							<option value="0">Inactivo</option>
						</select>
						<span class="text-danger" id="errestado"></span>
					</div>
					<div class="form-group">
						<label for="enusopordefecto">En uso por defecto </label>
						<select class="form-control selectpicker" name="enusopordefecto">
							<option value="1" selected>Si, asignar automáticamente a los perfiles nuevos</option>
							<option value="0">No, solo será de respaldo</option>
						</select>
						<span class="text-danger" id="errenusopordefecto"></span>
					</div>
					<div class="form-group">
						<label for="tipo">Tipo</label>
						<select class="form-control selectpicker" name="tipo">
							<option value="EMC" selected>Email Marketing de Clientes</option>
							<option value="NP">Notificaciones de Plataforma</option>
							<option value="REMC">Respaldo de Email Marketing de Clientes</option>
							<option value="EMCP">Email Marketing Personal</option>
							<option value="EMCSE">Email Marketing Clientes sume.email</option>
						</select>
						<span class="text-danger" id="errtipo"></span>
					</div>
				</form>
			</div>
			<div class="bottom">
				<button type="button" class="btn btn-primary" id="btnAgregar">Agregar</button>
				<?php echo HTML::linkRoute('SysWebEmailMarketingSrvAWSSES', 'Cancelar', array(), array('class' => 'btn btn-default')); ?>

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

<?php $__env->startSection('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('ajax-bootstrap-select/js/ajax-bootstrap-select.min.js'); ?>

<?php echo HTML::script('ajax-bootstrap-select/js/locale/ajax-bootstrap-select.es-ES.min.js'); ?>

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

<?php $__env->startSection('JSOr'); ?>
$("#btnAgregar").click(function(e){
	$("#frmAgregar").trigger("submit");
});
$("#frmAgregar").submit(function(e){
	$.isLoading({ text: "Cargando..." }); NProgress.start();
	$('[id^="err"]').html("");
	$("#btnAgregar").html('<i class="fa fa-spinner fa-spin"></i> Cargando').prop("disabled", true);
	e.preventDefault();
	$("#btnAgregar").prop("disabled", true);
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingSrvAWSSESAgregar', array()); ?>",
		$("#frmAgregar").serialize(),
		function(data){
			$.isLoading("hide"); NProgress.done();
			$("#btnAgregar").html("Agregr").prop("disabled", false);
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.href = "<?php echo URL::route('SysWebEmailMarketingSrvAWSSES'); ?>"; }, 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"

	);
});
var options = {
	ajax : {
		url: "<?php echo URL::route("SysWebEmailMarketingSrvAWSSESClientesSelect"); ?>",
		type: "POST",
		dataType: "json",
		data: {
			q: "<?= "{{{q}}}" ?>"
		}
	},
	locale: {
		emptyTitle: "Seleccione un cliente, buscando el correo electrónico asociado a su cuenta..."
	},
	log: 3,
	preprocessData: function (data) {
		var i, l = data.length, array = [];
		if (l) {
			for (i = 0; i < l; i++) {
				array.push($.extend(true, data[i], {
					text: data[i].correo_electronico,
					value: data[i].id,
					data: {
						subtext: data[i].correo_electronico
					}
				}));
			}
		}
		return array;
	}
};
$("#clientes_id").selectpicker().filter(".with-ajax").ajaxSelectPicker(options);
$("#clientes_id").trigger("change");
<?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(); ?>