109 lines
2.3 KiB
JavaScript
109 lines
2.3 KiB
JavaScript
// =========================
|
|
// MOSTRAR ESTADISTICAS
|
|
// =========================
|
|
|
|
$.ajax({
|
|
method: "POST",
|
|
url: "controladores/controladorUsuario.php",
|
|
data: {
|
|
orden: "mostrarEstadisticas",
|
|
},
|
|
}).done(function (respuesta) {
|
|
console.log(respuesta);
|
|
respuesta = JSON.parse(respuesta);
|
|
if (respuesta.error) {
|
|
console.log(respuesta.error);
|
|
} else {
|
|
$("#victorias").text(respuesta.victorias);
|
|
$("#derrotas").text(respuesta.derrotas);
|
|
$("#aciertos").text(respuesta.aciertos);
|
|
}
|
|
});
|
|
|
|
// =========================
|
|
// CAMBIAR NOMBRE
|
|
// =========================
|
|
function cambiarNombre() {
|
|
let nuevoNombre = $("#nuevoNombre").val().trim();
|
|
|
|
$.ajax({
|
|
method: "POST",
|
|
url: "controladores/controladorUsuario.php",
|
|
data: {
|
|
nombreUsuario: nuevoNombre,
|
|
orden: "cambiarNombre",
|
|
},
|
|
}).done(function (respuesta) {
|
|
console.log(respuesta);
|
|
respuesta = JSON.parse(respuesta);
|
|
if (respuesta.error) {
|
|
console.log(respuesta.error);
|
|
} else {
|
|
// Actualizamos el nombre mostrado en la página
|
|
$("#nombre").text(respuesta.nombreUsuario);
|
|
|
|
// Limpiamos el input
|
|
$("#nuevoNombre").val("");
|
|
}
|
|
});
|
|
}
|
|
|
|
// =========================
|
|
// BORRAR NOMBRE
|
|
// =========================
|
|
|
|
function borrarNombre() {
|
|
document.getElementById("nuevoNombre").value = "";
|
|
}
|
|
|
|
|
|
// =========================
|
|
// CAMBIAR FOTO
|
|
// =========================
|
|
|
|
function seleccionarFoto() {
|
|
$("#inputFoto").click();
|
|
}
|
|
|
|
$("#inputFoto").change(function () {
|
|
let archivo = this.files[0];
|
|
|
|
if (!archivo) {
|
|
return;
|
|
}
|
|
|
|
// Comprobamos que sea una imagen
|
|
if (!archivo.type.startsWith("image/")) {
|
|
alert("El archivo seleccionado no es una imagen.");
|
|
|
|
$("#inputFoto").val("");
|
|
|
|
return;
|
|
}
|
|
|
|
let datos = new FormData();
|
|
|
|
datos.append("avatar", archivo);
|
|
datos.append("orden", "cambiarAvatar");
|
|
|
|
$.ajax({
|
|
method: "POST",
|
|
url: "controladores/controladorUsuario.php",
|
|
data: datos,
|
|
processData: false,
|
|
contentType: false,
|
|
}).done(function (respuesta) {
|
|
console.log(respuesta);
|
|
respuesta = JSON.parse(respuesta);
|
|
if (respuesta.error) {
|
|
alert(respuesta.error);
|
|
} else {
|
|
// Actualizamos la imagen sin recargar la página
|
|
$("#fotoPerfil").attr(
|
|
"src",
|
|
respuesta.avatar + "?t=" + new Date().getTime(),
|
|
);
|
|
}
|
|
});
|
|
});
|