Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0207197fb | |||
| 5113b960d2 | |||
| 8453735727 | |||
| fdd1ba8272 |
+5
-3
@@ -10,12 +10,11 @@
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<link rel="stylesheet" href="css/buscadorSala.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<header id="cabecera-container"></header>
|
||||
<?php include_once("cabecera.php"); ?>
|
||||
|
||||
<main class="container py-4">
|
||||
|
||||
@@ -100,8 +99,11 @@
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
<script src="js/sala.js"></script>
|
||||
<script src="js/buscadorSala.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,96 +0,0 @@
|
||||
<!-- cabecera.html -->
|
||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<img src="img/favicon/favicon.svg" alt="TRIVIAGMÁTICO" class="me-2" style="height: 35px;">
|
||||
TRIVIAGMÁTICO
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
||||
|
||||
<!-- Contenedor dinámico de usuario/botones -->
|
||||
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera"></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- MODAL DE LOGIN -->
|
||||
<div class="modal fade" id="modalLogin" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="loginModalLabel">
|
||||
<i class="fa-solid fa-right-to-bracket text-primary me-2"></i>Iniciar sesión
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formLogin">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="loginEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="loginEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="loginPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="recordar" name="recordar" type="checkbox" />
|
||||
<label for="recordar" class="small">Recuérdeme durante 10 días</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="validar">
|
||||
</form>
|
||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-primary rounded-pill px-4" id="botonAceptarLogin">Entrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL DE REGISTRO -->
|
||||
<div class="modal fade" id="modalRegistro" tabindex="-1" aria-labelledby="registroModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="registroModalLabel">
|
||||
<i class="fa-solid fa-user-plus text-success me-2"></i>Registrarse
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formRegistro">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control border-dark" id="regNombre" name="nombreUsuario" placeholder="Nombre" required>
|
||||
<label for="regNombre">Nombre</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="regEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="regEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="regPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="registrar">
|
||||
</form>
|
||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro">Registrarse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<img src="img/favicon/favicon.svg" alt="TRIVIAGMÁTICO" class="me-2" style="height: 35px;">
|
||||
TRIVIAGMÁTICO
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
||||
|
||||
<!-- Contenedor dinámico de usuario/botones -->
|
||||
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- MODAL DE LOGIN -->
|
||||
<div class="modal fade" id="modalLogin" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="loginModalLabel">
|
||||
<i class="fa-solid fa-right-to-bracket text-primary me-2"></i>Iniciar sesión
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formLogin">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="loginEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="loginEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="loginPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="recordar" name="recordar" type="checkbox" />
|
||||
<label for="recordar" class="small">Recuérdeme durante 10 días</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="validar">
|
||||
</form>
|
||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-primary rounded-pill px-4" id="botonAceptarLogin">Entrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL DE REGISTRO -->
|
||||
<div class="modal fade" id="modalRegistro" tabindex="-1" aria-labelledby="registroModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="registroModalLabel">
|
||||
<i class="fa-solid fa-user-plus text-success me-2"></i>Registrarse
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formRegistro">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control border-dark" id="regNombre" name="nombreUsuario" placeholder="Nombre" required>
|
||||
<label for="regNombre">Nombre</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="regEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="regEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="regPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="registrar">
|
||||
</form>
|
||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro">Registrarse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/cabecera.js"></script>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -6,20 +6,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Triviagmático</title>
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<header id="cabecera-container"></header>
|
||||
<?php include 'cabecera.php'; ?>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center align-items-center g-4">
|
||||
@@ -55,7 +46,6 @@
|
||||
<!-- JS de Bootstrap -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+353
-279
@@ -1,435 +1,509 @@
|
||||
let usuarioYaEstaEnEquipo = false;
|
||||
let intervaloBuscadorSalas = null;
|
||||
let cargandoSalas = false;
|
||||
|
||||
$(document).ready(function () {
|
||||
comprobarSalaUsuario();
|
||||
});
|
||||
|
||||
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
||||
function comprobarSalaUsuario() {
|
||||
$("#cargandoSalas").remove();
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "obtenerSalaUsuario" },
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error || !respuesta.asociado) {
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
$("#contenedorCrearSala").show();
|
||||
cargarSalas();
|
||||
} else {
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
$("#contenedorCrearSala").hide(); // Ocultar "Crear Sala" si ya pertenece a una
|
||||
cargarSalaUsuario(respuesta.idPartida);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al comprobar la sala del usuario:", error);
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
cargarSalas();
|
||||
},
|
||||
});
|
||||
function iniciarActualizacionSalas() {
|
||||
if (intervaloBuscadorSalas) {
|
||||
clearInterval(intervaloBuscadorSalas);
|
||||
}
|
||||
|
||||
// 2. Cargar únicamente la sala en la que está metido el usuario
|
||||
function cargarSalaUsuario(idPartida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "buscar", idPartida: idPartida },
|
||||
success: function (partida) {
|
||||
if (partida.error) {
|
||||
console.error(partida.error);
|
||||
cargarSalas();
|
||||
|
||||
intervaloBuscadorSalas = setInterval(function () {
|
||||
if (!usuarioYaEstaEnEquipo) {
|
||||
cargarSalas();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function cargarSalas() {
|
||||
if (cargandoSalas) {
|
||||
return;
|
||||
}
|
||||
$("#contenedorSalas").empty();
|
||||
cargarInformacionSala(partida);
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener la sala del usuario:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Cargar la lista completa de todas las salas
|
||||
function cargarSalas() {
|
||||
cargandoSalas = true;
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "listar" },
|
||||
data: {
|
||||
orden: "listar",
|
||||
},
|
||||
|
||||
success: function (partidas) {
|
||||
const contenedor = $("#contenedorSalas");
|
||||
contenedor.empty();
|
||||
|
||||
if (!Array.isArray(partidas) || partidas.length === 0) {
|
||||
contenedor.html(`
|
||||
<div class="col-12 text-center">
|
||||
<p class="text-muted">No hay salas disponibles actualmente.</p>
|
||||
$(".sala-item").remove();
|
||||
|
||||
if ($("#mensajeSinSalas").length === 0) {
|
||||
contenedor.append(`
|
||||
<div
|
||||
id="mensajeSinSalas"
|
||||
class="col-12 text-center">
|
||||
|
||||
<p class="text-muted">
|
||||
No hay salas disponibles actualmente.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$("#mensajeSinSalas").remove();
|
||||
|
||||
const idsPartidas = partidas.map(function (partida) {
|
||||
return String(partida.idPartida);
|
||||
});
|
||||
|
||||
$(".sala-item").each(function () {
|
||||
const idPartida = String($(this).data("id-partida"));
|
||||
|
||||
if (!idsPartidas.includes(idPartida)) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
|
||||
partidas.forEach(function (partida) {
|
||||
cargarInformacionSala(partida);
|
||||
cargarSalaBuscador(partida);
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener las partidas:", error);
|
||||
console.error(
|
||||
"Error al obtener las partidas:",
|
||||
error
|
||||
);
|
||||
},
|
||||
|
||||
complete: function () {
|
||||
cargandoSalas = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Obtener equipos y jugadores asociados a una sala concreta
|
||||
function cargarInformacionSala(partida) {
|
||||
function cargarSalaBuscador(partida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "getEquipos", idPartida: partida.idPartida },
|
||||
data: {
|
||||
orden: "getEquipos",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (equipos) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "getJugadores", idPartida: partida.idPartida },
|
||||
success: function (jugadores) {
|
||||
mostrarSala(partida, equipos, jugadores);
|
||||
data: {
|
||||
orden: "getJugadores",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (jugadores) {
|
||||
if (
|
||||
!Array.isArray(jugadores) ||
|
||||
jugadores.length === 0
|
||||
) {
|
||||
$(
|
||||
`.sala-item[data-id-partida="${partida.idPartida}"]`
|
||||
).remove();
|
||||
|
||||
comprobarSiNoHaySalas();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
actualizarSalaBuscador(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener jugadores:", error);
|
||||
console.error(
|
||||
"Error al obtener jugadores:",
|
||||
error
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener equipos:", error);
|
||||
console.error(
|
||||
"Error al obtener equipos:",
|
||||
error
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 5. Renderizar el HTML de la sala y botones según estado
|
||||
function mostrarSala(partida, equipos, jugadores) {
|
||||
const contenedor = $("#contenedorSalas");
|
||||
function comprobarSiNoHaySalas() {
|
||||
if ($(".sala-item").length === 0) {
|
||||
if ($("#mensajeSinSalas").length === 0) {
|
||||
$("#contenedorSalas").append(`
|
||||
<div
|
||||
id="mensajeSinSalas"
|
||||
class="col-12 text-center">
|
||||
|
||||
<p class="text-muted">
|
||||
No hay salas disponibles actualmente.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function actualizarSalaBuscador(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
) {
|
||||
$("#mensajeSinSalas").remove();
|
||||
|
||||
const selectorSala =
|
||||
`.sala-item[data-id-partida="${partida.idPartida}"]`;
|
||||
|
||||
const salaExistente = $(selectorSala);
|
||||
|
||||
if (salaExistente.length === 0) {
|
||||
crearSalaBuscador(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const equiposHTML =
|
||||
generarEquiposHTML(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
);
|
||||
|
||||
salaExistente
|
||||
.find(".equipos")
|
||||
.html(equiposHTML);
|
||||
}
|
||||
|
||||
function crearSalaBuscador(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
) {
|
||||
$("#mensajeSinSalas").remove();
|
||||
|
||||
const equiposHTML =
|
||||
generarEquiposHTML(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
);
|
||||
|
||||
const salaHTML = `
|
||||
<div
|
||||
class="col-12 col-md-10 col-lg-8 sala-item"
|
||||
data-id-partida="${partida.idPartida}">
|
||||
|
||||
<div class="sala card p-3 shadow-sm mb-4">
|
||||
|
||||
<div
|
||||
class="sala-header h4 text-center mb-3 text-white">
|
||||
|
||||
${escapeHTML(partida.nombrePartida)}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="sala-body">
|
||||
|
||||
<div class="equipos d-flex justify-content-around">
|
||||
|
||||
${equiposHTML}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`;
|
||||
|
||||
$("#contenedorSalas").append(salaHTML);
|
||||
}
|
||||
|
||||
function generarEquiposHTML(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
) {
|
||||
let equiposHTML = "";
|
||||
|
||||
equipos.forEach(function (equipo) {
|
||||
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
const jugadoresEquipo =
|
||||
jugadores.filter(function (jugador) {
|
||||
return (
|
||||
jugador.idEquipo ==
|
||||
equipo.idEquipo
|
||||
);
|
||||
});
|
||||
|
||||
let jugadoresHTML = "";
|
||||
|
||||
if (jugadoresEquipo.length > 0) {
|
||||
jugadoresEquipo.forEach(function (jugador) {
|
||||
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||
const esHost =
|
||||
jugador.idUsuario ==
|
||||
partida.idUsuario;
|
||||
|
||||
jugadoresHTML += `
|
||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||
esHost ? "jugador-host" : ""
|
||||
}">
|
||||
<div
|
||||
class="jugador border border-2 d-flex align-items-center justify-content-between">
|
||||
|
||||
<div>
|
||||
<span class="avatar">${esHost ? '<i class="bi bi-award-fill"></i>' : '<i class="bi bi-person-fill"></i>'}</span>
|
||||
${escapeHTML(jugador.nombreUsuario)}
|
||||
|
||||
<span class="avatar">
|
||||
|
||||
${
|
||||
esHost
|
||||
? '<i class="bi bi-award-fill"></i>'
|
||||
: '<i class="bi bi-person-fill"></i>'
|
||||
}
|
||||
|
||||
</span>
|
||||
|
||||
${escapeHTML(
|
||||
jugador.nombreUsuario
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
${
|
||||
esHost
|
||||
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
||||
? `
|
||||
<span
|
||||
class="badge bg-warning text-dark ms-2">
|
||||
|
||||
HOST
|
||||
|
||||
</span>
|
||||
`
|
||||
: ""
|
||||
}
|
||||
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else {
|
||||
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
||||
jugadoresHTML = `
|
||||
<div class="text-muted small">
|
||||
Sin jugadores
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Botón "Unirse" solo visible si NO pertenece a ningún equipo
|
||||
let botonUnirseHTML = "";
|
||||
|
||||
if (!usuarioYaEstaEnEquipo) {
|
||||
botonUnirseHTML = `
|
||||
<button type="button" class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||
<button
|
||||
type="button"
|
||||
class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||
data-id-partida="${partida.idPartida}"
|
||||
data-id-equipo="${equipo.idEquipo}">
|
||||
|
||||
Unirse
|
||||
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
equiposHTML += `
|
||||
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||
<h6>${escapeHTML(equipo.nombreEquipo)}</h6>
|
||||
<div
|
||||
class="equipo me-2 ms-2 p-3 border rounded">
|
||||
|
||||
<h6>
|
||||
${escapeHTML(
|
||||
equipo.nombreEquipo
|
||||
)}
|
||||
</h6>
|
||||
|
||||
<div class="jugadores mb-2">
|
||||
|
||||
${jugadoresHTML}
|
||||
|
||||
</div>
|
||||
|
||||
${botonUnirseHTML}
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||
let accionesSalaHTML = "";
|
||||
|
||||
if (usuarioYaEstaEnEquipo) {
|
||||
const esHost = partida.idUsuario == idUsuarioSesion;
|
||||
let botonIniciarHTML = "";
|
||||
|
||||
// Solo el host puede iniciar la partida
|
||||
if (esHost) {
|
||||
botonIniciarHTML = `
|
||||
<a href="juego.php?idPartida=${partida.idPartida}"
|
||||
class="btn btn-success btn-lg px-4">
|
||||
<i class="bi bi-controller"></i> ¡Iniciar Partida!
|
||||
</a>
|
||||
`;
|
||||
}
|
||||
|
||||
accionesSalaHTML = `
|
||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||
|
||||
<button type="button"
|
||||
class="btn btn-outline-danger btn-abandonar-sala"
|
||||
data-id-partida="${partida.idPartida}"
|
||||
data-es-host="${esHost}">
|
||||
Abandonar sala
|
||||
</button>
|
||||
|
||||
${botonIniciarHTML}
|
||||
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
const salaHTML = `
|
||||
<div class="col-12 col-md-10 col-lg-8">
|
||||
<div class="sala card p-3 shadow-sm mb-4">
|
||||
<div class="sala-header h4 text-center mb-3 text-white">
|
||||
${escapeHTML(partida.nombrePartida)}
|
||||
</div>
|
||||
<div class="sala-body">
|
||||
<div class="equipos d-flex justify-content-around">
|
||||
${equiposHTML}
|
||||
</div>
|
||||
${accionesSalaHTML}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
contenedor.append(salaHTML);
|
||||
}
|
||||
|
||||
// 6. Evento: Unirse a un Equipo
|
||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||
const boton = $(this);
|
||||
const idEquipo = boton.data("id-equipo");
|
||||
const idPartida = boton.data("id-partida");
|
||||
|
||||
boton.prop("disabled", true).text("Uniéndose...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
orden: "registrarUsuarioEnEquipo",
|
||||
idEquipo: idEquipo,
|
||||
},
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
return;
|
||||
}
|
||||
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
$("#contenedorCrearSala").hide();
|
||||
$("#contenedorSalas").empty();
|
||||
cargarSalaUsuario(idPartida);
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al unirse al equipo:", error);
|
||||
alert("No se ha podido unir al equipo.");
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// 7. Evento: Abandonar Sala
|
||||
// Guardamos temporalmente el botón presionado
|
||||
let botonAbandonarReferencia = null;
|
||||
|
||||
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||
botonAbandonarReferencia = $(this);
|
||||
|
||||
const esHost = $(this).data("es-host") === true || $(this).data("es-host") === "true";
|
||||
const titulo = $("#modalAbandonarSalaLabel");
|
||||
const mensaje = $("#modalAbandonarSalaMensaje");
|
||||
const botonConfirmar = $("#btnConfirmarAbandonar");
|
||||
|
||||
if (esHost) {
|
||||
titulo.text("¿Abandonar la sala?");
|
||||
mensaje.text(
|
||||
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
||||
);
|
||||
botonConfirmar.text("Sí, terminar partida");
|
||||
} else {
|
||||
titulo.text("¿Abandonar la sala?");
|
||||
mensaje.text(
|
||||
"Si sales de la sala, perderás tu lugar en el equipo.",
|
||||
);
|
||||
botonConfirmar.text("Sí, salir");
|
||||
return equiposHTML;
|
||||
}
|
||||
|
||||
const modal = new bootstrap.Modal(
|
||||
document.getElementById("modalAbandonarSala"),
|
||||
);
|
||||
|
||||
modal.show();
|
||||
});
|
||||
|
||||
|
||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
const modalEl = document.getElementById("modalAbandonarSala");
|
||||
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||
|
||||
const btnConfirmar = $(this);
|
||||
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { orden: "salirDeSala" },
|
||||
success: function (respuesta) {
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Restablecemos la interfaz a la lista completa de salas
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
$("#contenedorCrearSala").show();
|
||||
cargarSalas();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al salir de la sala:", error);
|
||||
alert("No se pudo salir de la sala.");
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
// 8. Evento: Crear Sala
|
||||
$("#btnCrearSala").on("click", function () {
|
||||
const nombreSala = $("#nombreSala").val().trim();
|
||||
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
||||
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
||||
const nombreSala =
|
||||
$("#nombreSala").val().trim();
|
||||
|
||||
const nombreEquipo1 =
|
||||
$("#nombreEquipo1").val().trim();
|
||||
|
||||
const nombreEquipo2 =
|
||||
$("#nombreEquipo2").val().trim();
|
||||
|
||||
let valido = true;
|
||||
$(".mensaje-error-sala").remove();
|
||||
$(".input-kahoot").removeClass("is-invalid");
|
||||
|
||||
if (nombreSala === "" || nombreSala.length < 3) {
|
||||
$(".mensaje-error-sala").remove();
|
||||
|
||||
$(".input-kahoot")
|
||||
.removeClass("is-invalid");
|
||||
|
||||
if (
|
||||
nombreSala === "" ||
|
||||
nombreSala.length < 3
|
||||
) {
|
||||
mostrarError(
|
||||
"#nombreSala",
|
||||
"El nombre de la sala debe tener al menos 3 caracteres.",
|
||||
"El nombre de la sala debe tener al menos 3 caracteres."
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (nombreEquipo1 === "" || nombreEquipo1.length < 2) {
|
||||
if (
|
||||
nombreEquipo1 === "" ||
|
||||
nombreEquipo1.length < 2
|
||||
) {
|
||||
mostrarError(
|
||||
"#nombreEquipo1",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres."
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (nombreEquipo2 === "" || nombreEquipo2.length < 2) {
|
||||
if (
|
||||
nombreEquipo2 === "" ||
|
||||
nombreEquipo2.length < 2
|
||||
) {
|
||||
mostrarError(
|
||||
"#nombreEquipo2",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||
"El nombre del equipo debe tener al menos 2 caracteres."
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (
|
||||
nombreEquipo1 !== "" &&
|
||||
nombreEquipo2 !== "" &&
|
||||
nombreEquipo1.toLowerCase() === nombreEquipo2.toLowerCase()
|
||||
nombreEquipo1.toLowerCase() ===
|
||||
nombreEquipo2.toLowerCase()
|
||||
) {
|
||||
mostrarError(
|
||||
"#nombreEquipo2",
|
||||
"Los dos equipos deben tener nombres diferentes.",
|
||||
"Los dos equipos deben tener nombres diferentes."
|
||||
);
|
||||
|
||||
valido = false;
|
||||
}
|
||||
|
||||
if (!valido) return;
|
||||
if (!valido) {
|
||||
return;
|
||||
}
|
||||
|
||||
const boton = $("#btnCrearSala");
|
||||
boton.prop("disabled", true).text("Creando sala...");
|
||||
|
||||
boton
|
||||
.prop("disabled", true)
|
||||
.text("Creando sala...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "crear",
|
||||
nombrePartida: nombreSala,
|
||||
nombreEquipo1: nombreEquipo1,
|
||||
nombreEquipo2: nombreEquipo2,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
boton.prop("disabled", false).text("Crear sala");
|
||||
|
||||
boton
|
||||
.prop("disabled", false)
|
||||
.text("Crear sala");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (respuesta.exito) {
|
||||
$("#modalCrearSala").modal("hide");
|
||||
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al crear la sala:", error);
|
||||
alert("No se ha podido crear la sala.");
|
||||
boton.prop("disabled", false).text("Crear sala");
|
||||
console.error(
|
||||
"Error al crear la sala:",
|
||||
error
|
||||
);
|
||||
|
||||
alert(
|
||||
"No se ha podido crear la sala."
|
||||
);
|
||||
|
||||
boton
|
||||
.prop("disabled", false)
|
||||
.text("Crear sala");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Auxiliares
|
||||
function escapeHTML(texto) {
|
||||
return $("<div>")
|
||||
.text(texto ?? "")
|
||||
.html();
|
||||
}
|
||||
|
||||
function mostrarError(selector, mensaje) {
|
||||
function mostrarError(
|
||||
selector,
|
||||
mensaje
|
||||
) {
|
||||
const input = $(selector);
|
||||
|
||||
input.addClass("is-invalid");
|
||||
input.after(
|
||||
`<div class="mensaje-error-sala text-danger mt-1 small">${mensaje}</div>`,
|
||||
);
|
||||
|
||||
input.after(`
|
||||
<div
|
||||
class="mensaje-error-sala text-danger mt-1 small">
|
||||
|
||||
${mensaje}
|
||||
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
$(document).on("input", ".input-kahoot", function () {
|
||||
$(this).removeClass("is-invalid");
|
||||
$(this).next(".mensaje-error-sala").remove();
|
||||
});
|
||||
$(document).on(
|
||||
"input",
|
||||
".input-kahoot",
|
||||
function () {
|
||||
$(this)
|
||||
.removeClass("is-invalid");
|
||||
|
||||
$(this)
|
||||
.next(".mensaje-error-sala")
|
||||
.remove();
|
||||
}
|
||||
);
|
||||
+2
-8
@@ -2,13 +2,7 @@ let idUsuarioSesion = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
comprobarSesion();
|
||||
// Carga la cabecera html
|
||||
$("#cabecera-container").load("cabecera.html", function () {
|
||||
// Después de cargar cabecera comprobamos sesión
|
||||
comprobarSesion();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Función auxiliar para escapar texto HTML
|
||||
function escapeHTML(str) {
|
||||
@@ -98,7 +92,7 @@ function comprobarSesion() {
|
||||
}
|
||||
|
||||
// Registro
|
||||
$(document).on("click", "#botonAceptarRegistro", function (event) {
|
||||
$("#botonAceptarRegistro").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let nombreUsuario = $("#regNombre").val().trim();
|
||||
@@ -151,7 +145,7 @@ $(document).on("click", "#botonAceptarRegistro", function (event) {
|
||||
});
|
||||
|
||||
// Login
|
||||
$(document).on("click", "#botonAceptarLogin", function (event) {
|
||||
$("#botonAceptarLogin").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let email = $("#loginEmail").val().trim();
|
||||
|
||||
+550
@@ -0,0 +1,550 @@
|
||||
let usuarioYaEstaEnEquipo = false;
|
||||
let intervaloSala = null;
|
||||
let botonAbandonarReferencia = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
comprobarSalaUsuario();
|
||||
});
|
||||
|
||||
function comprobarSalaUsuario() {
|
||||
$("#cargandoSalas").remove();
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
orden: "obtenerSalaUsuario",
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error || !respuesta.asociado) {
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
$("#contenedorCrearSala").show();
|
||||
|
||||
iniciarActualizacionSalas();
|
||||
} else {
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
|
||||
$("#contenedorCrearSala").hide();
|
||||
|
||||
cargarSalaUsuario(respuesta.idPartida);
|
||||
}
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
if (intervaloSala) {
|
||||
clearInterval(intervaloSala);
|
||||
intervaloSala = null;
|
||||
}
|
||||
|
||||
$("#contenedorSalas").empty();
|
||||
|
||||
$("#contenedorCrearSala").show();
|
||||
|
||||
iniciarActualizacionSalas();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function cargarSalaUsuario(idPartida) {
|
||||
cargarSalaCompleta(idPartida);
|
||||
|
||||
if (intervaloSala) {
|
||||
clearInterval(intervaloSala);
|
||||
}
|
||||
|
||||
intervaloSala = setInterval(function () {
|
||||
actualizarSalaUsuario(idPartida);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function cargarSalaCompleta(idPartida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "buscar",
|
||||
idPartida: idPartida,
|
||||
},
|
||||
|
||||
success: function (partida) {
|
||||
if (partida.error) {
|
||||
console.error(partida.error);
|
||||
return;
|
||||
}
|
||||
|
||||
cargarInformacionSalaCompleta(partida);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener la sala:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function cargarInformacionSalaCompleta(partida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getEquipos",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (equipos) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getJugadores",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (jugadores) {
|
||||
mostrarSala(partida, equipos, jugadores);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener jugadores:", error);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener equipos:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function actualizarSalaUsuario(idPartida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "buscar",
|
||||
idPartida: idPartida,
|
||||
},
|
||||
|
||||
success: function (partida) {
|
||||
if (partida.error) {
|
||||
console.error(partida.error);
|
||||
return;
|
||||
}
|
||||
|
||||
cargarInformacionSala(partida);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al actualizar la sala:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function cargarInformacionSala(partida) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getEquipos",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (equipos) {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "getJugadores",
|
||||
idPartida: partida.idPartida,
|
||||
},
|
||||
|
||||
success: function (jugadores) {
|
||||
mostrarEquipos(partida, equipos, jugadores);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener jugadores:", error);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al obtener equipos:", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function mostrarSala(partida, equipos, jugadores) {
|
||||
const contenedor = $("#contenedorSalas");
|
||||
|
||||
let equiposHTML = "";
|
||||
|
||||
equipos.forEach(function (equipo) {
|
||||
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
});
|
||||
|
||||
let jugadoresHTML = "";
|
||||
|
||||
if (jugadoresEquipo.length > 0) {
|
||||
jugadoresEquipo.forEach(function (jugador) {
|
||||
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||
|
||||
jugadoresHTML += `
|
||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||
esHost ? "jugador-host" : ""
|
||||
}">
|
||||
|
||||
<div>
|
||||
<span class="avatar">
|
||||
${
|
||||
esHost
|
||||
? '<i class="bi bi-award-fill"></i>'
|
||||
: '<i class="bi bi-person-fill"></i>'
|
||||
}
|
||||
</span>
|
||||
|
||||
${escapeHTML(jugador.nombreUsuario)}
|
||||
</div>
|
||||
|
||||
${
|
||||
esHost
|
||||
? `<span class="badge bg-warning text-dark ms-2">
|
||||
HOST
|
||||
</span>`
|
||||
: ""
|
||||
}
|
||||
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else {
|
||||
jugadoresHTML = `
|
||||
<div class="text-muted small">
|
||||
Sin jugadores
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
equiposHTML += `
|
||||
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||
|
||||
<h6>
|
||||
${escapeHTML(equipo.nombreEquipo)}
|
||||
</h6>
|
||||
|
||||
<div class="jugadores mb-2">
|
||||
${jugadoresHTML}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
const esHost = partida.idUsuario == idUsuarioSesion;
|
||||
|
||||
let botonIniciarHTML = "";
|
||||
|
||||
if (esHost) {
|
||||
botonIniciarHTML = `
|
||||
<a
|
||||
href="juego.php?idPartida=${partida.idPartida}"
|
||||
class="btn btn-success btn-lg px-4">
|
||||
|
||||
<i class="bi bi-controller"></i>
|
||||
¡Iniciar Partida!
|
||||
|
||||
</a>
|
||||
`;
|
||||
}
|
||||
|
||||
const salaHTML = `
|
||||
<div class="col-12 col-md-10 col-lg-8">
|
||||
|
||||
<div class="sala card p-3 shadow-sm mb-4">
|
||||
|
||||
<div class="sala-header h4 text-center mb-3 text-white">
|
||||
${escapeHTML(partida.nombrePartida)}
|
||||
</div>
|
||||
|
||||
<div class="sala-body">
|
||||
|
||||
<div class="equipos d-flex justify-content-around">
|
||||
${equiposHTML}
|
||||
</div>
|
||||
|
||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-danger btn-abandonar-sala"
|
||||
data-id-partida="${partida.idPartida}"
|
||||
data-es-host="${esHost}">
|
||||
|
||||
Abandonar sala
|
||||
|
||||
</button>
|
||||
|
||||
${esHost ? botonIniciarHTML : ""}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`;
|
||||
|
||||
contenedor.html(salaHTML);
|
||||
}
|
||||
|
||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||
const boton = $(this);
|
||||
|
||||
const idEquipo = boton.data("id-equipo");
|
||||
const idPartida = boton.data("id-partida");
|
||||
|
||||
boton.prop("disabled", true).text("Uniéndose...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "registrarUsuarioEnEquipo",
|
||||
idEquipo: idEquipo,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
usuarioYaEstaEnEquipo = true;
|
||||
|
||||
$("#contenedorCrearSala").hide();
|
||||
$("#contenedorSalas").empty();
|
||||
|
||||
cargarSalaUsuario(idPartida);
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error al unirse al equipo:", error);
|
||||
|
||||
alert("No se ha podido unir al equipo.");
|
||||
|
||||
boton.prop("disabled", false).text("Unirse");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||
botonAbandonarReferencia = $(this);
|
||||
|
||||
const esHost =
|
||||
$(this).data("es-host") === true ||
|
||||
$(this).data("es-host") === "true";
|
||||
|
||||
const titulo = $("#modalAbandonarSalaLabel");
|
||||
|
||||
const mensaje = $("#modalAbandonarSalaMensaje");
|
||||
|
||||
const botonConfirmar = $("#btnConfirmarAbandonar");
|
||||
|
||||
if (esHost) {
|
||||
titulo.text("¿Abandonar la sala?");
|
||||
|
||||
mensaje.text(
|
||||
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
||||
);
|
||||
|
||||
botonConfirmar.text("Sí, terminar partida");
|
||||
} else {
|
||||
titulo.text("¿Abandonar la sala?");
|
||||
|
||||
mensaje.text(
|
||||
"Si sales de la sala, perderás tu lugar en el equipo.",
|
||||
);
|
||||
|
||||
botonConfirmar.text("Sí, salir");
|
||||
}
|
||||
|
||||
const modal = new bootstrap.Modal(
|
||||
document.getElementById("modalAbandonarSala"),
|
||||
);
|
||||
|
||||
modal.show();
|
||||
});
|
||||
|
||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
const modalEl =
|
||||
document.getElementById("modalAbandonarSala");
|
||||
|
||||
const modalInstance =
|
||||
bootstrap.Modal.getInstance(modalEl);
|
||||
|
||||
const btnConfirmar = $(this);
|
||||
|
||||
btnConfirmar
|
||||
.prop("disabled", true)
|
||||
.text("Saliendo...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "salirDeSala",
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
btnConfirmar
|
||||
.prop("disabled", false)
|
||||
.text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
return;
|
||||
}
|
||||
|
||||
usuarioYaEstaEnEquipo = false;
|
||||
|
||||
if (intervaloSala) {
|
||||
clearInterval(intervaloSala);
|
||||
intervaloSala = null;
|
||||
}
|
||||
|
||||
$("#contenedorSalas").empty();
|
||||
|
||||
$("#contenedorCrearSala").show();
|
||||
|
||||
iniciarActualizacionSalas();
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error(
|
||||
"Error al salir de la sala:",
|
||||
error
|
||||
);
|
||||
|
||||
alert("No se pudo salir de la sala.");
|
||||
|
||||
btnConfirmar
|
||||
.prop("disabled", false)
|
||||
.text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function escapeHTML(texto) {
|
||||
return $("<div>")
|
||||
.text(texto ?? "")
|
||||
.html();
|
||||
}
|
||||
|
||||
function mostrarEquipos(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
) {
|
||||
let equiposHTML = "";
|
||||
|
||||
equipos.forEach(function (equipo) {
|
||||
const jugadoresEquipo =
|
||||
jugadores.filter(function (jugador) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
});
|
||||
|
||||
let jugadoresHTML = "";
|
||||
|
||||
if (jugadoresEquipo.length > 0) {
|
||||
jugadoresEquipo.forEach(function (jugador) {
|
||||
const esHost =
|
||||
jugador.idUsuario == partida.idUsuario;
|
||||
|
||||
jugadoresHTML += `
|
||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||
esHost ? "jugador-host" : ""
|
||||
}">
|
||||
|
||||
<div>
|
||||
<span class="avatar">
|
||||
${
|
||||
esHost
|
||||
? '<i class="bi bi-award-fill"></i>'
|
||||
: '<i class="bi bi-person-fill"></i>'
|
||||
}
|
||||
</span>
|
||||
|
||||
${escapeHTML(
|
||||
jugador.nombreUsuario
|
||||
)}
|
||||
</div>
|
||||
|
||||
${
|
||||
esHost
|
||||
? `<span class="badge bg-warning text-dark ms-2">
|
||||
HOST
|
||||
</span>`
|
||||
: ""
|
||||
}
|
||||
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} else {
|
||||
jugadoresHTML = `
|
||||
<div class="text-muted small">
|
||||
Sin jugadores
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
equiposHTML += `
|
||||
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||
|
||||
<h6>
|
||||
${escapeHTML(equipo.nombreEquipo)}
|
||||
</h6>
|
||||
|
||||
<div class="jugadores mb-2">
|
||||
${jugadoresHTML}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
$("#contenedorSalas .equipos").html(equiposHTML);
|
||||
}
|
||||
+1
-2
@@ -41,7 +41,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<body>
|
||||
|
||||
<header id="cabecera-container"></header>
|
||||
<?php include_once 'cabecera.php'; ?>
|
||||
|
||||
<div class="perfil-container">
|
||||
|
||||
@@ -310,7 +310,6 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<!-- Tu JavaScript -->
|
||||
<script src="js/perfil.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user