<?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('DataTables/select.dataTables.min.css'); ?>

<?php echo HTML::style('DataTables/buttons.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; } }
</style>
<style type="text/css" class="init">
	table.dataTable.stripe tbody > tr.odd.selected, table.dataTable.stripe tbody > tr.odd > .selected, table.dataTable.display tbody > tr.odd.selected, table.dataTable.display tbody > tr.odd > .selected {
		background-color: #E9E9E9;
	}
	table.dataTable tbody > tr.selected, table.dataTable tbody > tr > .selected {
		background-color: #E9E9E9;
	}
	table.dataTable.display tbody > tr.odd.selected > .sorting_1, table.dataTable.order-column.stripe tbody > tr.odd.selected > .sorting_1 {
		background-color: #E9E9E9;
	}
	table.dataTable.order-column tbody > tr.selected > .sorting_1, table.dataTable.order-column tbody > tr.selected > .sorting_2, table.dataTable.order-column tbody > tr.selected > .sorting_3, table.dataTable.order-column tbody > tr > .selected, table.dataTable.display tbody > tr.selected > .sorting_1, table.dataTable.display tbody > tr.selected > .sorting_2, table.dataTable.display tbody > tr.selected > .sorting_3, table.dataTable.display tbody > tr > .selected {
		background-color: #E9E9E9;
	}
	table.dataTable.display tbody > tr.even.selected > .sorting_1, table.dataTable.order-column.stripe tbody > tr.even.selected > .sorting_1 {
		background-color: #E9E9E9;
	}
	table.dataTable.display tbody > tr.selected:hover, table.dataTable.display tbody > tr > .selected:hover {
		background-color: #E9E9E9;
	}
	table.dataTable.display tbody > tr.selected:hover > .sorting_1, table.dataTable.order-column.hover tbody > tr.selected:hover > .sorting_1 {
		background-color: #E9E9E9;
	}
	.table-hover > tbody > tr:hover > td, .table-hover > tbody > tr:hover > th {
		background-color: #E9E9E9;
	}
	<?php
		if( !isset($_GET['import']) ){
	?>
	.oculto {
		display: none !important;
	}
	<?php
		}
	?>
</style>
<?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">
		<div class="block-web">
			<div class="header"> <h3 class="content-header"> Listado de páginas de captura creadas </h3> </div>
			<div class="porlets-content">
				<div class="table-responsive">
					<table class="table table-striped-old table-bordered table-hover display" id="tblPaginasxCliente" cellspacing="0" width="100%">
						<thead>
							<tr>
								<th></th>
								<th class="all" data-priority="1"> Nombre </th>
								<th class="min-tablet-l" data-priority="2" style="width: 35%;"> Acciones </th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div class="bottom">
				<?php echo HTML::linkRoute('SysWebPAterrizajePlantillaxClienteCrear', 'Agregar', array(), array('class' => 'btn btn-primary btnAgregar')); ?>

				<button type="button" style="display: none;" class="btn btn-danger" id="btnEliminarSeleccionados"> Eliminar seleccionados </button>
				<?php
					if( isset($_GET['import']) ){
				?>
				<button type="button" class="btn btn-info" id="btnImportarP" onclick="Importar()"> Importar Plantilla </button>
				<?php
					}
				?>
			</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'); ?>

<?php echo HTML::script('DataTables/dataTables.select.min.js'); ?>

<?php echo HTML::script('DataTables/dataTables.buttons.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 eliminar? </h2> \
									<input type='hidden' name='idP' 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();
					$.isLoading("hide"); NProgress.done();
					$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebPAterrizajePlantillaxClienteBorrar'); ?>",
						{idP:id},
						function(data){
							$("#btnEnviar").prop("disabled", false).html("Eliminar");
							if(data.success){
								new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
								dialogItself.close();
								var table = $("#tblPaginasxCliente").DataTable();
								table.ajax.reload(null, 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(""); } });
							}
						},
						"json"
					);
				}
			}]
		});
	}
	function Clonar(id){
		var id = id;
		$.isLoading({ text: "Cargando..." }); NProgress.start();
		var ruta = "<?php echo URL::route('SysWebPAterrizajePlantillaxClienteClonar', array('')); ?>";
		ruta = ruta+'/'+id;
		$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
		$.post(
			ruta,
			{idP: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" });
					var table = $("#tblPaginasxCliente").DataTable();
					table.ajax.reload(null, 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(""); } });
				}
			},
			"json"
		);
	}
	function Descargar(id){
		var id = id;
		var ruta = "<?php echo URL::route('SysWebPAterrizajePlantillaxClienteDescargar', array('')); ?>";
		ruta = ruta+'/'+id;
		//$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
		$.get(
			ruta,
			/*{idP:id},*/
			function(data){
				//$("#btnEnviar").prop("disabled", false).html("Eliminar");
				if(data.success){
					/*new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });*/
					//var table = $("#tblPaginasxCliente").DataTable();
					//table.ajax.reload(null, 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(""); } });
				}
			},
			"json"
		);
	}
	<?php
		if( isset($_GET['import']) ){
	?>
	function Importar(){
		var id = id;
		var mensaje = "<div class='row'> \
			<div class='col-xs-12'> \
				<form id='frmImportarPlantilla' enctype='multipart/form-data'> \
					<div class='form-group'> \
						<label for='txtNombre'>Nombre a asignar</label> \
						<input type='text' class='form-control' id='txtNombre' name='txtNombre' placeholder='Nombre a asignar...'> \
						<span class='text-danger' id='errtxtNombre'></span> \
					</div> \
					<div class='form-group'> \
						<label for='flArchivo'>Archivo HTML</label> \
						<input type='file' id='flArchivo' name='flArchivo'> \
						<span class='text-danger' id='errflArchivo'></span> \
					</div> \
				</form> \
			</div> \
		</div>";
		BootstrapDialog.show({
			title: "Importar Plantilla de archivo HTML",
			type: BootstrapDialog.TYPE_DEFAULT,
			message: mensaje,
			draggable: true,
			cssClass: "ModalImportarPlantilla",
			buttons: [{
				id: "btnImportarPlantilla",
				label: "Importar",
				cssClass: "btn-default",
				action: function(dialogItself){
					$.isLoading({ text: "Cargando..." }); NProgress.start();
					$.isLoading("hide"); NProgress.done();
					$("#btnImportarPlantilla").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Importando...');
					var formulario = $("#frmImportarPlantilla");
					var formData = new FormData(document.getElementById("frmImportarPlantilla"));
					$.ajax({
						type: "POST",
						url: "<?php echo URL::route('SysWebPAterrizajePlantillaxClienteCargarPlantilla', array()); ?>",
						data: formData,
						cache: false,
						contentType: false,
						processData: false,
						dataType: "json",
						timeout: 1800000,
						success: function(data){
							$("#btnImportarPlantilla").prop("disabled", false).html("Importar");
							if(data.success){
								new PNotify({ title: "Realizado", text: data.mensaje, type: "success" });
								var table = $("#tblPaginasxCliente").DataTable();
								table.ajax.reload(null, false);
								dialogItself.close();
							}
							else{
								if(typeof data.MensajeError != "undefined"){ $("#Errs").html(data.MensajeError); $("#MensajeError").show(); }else{ $("#MensajeError").hide(); $("#Errs").html(""); }
								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(""); } });
							}
						},
						error: function(jqXHR, textStatus, errorThrown){
							$("#btnImportarPlantilla").prop("disabled", false).html("Importar");
							new PNotify({ title: "Error", text: textStatus + " " + errorThrown, type: "error" });
						}
					});
				}
			}]
		});
	}
	<?php
		}
	?>
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
<?php if(Session::has('message')): ?>
new PNotify({ title: "¡Felicidades!", text: "<?php echo Session::get('message'); ?>", type: "success" });
<?php endif; ?>
var tabla = $("#tblPaginasxCliente").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebPAterrizajePlantillaxCliente'); ?>",
	columns: [
		{data: null, defaultContent: "", "searchable": false, "orderable": false},
		{data: "nombre", name: "nombre"},
		{data: "acciones", name: "acciones", "searchable": false, "orderable": false, "class": "text-center", 
		"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			$(nTd).find(".btn-danger").css("margin-bottom", "3px");
		}
	}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>",
		select: {
			rows: {
				_: "Tienes seleccionada %d filas",
				0: "De clic sobre la fila para seleccionarla",
				1: "Solo tiene 1 fila seleccionada"
			}
		}
	},
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
		$(".table-responsive").find("[title]").tooltip();
		if(oSettings._iRecordsTotal == 0){
			$(".btnAgregar").webuiPopover({
				trigger: "manual",
				title: "Instrucciones de Plataforma Sume Clientes",
				content: '<div class="alert alert-info" role="alert"> \
					<p style="font-size: 16;">Aún no tienes ningúna página creada, empieza a crear tus páginas haciendo clic en el botón de agregar</p> \
				<div>',
				closeable: true,
				backdrop: true,
				style: "",
				width: 500,
				multi: true
			});
			$(".btnAgregar").webuiPopover("show");
		}
	},
	autoWidth: false,
	responsive: {
		"details": {
			"type": "column",
			"target": 0
		}
	},
	columnDefs: [{
		"data": null,
		"defaultContent": "",
		"className": "control",
		"orderable": false,
		"width": "9%",
		"targets": 0
	}],
	select: {
		style: "multi",
		selector: "td:not(.control)"
	},
	dom: "Blfrtip",
	buttons: [
		{
			text: "<i class='fa fa-check-square-o' data-toggle='tooltip' data-original-title='Seleccionar todos los elementos'> </i>",
			action: function(){
				tabla.rows().select();
			},
			titleAttr: "Seleccionar todos los elementos"
		},
		{
			text: "<i class='fa fa-square-o' data-toggle='tooltip' data-original-title='Deseleccionar'> </i>",
			action: function(){
				tabla.rows().deselect();
			},
			titleAttr: "Deseleccionar todos los elementos seleccionados"
		}
	],
	order: [[ 1, "asc" ]]
}).on("select", function (e, dt, type, indexes){
	var seleccionados = tabla.rows({ selected: true }).count();
	if( seleccionados > 0 ){
		$("#btnEliminarSeleccionados").show();
	}
	else{
		$("#btnEliminarSeleccionados").hide();
	}
}).on("deselect", function(e, dt, type, indexes){
	var seleccionados = tabla.rows({ selected: true }).count();
	if( seleccionados > 0 ){
		$("#btnEliminarSeleccionados").show();
	}
	else{
		$("#btnEliminarSeleccionados").hide();
	}
});
$("#btnEliminarSeleccionados").click(function(e){
	var mensaje = "<div class='row'> \
						<div class='col-xs-12'> \
							<form id='frmEliminar'> \
								<h2> ¿Seguro que desea eliminar los registros seleccionados? </h2> \
							</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();
				var ids = new Array();
				$("#tblPaginasxCliente").find(".selected").each(function(e){ ids.push($(this).find(".hdnid").val()); });
				$("#btnEliminarSeleccionados").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando...');
				$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando...');
				$.post(
					"<?php echo URL::route('SysWebPAterrizajePlantillaxClienteBorrar'); ?>",
					{idP:ids},
					function(data){
						$.isLoading("hide"); NProgress.done();
						$("#btnEliminarSeleccionados").prop("disabled", false).html("Eliminar seleccionados").hide();
						$("#btnEliminar").prop("disabled", false).html("Eliminar");
						if(data.success){
							new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
							dialogItself.close();
							var table = $("#tblPaginasxCliente").DataTable();
							table.ajax.reload(null, 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(""); } });
						}
					},
					"json"
				);
			}
		}]
	});
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>