<?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; } }
	.mdAvatar .modal-footer {
		margin-top: 0px;
	}
	.mdAvatar .modal-dialog .modal-content .modal-header{ background-color: #363B3F; }
	.btnRadio4PX {
		border-radius: 4px;
	}
</style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<?php /* <h2><i class="fa fa-users"></i> Administración de cuentas </h2> */ ?>
		<h2><i class="fa fa-plus-circle"></i> Administración de proyectos </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>
<?php
	$cantidadCuentas = Cliente::where('cliente_padre', '=', $Cliente->id)->where('vinculado', '=', 1)->count();
	$ocultarBotonNC = ( (int)$cantidadCuentas < (int)$Cliente->cuentas )?'':'style="display: none;"';
	$mostrarAlertaNC = ( (int)$cantidadCuentas < (int)$Cliente->cuentas )?'style="display: none;"':'style="margin-bottom: 1px; margin-top: 10px;"';
?>
<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<?php /* <div class="header"> <h3 class="content-header"> Listado de cuentas </h3> </div> */ ?>
			<div class="header">
				<h3 class="content-header">
					Listado de proyectos 
					<a href="<?php echo URL::route('SysWebPerfilCuentasAgregar', array($Usuario->id)); ?>" class="btn btn-primary btnAgregarCuenta btnRadio4PX" id="btnAgregarCuenta" <?php echo $ocultarBotonNC; ?>>
						Agregar proyecto
					</a>
				</h3>
			</div>
			<div class="porlets-content">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover" id="tblCuentas">
						<thead>
							<tr>
								<th class=""> Empresa </th>
								<th class=""> Usuario principal </th>
								<th style="" class=""> Acciones </th>
							</tr>
						</thead>
						</table>
				</div>
			</div>
			<div class="bottom">
				<input type="hidden" name="cantidadCuentas" value="<?php echo $cantidadCuentas; ?>">
				<input type="hidden" name="cuentas" value="<?php echo $Cliente->cuentas; ?>">
				<?php /* <a href="<?php echo URL::route('SysWebPerfilCuentasAgregar', array($Usuario->id)); ?>" class="btn btn-primary" id="btnAgregarCuenta" <?php echo $ocultarBotonNC; ?>>
					Agregar cuenta
				</a> */ ?>
				<a href="<?php echo URL::route('SysWebPerfilCuentasAgregar', array($Usuario->id)); ?>" class="btn btn-primary btnAgregarCuenta" id="btnAgregarCuenta" <?php echo $ocultarBotonNC; ?>>
					Agregar proyecto
				</a>
			</div>
			<div class="alert alert-info" role="alert" <?php echo $mostrarAlertaNC; ?>>
				Puedes solicitar más proyectos por medio del chat de soporte para que te brinden el precio actual actual por proyecto adicional.
			</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 Eliminar(id){
		var id = id;
		var mensaje = '<div class="row"> \
			<div class="col-xs-12"> \
				<form id="frmEliminar"> \
					<h2> ¿Seguro que desea desvincular el proyecto? </h2> \
					<!-- <p> Si desvinculas esta cuenta de tu cuenta principal se mantendrá con los datos como la dejes y podrás vincularla nuevamente en un futuro si lo deseas... pero mientras esté desvinculada todo lo que está dentro de ella dejará de funcionar, páginas de captura, secuencias de seguimiento, campañas, etc. y el usuario no podrá acceder más a esa cuenta porqué quedará inactiva </p> --> \
					<p> Si desvinculas este proyecto de tu cuenta principal se mantendrá con los datos como la dejes y podrás vincularla nuevamente en un futuro si lo deseas y tienes proyectos disponibles... pero mientras esté desvinculada todo lo que está dentro de ella dejará de funcionar, páginas de captura, secuencias de seguimiento, campañas, etc. y el usuario no podrá acceder más a esa cuenta porqué quedará inactiva </p> \
					<input type="hidden" name="idC" value="'+id+'"> \
				</form> \
			</div> \
		</div>';
		BootstrapDialog.show({
			title: "Desvincular de tu cuenta",
			type: BootstrapDialog.TYPE_DANGER,
			message: mensaje,
			draggable: true,
			cssClass: "ModalEliminar mdAvatar",
			closeByBackdrop: false,
			onshown: function(dialogItself){
				$("body").addClass("modal-open");
			},
			buttons: [{
				id: "btnEliminar",
				label: "Desvincular",
				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('SysWebPerfilCuentasEliminar', array($Usuario->id)); ?>",
						{idC: id},
						function(data){
							$.isLoading("hide"); NProgress.done();
							$("#btnEliminar").prop("disabled", false).html("Eliminar");
							if(data.success){
								location.reload();
								var table = $("#tblCuentas").DataTable();
								table.ajax.reload(null, false);
								if( parseInt(data.cantidadCuentas) < parseInt(<?php echo $Cliente->cuentas; ?>) ){
									$(".btnAgregarCuenta").show();
								}
								else{
									$(".btnAgregarCuenta").hide();
								}
								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");
			}
		});
	}
	function EliminarProyecto(id){
		var id = id;
		var mensaje = '<div class="row"> \
			<div class="col-xs-12"> \
				<form id="frmEliminar"> \
					<h2> ¿Seguro que desea eliminar el proyecto de tu cuenta? </h2> \
					<p> Si eliminas el proyecto, <b class="text-danger">se perderá toda la información</b> asociada a este, de tal forma que si tu cliente solo está pausando su proyecto recomendamos que lo mantengas desvinculado </p> \
					<input type="hidden" name="idC" value="'+id+'"> \
				</form> \
			</div> \
			<div class="radio-inline"> \
				<label> \
					<input type="checkbox" value="0" id="rdAcuerdo" name="rdAcuerdo"> \
					<span class="custom-checkbox"></span> Estoy de acuerdo con lo mencionado anteriormente \
				</label> \
			</div> \
			<div class="col-xs-12"> \
				<div class="alert alert-danger" role="alert" <?php echo $mostrarAlertaNC; ?>> \
					El descuento de este proyecto en el costo de tu membreseria se verá reflejado hasta tu proxima mensualidad, luego de eliminado puedes confirmar por medio del chat de soporte si ya se aplico dicho descuento en tu proxima mensualidad. \
				</div> \
			</div> \
		</div>';
		BootstrapDialog.show({
			title: "Eliminar proyecto de tu cuenta",
			type: BootstrapDialog.TYPE_DANGER,
			message: mensaje,
			draggable: true,
			cssClass: "ModalEliminar mdAvatar",
			closeByBackdrop: false,
			onshow: function(dialog) {
				var ventana = dialog.getModalBody();
				$("body").addClass("modal-open");
				dialog.getButton("btnEliminarProyecto").disable();
				ventana.find("#rdAcuerdo").click(function(e){
					if(ventana.find("#rdAcuerdo").prop("checked")){
						dialog.getButton("btnEliminarProyecto").enable();
					}
					else{
						dialog.getButton("btnEliminarProyecto").disable();
					}
				});
			},
			buttons: [{
				id: "btnEliminarProyecto",
				label: "Eliminar",
				cssClass: "btn btn-danger btn-block btn-lg",
				action: function(dialogItself){
					$.isLoading({ text: "Cargando..." }); NProgress.start();
					$("#btnEliminarProyecto").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebPerfilCuentasEliminarProyecto', array($Usuario->id)); ?>",
						{idC: id},
						function(data){
							$.isLoading("hide"); NProgress.done();
							$("#btnEliminarProyecto").prop("disabled", false).html("Eliminar");
							if(data.success){
								var table = $("#tblCuentas").DataTable();
								new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
								setTimeout(function(){ table.ajax.reload(null, false);  location.reload();}, 2000);
								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");
			}
		});
	}
	function Vincular(id){
		var id = id;
		var mensaje = '<div class="row"> \
			<div class="col-xs-12"> \
				<form id="frmEliminar"> \
					<h2> ¿Seguro que desea volver a vincular el proyecto? </h2> \
					<!-- <p> Si la vinculas nuevamente, la cuenta se activará automáticamente y todo seguirá funcionando como lo dejaste al momento de desvincularla de tu cuenta (Páginas de captura, secuencias de seguimiento, campañas, prospectos, etc...) </p> --> \
					<p> Si lo vinculas nuevamente, el proyecto se activará automáticamente y todo seguirá funcionando como lo dejaste al momento de desvincularla de tu cuenta (Páginas de captura, secuencias de seguimiento, campañas, prospectos, etc...) </p> \
					<input type="hidden" name="idC" value="'+id+'"> \
				</form> \
			</div> \
		</div>';
		BootstrapDialog.show({
			title: "Vincular a tu cuenta",
			type: BootstrapDialog.TYPE_SUCCESS,
			message: mensaje,
			draggable: true,
			cssClass: "ModalEliminar mdAvatar",
			closeByBackdrop: false,
			onshown: function(dialogItself){
				$("body").addClass("modal-open");
			},
			buttons: [{
				id: "btnVincular",
				label: "Vincular",
				cssClass: "btn-success btn-block btn-lg",
				action: function(dialogItself){
					$.isLoading({ text: "Cargando..." }); NProgress.start();
					$("#btnVincular").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebPerfilCuentasVincular', array($Usuario->id)); ?>",
						{idC: id},
						function(data){
							$.isLoading("hide"); NProgress.done();
							$("#btnVincular").prop("disabled", false).html("Eliminar");
							if(data.success){
								location.reload();
								var table = $("#tblCuentas").DataTable();
								table.ajax.reload(null, false);
								if( parseInt(data.cantidadCuentas) < parseInt(<?php echo $Cliente->cuentas; ?>) ){
									$(".btnAgregarCuenta").show();
								}
								else{
									$(".btnAgregarCuenta").hide();
								}
								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");
			}
		});
	}
	function IniciarSesion(id){
		var idC = id;
		$.post(
			"<?php echo URL::route('SysWebCambiarSesion'); ?>",
			{idC:id, tipo:"user"},
			function(data){
				if(data.success){
					new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
					setTimeout(function(){ window.location.href = "<?php echo URL::route('SysWebIndex'); ?>" }, 1000);
				}
				else{
					if(data.mensaje != ""){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
				}
			},
			"json"
		);
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
$("a[data-toggle=\"tab\"]").on("shown.bs.tab", function (e) { $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust(); });
$("#tblCuentas").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebPerfilCuentas', array($Usuario->id)); ?>",
	columns: [
		{data: "empresa", name: "empresa"},
		{data: "username", name: "username"},
		{data: "acciones", name: "acciones", "searchable": false, "orderable": false, "class": "text-center"}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
	},
	autoWidth: false,
	responsive: true
});
<?php if(Session::has('EliminarMensajeS')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('EliminarMensajeS'); ?>", type: "success" });
<?php endif; ?>
<?php if(Session::has('EliminarMensajeE')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('EliminarMensajeE'); ?>", type: "error" });
<?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>