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

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

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

<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="icon-sc-landingpageicon"></i> Páginas de captura </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"> API Keys de Sume Clientes </h3> </div>
			<div class="porlets-content">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover" id="tblApiKey">
						<thead>
							<tr>
								<th style="width: 20%" class="all"> API Key </th>
								<th style="width: 15%" class="min-tablet-l"> Estado </th>
								<th class="min-tablet-l"> Sitio web </th>
								<th style="width: 10%" class="text-center min-tablet-l"> Acciones </th>
							</tr>
						</thead>
						<tbody>
							<?php $__empty_1 = true; foreach($APIKeys as $APIKey): $__empty_1 = false; ?>
							<tr>
								<td>
									<div class="input-group">
										<input type="text" class="form-control" readonly value="<?php echo $APIKey->api_key; ?>" id="Key<?php echo $APIKey->id; ?>"></input>
										<div class="input-group-btn">
											<button id="btnCopiar<?php echo $APIKey->id; ?>" class="btn btn-default btnCopiar" data-clipboard-target="#Key<?php echo $APIKey->id; ?>">
												<i class="fa fa-copy"></i>
											</button>
										</div>
									</div>
								</td>
								<td> <?php if($APIKey->estado == 1): ?> En uso <?php else: ?> Disponible <?php endif; ?> </td>
								<td> <?php echo $APIKey->sitio_web; ?> </td>
								<td class="text-center">
									<button type="button" onclick="Eliminar(<?php echo $APIKey->id; ?>)" class="btn btn-danger tooltips" data-toggle="tooltip" data-original-title="Eliminar"><i class="fa fa-trash-o"></i></button>
								</td>
							</tr>
							<?php endforeach; if ($__empty_1): ?>
							<tr class="danger"> <td colspan="4"> No existe ningúna API Key generada </td> </tr>
							<?php endif; ?>
						</tbody>
					</table>
				</div>
			</div>
			<?php if( DominioDeConfianza::where('clientes_id', '=', $cid)->count() < 3 ): ?>
			<div class="bottom">
				<?php echo Form::button('Generar', array('class' => 'btn btn-primary', 'id' => 'btnGenerar', 'type' => 'button')); ?>

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

<?php $__env->startSection('JS'); ?>
<?php echo HTML::script('ZeroClipBoard/ZeroClipboard.js'); ?>

<?php echo HTML::script('ClipboardJS/clipboard.min.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">
	ZeroClipboard.config( { swfPath: "<?php echo asset('ZeroClipBoard/ZeroClipboard.swf'); ?>" } );
	function Eliminar(id){
		var id = id;
		var mensaje = "<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmEliminar'> \
									<h2> ¿Seguro que desea eliminar? </h2> \
									<input type='hidden' name='idAPI' 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){
					$.isLoading({ text: "Cargando..." }); NProgress.start();
					$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebPAterrizajeAPIKeysEliminar'); ?>",
						{idAPI:id},
						function(data){
							$.isLoading("hide"); NProgress.done();
							$("#btnEnviar").prop("disabled", false).html("Eliminar");
							if(data.success){
								new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
								dialogItself.close();
								setTimeout( function(){ window.location.reload(); }, 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"
					);
				}
			}]
		});
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
$("#btnGenerar").click(function(){
	$.isLoading({ text: "Cargando..." }); NProgress.start();
	$("#btnGenerar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Generando');
	$.post(
		"<?php echo URL::route('SysWebPAterrizajeAPIKeysGenerar'); ?>",
		{cid: <?php echo $cid; ?>},
		function(data){
			$.isLoading("hide"); NProgress.done();
			$("#btnGenerar").prop("disabled", false).html("Generar");
			if(data.success){
				new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
				setTimeout( function(){ window.location.reload(); }, 3000 );
			}
			else{
				if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
			}
		},
		"json"
	);
});
var clipboard = new Clipboard(".btnCopiar");
clipboard.on("success", function(e) {
	$("#"+e.trigger.id).tooltip({trigger: "manual", title: "Copiado!"});
	$("#"+e.trigger.id).tooltip("show");
	$("#"+e.trigger.id).html('<i class="fa fa-check"></i>');
	setTimeout(function(){ $("#"+e.trigger.id).html('<i class="fa fa-copy"></i>'); $("#"+e.trigger.id).tooltip("destroy"); }, 1000);
}).on("error", function(e) {
	var msj = "";
	if(/iPhone|iPad/i.test(navigator.userAgent)) {
		msj = "El navegador web no soporta la función de copiado, debes hacerlo manualmente";
	}
	else if (/Mac/i.test(navigator.userAgent)) {
		msj = "Presiona ⌘-C para copiar";
	}
	else {
		msj = "Presiona Ctrl-C para copiar";
	}
	$("#"+e.trigger.id).tooltip({trigger: "manual", title: msj});
	$("#"+e.trigger.id).tooltip("show");
	setTimeout(function(){ $("#"+e.trigger.id).tooltip("destroy"); }, 5000);
});
$("#tblApiKey").DataTable({
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
	},
	autoWidth: false,
	responsive: true
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>