-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
211 lines (180 loc) · 7.22 KB
/
script.js
File metadata and controls
211 lines (180 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
document.addEventListener('DOMContentLoaded', function() {
const eventForm = document.getElementById('eventForm');
const loadingOverlay = document.getElementById('loading');
const successMessage = document.getElementById('success-message');
const emailSent = document.getElementById('email-sent');
const adminLink = document.getElementById('admin-link');
const presencaLink = document.getElementById('presenca-link');
// Validação de formulário
eventForm.addEventListener('submit', function(e) {
e.preventDefault();
if (validateForm()) {
// Mostrar overlay de carregamento
loadingOverlay.classList.add('show');
// Simulação de envio do formulário (será substituído pelo envio real)
simulateFormSubmission();
}
});
// Validação em tempo real para o campo de email
const emailInput = document.getElementById('emailOrganizador');
emailInput.addEventListener('blur', function() {
validateEmail(emailInput);
});
// Validação em tempo real para os campos de senha
const senhaInput = document.getElementById('senha');
const confirmaSenhaInput = document.getElementById('confirmaSenha');
confirmaSenhaInput.addEventListener('blur', function() {
validatePasswordMatch(senhaInput, confirmaSenhaInput);
});
// Função para validar o formulário completo
function validateForm() {
let isValid = true;
// Validar nome do evento
const nomeEvento = document.getElementById('nomeEvento');
if (!nomeEvento.value.trim()) {
showError(nomeEvento, 'Nome do evento é obrigatório');
isValid = false;
} else {
hideError(nomeEvento);
}
// Validar data do evento
const dataEvento = document.getElementById('dataEvento');
if (!dataEvento.value) {
showError(dataEvento, 'Data do evento é obrigatória');
isValid = false;
} else {
const selectedDate = new Date(dataEvento.value);
const today = new Date();
today.setHours(0, 0, 0, 0);
if (selectedDate < today) {
showError(dataEvento, 'A data do evento não pode ser no passado');
isValid = false;
} else {
hideError(dataEvento);
}
}
// Validar nome do organizador
const nomeOrganizador = document.getElementById('nomeOrganizador');
if (!nomeOrganizador.value.trim()) {
showError(nomeOrganizador, 'Nome do organizador é obrigatório');
isValid = false;
} else {
hideError(nomeOrganizador);
}
// Validar email
if (!validateEmail(emailInput)) {
isValid = false;
}
// Validar senhas
if (!validatePasswordMatch(senhaInput, confirmaSenhaInput)) {
isValid = false;
}
// Validar termos
const termos = document.getElementById('termos');
if (!termos.checked) {
showError(termos, 'Você precisa concordar com os termos');
isValid = false;
} else {
hideError(termos);
}
return isValid;
}
// Função para validar email
function validateEmail(input) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!input.value.trim()) {
showError(input, 'Email é obrigatório');
return false;
} else if (!emailRegex.test(input.value)) {
showError(input, 'Por favor, insira um email válido');
return false;
} else {
hideError(input);
return true;
}
}
// Função para validar correspondência de senhas
function validatePasswordMatch(passwordInput, confirmInput) {
if (!passwordInput.value) {
showError(passwordInput, 'Senha é obrigatória');
return false;
} else if (passwordInput.value.length < 6) {
showError(passwordInput, 'A senha deve ter pelo menos 6 caracteres');
return false;
} else {
hideError(passwordInput);
}
if (!confirmInput.value) {
showError(confirmInput, 'Confirmação de senha é obrigatória');
return false;
} else if (passwordInput.value !== confirmInput.value) {
showError(confirmInput, 'As senhas não coincidem');
return false;
} else {
hideError(confirmInput);
return true;
}
}
// Função para mostrar erro
function showError(input, message) {
const errorElement = document.getElementById(`${input.id}-error`);
errorElement.textContent = message;
errorElement.classList.add('show');
input.classList.add('input-error');
}
// Função para esconder erro
function hideError(input) {
const errorElement = document.getElementById(`${input.id}-error`);
errorElement.textContent = '';
errorElement.classList.remove('show');
input.classList.remove('input-error');
}
// Função para simular o envio do formulário (será substituída pelo envio real)
function simulateFormSubmission() {
// Preparar dados do formulário
const formData = new FormData(eventForm);
// Converter FormData para objeto JSON
const dados = {};
formData.forEach((value, key) => {
dados[key] = value;
});
// Enviar dados para o backend
fetch('criar_evento.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(dados)
})
.then(response => response.json())
.then(data => {
// Esconder o overlay de carregamento
loadingOverlay.classList.remove('show');
if (data.sucesso) {
// Esconder o formulário
eventForm.parentElement.style.display = 'none';
// Mostrar mensagem de sucesso
successMessage.classList.add('show');
// Preencher o email na mensagem de sucesso
emailSent.textContent = document.getElementById('emailOrganizador').value;
// Definir links reais
adminLink.href = data.admin_url;
presencaLink.href = data.presenca_url;
} else {
// Mostrar erro
alert('Erro ao criar evento: ' + data.mensagem);
}
})
.catch(error => {
// Esconder o overlay de carregamento
loadingOverlay.classList.remove('show');
console.error('Erro:', error);
alert('Erro ao processar solicitação. Tente novamente.');
});
}
// Função para gerar um ID aleatório (apenas para simulação)
function generateRandomId() {
return Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15);
}
});