158 lines
5.9 KiB
JavaScript
158 lines
5.9 KiB
JavaScript
// Pop up desenvolvido para alinhar os Grupos de usuário de um ambiente respectivamente
|
|
|
|
InicializandoPopPerfil();
|
|
|
|
function InicializandoPopPerfil() {
|
|
|
|
|
|
const interval_ConfigPerfil = 500; // Tempo em milissegundos (1 segundo)
|
|
|
|
try {
|
|
|
|
const checkElements_ConfigPerfil = setInterval(() => {
|
|
try {
|
|
|
|
const ConfigPerfilConstruida = document.getElementById('EstruturaPerfil');
|
|
|
|
|
|
if (ConfigPerfilConstruida) {
|
|
const IntegridadePopUp = document.getElementById('Pop_up_Config');
|
|
const ButtonEnviar = document.getElementById('EnviarInformacoes')
|
|
ButtonEnviar.addEventListener('click', capiturarInfos);
|
|
SeletorEmpresa();
|
|
|
|
|
|
const inputPerfil = document.getElementById('uploadImagem_Perfil');
|
|
const inputFundo = document.getElementById('uploadImagem_Fundo');
|
|
|
|
const buttonPerfil = document.getElementById('ImagemPerfil');
|
|
const buttonFundo = document.getElementById('ImagemFundo');
|
|
inputPerfil.addEventListener('change', () => alterarImagem(inputPerfil, buttonPerfil));
|
|
inputFundo.addEventListener('change', () => alterarImagem(inputFundo, buttonFundo));
|
|
|
|
|
|
|
|
// 📌 Função para alterar a imagem de fundo dos botões
|
|
function alterarImagem(input, button) {
|
|
const file = input.files[0];
|
|
|
|
if (file) {
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function (event) {
|
|
// Define a imagem como fundo do botão
|
|
button.style.backgroundImage = `url(${event.target.result})`;
|
|
button.style.backgroundSize = "cover";
|
|
button.style.backgroundPosition = "center";
|
|
button.style.transition = '0.5s ease';
|
|
button.textContent = ''; // Remove qualquer texto dentro do botão
|
|
};
|
|
|
|
reader.readAsDataURL(file); // Lê a imagem e converte para URL
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function capiturarInfos() {
|
|
|
|
// Verifica se os inputs existem
|
|
if (!inputPerfil || !inputFundo) {
|
|
console.error('Um ou mais elementos do formulário não foram encontrados.');
|
|
alert('Erro interno: Elementos do formulário não encontrados.');
|
|
return;
|
|
}
|
|
|
|
const perfil = inputPerfil.files[0];
|
|
const foto_fundo = inputFundo.files[0];
|
|
|
|
// Validação de preenchimento
|
|
if (!perfil || !foto_fundo) {
|
|
alert('Por favor, selecione ambas as imagens antes de continuar.');
|
|
return;
|
|
}
|
|
|
|
// Define limites de tamanho e formato
|
|
const tamanhoMaximo = 150 * 1024 * 1024; // 150MB em bytes
|
|
const extensoesPermitidas = ["image/jpeg", "image/jpg"];
|
|
|
|
// Função para validar arquivo
|
|
function validarArquivo(arquivo, nomeCampo) {
|
|
if (!extensoesPermitidas.includes(arquivo.type)) {
|
|
alert(`O arquivo selecionado para ${nomeCampo} não é um JPG válido.`);
|
|
return false;
|
|
}
|
|
if (arquivo.size > tamanhoMaximo) {
|
|
alert(`O arquivo selecionado para ${nomeCampo} excede o limite de 150MB.`);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Valida ambos os arquivos
|
|
if (!validarArquivo(perfil, "Perfil") || !validarArquivo(foto_fundo, "Fundo")) {
|
|
return; // Interrompe o envio se houver erro
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('perfil', perfil);
|
|
formData.append('foto_fundo', foto_fundo);
|
|
|
|
//console.log(perfil)
|
|
enviarInfo(formData);
|
|
|
|
}
|
|
async function enviarInfo(dataperfil) {
|
|
|
|
try {
|
|
|
|
await NovasImagens(dataperfil);
|
|
alert('Imagens atualizadas');
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Erro:', error);
|
|
alert('Erro ao criar ao atualizar a imagem. Tente novamente mais tarde.');
|
|
|
|
}
|
|
}
|
|
|
|
function SeletorEmpresa() {
|
|
|
|
const ButtonFecharUser = document.getElementById('EncerrarPopupPerfil');
|
|
|
|
ButtonFecharUser.addEventListener('click', Fechar);
|
|
|
|
function Fechar() {
|
|
IntegridadePopUp.style.display = "none"
|
|
IntegridadePopUp.innerHTML = '';
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearInterval(checkElements_ConfigPerfil); // Para o setInterval
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
console.error('Houve algo inesperado dentro da tela home' + error)
|
|
|
|
clearInterval(checkElements_ConfigPerfil); // Para o setInterval
|
|
|
|
return false
|
|
}
|
|
|
|
|
|
|
|
}, interval_ConfigPerfil);
|
|
|
|
} catch (error) {
|
|
console.error('Houve algo inesperado fora da tela home' + error)
|
|
}
|
|
|
|
|
|
|
|
|
|
} |