86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function() {
|
|
cargarEventos();
|
|
});
|
|
|
|
function cargarEventos() {
|
|
fetch("../php/obtener_conciertos.php")
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
let select = document.getElementById("eventoSeleccionado");
|
|
select.innerHTML = '<option value="">Seleccione un evento</option>';
|
|
|
|
data.forEach(concierto => {
|
|
let option = document.createElement("option");
|
|
option.value = concierto.id;
|
|
option.textContent = concierto.nombre;
|
|
select.appendChild(option);
|
|
});
|
|
|
|
select.addEventListener("change", function() {
|
|
cargarDatosEvento(select.value);
|
|
});
|
|
})
|
|
.catch(error => console.error("Error cargando conciertos:", error));
|
|
}
|
|
|
|
function cargarDatosEvento(eventoId) {
|
|
if (!eventoId) return;
|
|
|
|
fetch(`../php/obtener_detalle_concierto.php?id=${eventoId}`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
document.querySelector("input[name='nombre']").value = data.nombre;
|
|
document.querySelector("input[name='artista']").value = data.artista;
|
|
document.querySelector("input[name='fecha']").value = data.fecha;
|
|
document.querySelector("input[name='hora']").value = data.hora;
|
|
document.querySelector("input[name='direccion']").value = data.direccion;
|
|
document.querySelector("input[name='precio_vip']").value = data.precio_vip;
|
|
document.querySelector("input[name='precio_general']").value = data.precio_general;
|
|
})
|
|
.catch(error => console.error("Error cargando detalles del evento:", error));
|
|
}
|
|
|
|
document.getElementById("formEditarEvento").addEventListener("submit", function(e) {
|
|
e.preventDefault();
|
|
|
|
let formData = new FormData(this);
|
|
|
|
fetch("../php/editar_concierto.php", {
|
|
method: "POST",
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(() => {
|
|
window.location.href = "../views/index.html"; // Redirigir sin alert
|
|
})
|
|
.catch(error => console.error("Error:", error));
|
|
});
|
|
|
|
document.getElementById("btnEliminar").addEventListener("click", function() {
|
|
let eventoId = document.getElementById("eventoSeleccionado").value;
|
|
|
|
if (!eventoId) {
|
|
alert("Selecciona un evento para eliminar.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm("¿Estás seguro de que quieres eliminar este evento?")) {
|
|
return;
|
|
}
|
|
|
|
fetch("../php/eliminar_concierto.php", {
|
|
method: "POST",
|
|
body: JSON.stringify({ id: eventoId }),
|
|
headers: { "Content-Type": "application/json" }
|
|
})
|
|
.then(response => response.text())
|
|
.then(() => {
|
|
window.location.href = "../views/index.html"; // Redirigir sin alert
|
|
})
|
|
.catch(error => console.error("Error eliminando evento:", error));
|
|
});
|
|
|
|
document.getElementById("btnVolver").addEventListener("click", function() {
|
|
window.location.href = "../views/index.html";
|
|
});
|