forked from wagnerfusca/eventos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
936 lines (847 loc) · 36 KB
/
Copy pathadmin.html
File metadata and controls
936 lines (847 loc) · 36 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin — Papo de Sysadmin Eventos</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<style>
body { background: #0f0f14; color: #f0f0f5; font-family: 'Inter', sans-serif; }
/* Admin content */
.admin-content { display: none; }
.admin-banner {
background-color: #1e1e2a; border: 1px solid #4CAF50;
color: #4CAF50; padding: 0.75rem 1rem; text-align: center;
font-weight: 600; font-size: 0.9rem; border-radius: 8px; margin-bottom: 1.5rem;
}
.btn-deletar {
background-color: #dc3545;
color: #fff;
border: none;
padding: 0.3rem 0.6rem;
border-radius: 4px;
font-size: 0.8rem;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-deletar:hover { background-color: #c82333; color: #fff; }
.btn-editar {
background-color: #007bff;
color: #fff;
border: none;
padding: 0.3rem 0.6rem;
border-radius: 4px;
font-size: 0.8rem;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-editar:hover { background-color: #0056b3; color: #fff; }
.btn-salvar-global {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 6px;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-salvar-global:hover { background-color: #66BB6A; color: #fff; }
.save-instructions {
background-color: #1e3a1e;
border: 1px solid #4CAF50;
color: #a5d6a7;
padding: 0.75rem 1rem;
border-radius: 6px;
margin-top: 0.75rem;
font-size: 0.9rem;
}
.edit-form {
background-color: #1e1e2a;
border: 1px solid #2a2a3a;
border-radius: 8px;
padding: 1rem;
margin-top: 0.5rem;
}
.edit-form label {
font-size: 0.85rem;
font-weight: 600;
color: #ccc;
margin-bottom: 0.2rem;
}
.edit-form input,
.edit-form select,
.edit-form textarea {
font-size: 0.85rem;
background: #0f0f14;
color: #f0f0f5;
border: 1px solid #2a2a3a;
}
.edit-form input:focus,
.edit-form select:focus {
border-color: #4CAF50;
outline: none;
box-shadow: 0 0 0 2px rgba(76,175,80,0.2);
}
.add-form {
background-color: #1e1e2a;
border: 2px solid #4CAF50;
border-radius: 8px;
padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.add-form h3 {
color: #4CAF50;
margin-bottom: 1rem;
}
.import-form {
background-color: #1a1a2e;
border: 2px solid #ff9800;
border-radius: 8px;
padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.import-form h3 {
color: #ff9800;
margin-bottom: 1rem;
}
.import-status {
margin-top: 0.75rem;
padding: 0.75rem 1rem;
border-radius: 6px;
font-size: 0.85rem;
display: none;
}
.import-status.loading {
display: block;
background: #1a2a3a;
border: 1px solid #2196F3;
color: #90caf9;
}
.import-status.success {
display: block;
background: #1e3a1e;
border: 1px solid #4CAF50;
color: #a5d6a7;
}
.import-status.error {
display: block;
background: #3a1e1e;
border: 1px solid #f44336;
color: #ef9a9a;
}
.badge-presenca-tipo {
display: inline-block;
background-color: #4CAF50;
color: #fff;
font-size: 0.75rem;
font-weight: 600;
padding: 0.15rem 0.4rem;
border-radius: 4px;
text-transform: capitalize;
}
.changes-pending {
position: fixed;
bottom: 1rem;
right: 1rem;
z-index: 1050;
box-shadow: 0 4px 16px rgba(0,0,0,0.5);
border-radius: 8px;
padding: 1rem 1.5rem;
background-color: #1e1e2a;
border: 2px solid #4CAF50;
}
.admin-table {
color: #f0f0f5;
}
.admin-table th {
background: #1e1e2a;
color: #9a9ab0;
border-color: #2a2a3a;
}
.admin-table td {
border-color: #2a2a3a;
vertical-align: middle;
}
.btn-import {
background-color: #ff9800;
color: #fff;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 6px;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-import:hover { background-color: #ffa726; color: #fff; }
.btn-import:disabled {
background-color: #555;
cursor: not-allowed;
}
</style>
</head>
<body>
<!-- Admin Content (protegido por Cloudflare Access) -->
<div class="admin-content" id="admin-content" style="display:block;">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" style="background:#0f0f14;border-bottom:1px solid #2a2a3a;">
<a class="navbar-brand" href="index.html">
<img src="assets/logo-papo.png" alt="Papo de Sysadmin" height="30" style="filter:invert(1);">
<span class="ml-2" style="font-size:0.9rem;">Admin</span>
</a>
<span class="navbar-text text-white ml-auto" style="font-size:0.8rem;">Painel de Gerenciamento</span>
</nav>
<div class="container-fluid mt-4">
<!-- Banner de aviso -->
<div class="admin-banner">
⚠️ Painel Admin Local — As alterações precisam ser salvas manualmente no repositório
</div>
<!-- Importar via URL -->
<div class="import-form" id="import-form">
<h3>🔗 Importar Evento via URL</h3>
<p style="color:#9a9ab0;font-size:0.85rem;margin-bottom:1rem;">Cole a URL do evento e o sistema extrairá automaticamente as informações (nome, data, local, etc.)</p>
<form onsubmit="return importarViaUrl(event)">
<div class="form-row">
<div class="form-group col-md-7">
<label for="import-url">URL do Evento *</label>
<input type="url" class="form-control" id="import-url" placeholder="https://exemplo.com/evento" required style="background:#0f0f14;color:#f0f0f5;border:1px solid #2a2a3a;">
</div>
<div class="form-group col-md-3">
<label for="import-presenca">Tipo de Presença</label>
<select class="form-control" id="import-presenca" style="background:#0f0f14;color:#f0f0f5;border:1px solid #2a2a3a;">
<option value="">Nenhuma</option>
<option value="palestrante">Palestrante</option>
<option value="participante">Participante</option>
<option value="organizador">Organizador</option>
<option value="midia">Mídia</option>
</select>
</div>
<div class="form-group col-md-2 d-flex align-items-end">
<button type="submit" class="btn-import w-100" id="btn-importar">🚀 Extrair</button>
</div>
</div>
</form>
<div class="import-status" id="import-status"></div>
</div>
<!-- Formulário Adicionar Evento -->
<div class="add-form" id="add-form">
<h3>➕ Adicionar Evento</h3>
<form id="form-adicionar" onsubmit="return adicionarEvento(event)">
<div class="form-row">
<div class="form-group col-md-6">
<label for="add-nome">Nome *</label>
<input type="text" class="form-control" id="add-nome" required>
</div>
<div class="form-group col-md-3">
<label for="add-dataInicio">Data Início *</label>
<input type="date" class="form-control" id="add-dataInicio" required>
</div>
<div class="form-group col-md-3">
<label for="add-dataFim">Data Fim</label>
<input type="date" class="form-control" id="add-dataFim">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="add-local">Local</label>
<input type="text" class="form-control" id="add-local">
</div>
<div class="form-group col-md-3">
<label for="add-cidade">Cidade</label>
<input type="text" class="form-control" id="add-cidade">
</div>
<div class="form-group col-md-2">
<label for="add-estado">Estado</label>
<input type="text" class="form-control" id="add-estado">
</div>
<div class="form-group col-md-3">
<label for="add-pais">País</label>
<input type="text" class="form-control" id="add-pais" value="Brasil">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="add-url">URL do Evento</label>
<input type="url" class="form-control" id="add-url">
</div>
<div class="form-group col-md-3">
<label for="add-categoria">Categoria *</label>
<select class="form-control" id="add-categoria" required>
<option value="">Selecione...</option>
<option value="Cloud">Cloud</option>
<option value="DevOps">DevOps</option>
<option value="Seguranca">Segurança</option>
<option value="Infraestrutura">Infraestrutura</option>
<option value="Automacao">Automação</option>
<option value="Observabilidade">Observabilidade</option>
<option value="Containers">Containers</option>
<option value="Linux">Linux</option>
<option value="Redes">Redes</option>
<option value="Geral">Geral</option>
<option value="IA">IA</option>
<option value="Desenvolvimento">Desenvolvimento</option>
<option value="Dados">Dados</option>
<option value="Carreira">Carreira</option>
</select>
</div>
<div class="form-group col-md-2">
<label for="add-presenca-tipo">Tipo Presença</label>
<select class="form-control" id="add-presenca-tipo">
<option value="">Nenhuma</option>
<option value="palestrante">Palestrante</option>
<option value="participante">Participante</option>
<option value="organizador">Organizador</option>
<option value="midia">Mídia</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="add-descricao">Descrição</label>
<input type="text" class="form-control" id="add-descricao">
</div>
</div>
<button type="submit" class="btn btn-salvar-global">Adicionar Evento</button>
</form>
</div>
<!-- Tabela de Eventos -->
<div class="table-responsive">
<table class="table table-striped table-bordered admin-table">
<thead>
<tr>
<th>Nome</th>
<th style="cursor:pointer;user-select:none;" onclick="toggleSortData()" id="th-data">Data Início <span id="sort-icon">▲</span></th>
<th>Categoria</th>
<th>Presença</th>
<th>Ações</th>
</tr>
</thead>
<tbody id="tabela-eventos">
</tbody>
</table>
</div>
<p id="loading-msg" class="text-center text-muted">Carregando eventos...</p>
</div>
<!-- Floating save button -->
<div class="changes-pending" id="save-panel" style="display:none;">
<button class="btn btn-salvar-global" onclick="salvarAlteracoes()">💾 Salvar Alterações</button>
<div class="save-instructions" id="save-instructions" style="display:none;">
Substitua o arquivo <code>data/eventos.json</code> pelo arquivo baixado e faça push.
</div>
</div>
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
'use strict';
const CATEGORIAS = [
'Cloud', 'DevOps', 'Seguranca', 'Infraestrutura', 'Automacao',
'Observabilidade', 'Containers', 'Linux', 'Redes', 'Geral',
'IA', 'Desenvolvimento', 'Dados', 'Carreira'
];
const TIPOS_PRESENCA = ['palestrante', 'participante', 'organizador', 'midia'];
let eventos = [];
let alteracoesPendentes = false;
// Autenticação via Cloudflare Access — carregar admin diretamente
document.addEventListener('DOMContentLoaded', function() {
carregarEventos();
});
async function carregarEventos() {
try {
const response = await fetch('data/eventos.json');
if (!response.ok) throw new Error('Falha ao carregar');
eventos = await response.json();
renderizarTabela();
} catch (err) {
document.getElementById('loading-msg').textContent =
'Erro ao carregar eventos. Verifique se o arquivo data/eventos.json existe.';
}
}
var sortOrder = 'asc'; // 'asc' ou 'desc'
function toggleSortData() {
sortOrder = sortOrder === 'asc' ? 'desc' : 'asc';
document.getElementById('sort-icon').textContent = sortOrder === 'asc' ? '▲' : '▼';
eventos.sort(function(a, b) {
var dA = a.dataInicio || '';
var dB = b.dataInicio || '';
return sortOrder === 'asc' ? dA.localeCompare(dB) : dB.localeCompare(dA);
});
renderizarTabela();
}
function renderizarTabela() {
const tbody = document.getElementById('tabela-eventos');
const loading = document.getElementById('loading-msg');
loading.style.display = 'none';
tbody.innerHTML = '';
eventos.forEach(function(evento, index) {
const tr = document.createElement('tr');
tr.id = 'row-' + index;
tr.innerHTML = renderRow(evento, index);
tbody.appendChild(tr);
});
}
function renderRow(evento, index) {
const presencaHtml = evento.presenca && evento.presenca.confirmada
? '<span class="badge-presenca-tipo">' + escapeHtml(evento.presenca.tipo) + '</span>'
: '<span class="text-muted">—</span>';
return '<td>' + escapeHtml(evento.nome) + '</td>' +
'<td>' + formatarData(evento.dataInicio) + '</td>' +
'<td>' + escapeHtml(evento.categoria) + '</td>' +
'<td>' + presencaHtml + '</td>' +
'<td class="text-nowrap">' +
'<button class="btn-editar mr-1" onclick="editarEvento(' + index + ')">Editar</button>' +
'<button class="btn-deletar" onclick="deletarEvento(' + index + ')">Deletar</button>' +
'</td>';
}
function formatarData(dateStr) {
if (!dateStr) return '—';
const parts = dateStr.split('-');
if (parts.length !== 3) return dateStr;
return parts[2] + '/' + parts[1] + '/' + parts[0];
}
function gerarId() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function adicionarEvento(e) {
e.preventDefault();
const nome = document.getElementById('add-nome').value.trim();
const dataInicio = document.getElementById('add-dataInicio').value;
const dataFim = document.getElementById('add-dataFim').value;
const local = document.getElementById('add-local').value.trim();
const cidade = document.getElementById('add-cidade').value.trim();
const estado = document.getElementById('add-estado').value.trim();
const pais = document.getElementById('add-pais').value.trim();
const url = document.getElementById('add-url').value.trim();
const categoria = document.getElementById('add-categoria').value;
const descricao = document.getElementById('add-descricao').value.trim();
const presencaTipo = document.getElementById('add-presenca-tipo').value;
const novoEvento = {
id: gerarId(),
nome: nome,
dataInicio: dataInicio,
local: local,
cidade: cidade,
estado: estado,
pais: pais,
url: url,
categoria: categoria
};
if (dataFim) novoEvento.dataFim = dataFim;
if (descricao) novoEvento.descricao = descricao;
if (presencaTipo) {
novoEvento.presenca = { confirmada: true, tipo: presencaTipo };
}
eventos.push(novoEvento);
marcarAlteracoes();
renderizarTabela();
document.getElementById('form-adicionar').reset();
document.getElementById('add-pais').value = 'Brasil';
return false;
}
function deletarEvento(index) {
const evento = eventos[index];
if (!confirm('Tem certeza que deseja deletar o evento "' + evento.nome + '"?')) {
return;
}
eventos.splice(index, 1);
marcarAlteracoes();
renderizarTabela();
}
function editarEvento(index) {
const evento = eventos[index];
const tr = document.getElementById('row-' + index);
// Check if edit form already exists
const existingForm = document.getElementById('edit-form-' + index);
if (existingForm) {
existingForm.remove();
return;
}
const editRow = document.createElement('tr');
editRow.id = 'edit-form-' + index;
editRow.innerHTML = '<td colspan="5">' +
'<div class="edit-form">' +
'<div class="form-row">' +
'<div class="form-group col-md-5">' +
'<label>Nome</label>' +
'<input type="text" class="form-control" id="edit-nome-' + index + '" value="' + escapeAttr(evento.nome) + '">' +
'</div>' +
'<div class="form-group col-md-2">' +
'<label>Data Início</label>' +
'<input type="date" class="form-control" id="edit-dataInicio-' + index + '" value="' + (evento.dataInicio || '') + '">' +
'</div>' +
'<div class="form-group col-md-2">' +
'<label>Data Fim</label>' +
'<input type="date" class="form-control" id="edit-dataFim-' + index + '" value="' + (evento.dataFim || '') + '">' +
'</div>' +
'<div class="form-group col-md-3">' +
'<label>Categoria</label>' +
'<select class="form-control" id="edit-categoria-' + index + '">' +
gerarOptionsCategorias(evento.categoria) +
'</select>' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<div class="form-group col-md-3">' +
'<label>Local</label>' +
'<input type="text" class="form-control" id="edit-local-' + index + '" value="' + escapeAttr(evento.local || '') + '">' +
'</div>' +
'<div class="form-group col-md-2">' +
'<label>Cidade</label>' +
'<input type="text" class="form-control" id="edit-cidade-' + index + '" value="' + escapeAttr(evento.cidade || '') + '">' +
'</div>' +
'<div class="form-group col-md-2">' +
'<label>Estado</label>' +
'<input type="text" class="form-control" id="edit-estado-' + index + '" value="' + escapeAttr(evento.estado || '') + '">' +
'</div>' +
'<div class="form-group col-md-2">' +
'<label>País</label>' +
'<input type="text" class="form-control" id="edit-pais-' + index + '" value="' + escapeAttr(evento.pais || '') + '">' +
'</div>' +
'<div class="form-group col-md-3">' +
'<label>URL</label>' +
'<input type="url" class="form-control" id="edit-url-' + index + '" value="' + escapeAttr(evento.url || '') + '">' +
'</div>' +
'</div>' +
'<div class="form-row">' +
'<div class="form-group col-md-4">' +
'<label>Descrição</label>' +
'<input type="text" class="form-control" id="edit-descricao-' + index + '" value="' + escapeAttr(evento.descricao || '') + '">' +
'</div>' +
'<div class="form-group col-md-3">' +
'<label>Tipo Presença</label>' +
'<select class="form-control" id="edit-presenca-' + index + '">' +
gerarOptionsPresenca(evento.presenca ? evento.presenca.tipo : '') +
'</select>' +
'</div>' +
'<div class="form-group col-md-5 d-flex align-items-end">' +
'<button class="btn btn-salvar-global mr-2" onclick="salvarEdicao(' + index + ')">Confirmar Edição</button>' +
'<button class="btn btn-secondary" onclick="cancelarEdicao(' + index + ')">Cancelar</button>' +
'</div>' +
'</div>' +
'</div>' +
'</td>';
tr.parentNode.insertBefore(editRow, tr.nextSibling);
// Setup autocomplete para o campo cidade na edição
if (cidadesDB.length > 0) {
setupAutocomplete('edit-cidade-' + index, 'edit-estado-' + index);
}
}
function gerarOptionsCategorias(selecionada) {
let html = '';
CATEGORIAS.forEach(function(cat) {
const selected = cat === selecionada ? ' selected' : '';
html += '<option value="' + cat + '"' + selected + '>' + cat + '</option>';
});
return html;
}
function gerarOptionsPresenca(selecionado) {
let html = '<option value="">Nenhuma</option>';
TIPOS_PRESENCA.forEach(function(tipo) {
const selected = tipo === selecionado ? ' selected' : '';
html += '<option value="' + tipo + '"' + selected + '>' + tipo + '</option>';
});
return html;
}
function salvarEdicao(index) {
const evento = eventos[index];
evento.nome = document.getElementById('edit-nome-' + index).value.trim();
evento.dataInicio = document.getElementById('edit-dataInicio-' + index).value;
evento.dataFim = document.getElementById('edit-dataFim-' + index).value || undefined;
evento.local = document.getElementById('edit-local-' + index).value.trim();
evento.cidade = document.getElementById('edit-cidade-' + index).value.trim();
evento.estado = document.getElementById('edit-estado-' + index).value.trim();
evento.pais = document.getElementById('edit-pais-' + index).value.trim();
evento.url = document.getElementById('edit-url-' + index).value.trim();
evento.categoria = document.getElementById('edit-categoria-' + index).value;
evento.descricao = document.getElementById('edit-descricao-' + index).value.trim() || undefined;
const presencaTipo = document.getElementById('edit-presenca-' + index).value;
if (presencaTipo) {
evento.presenca = { confirmada: true, tipo: presencaTipo };
} else {
delete evento.presenca;
}
marcarAlteracoes();
renderizarTabela();
}
function cancelarEdicao(index) {
const editForm = document.getElementById('edit-form-' + index);
if (editForm) editForm.remove();
}
function marcarAlteracoes() {
alteracoesPendentes = true;
document.getElementById('save-panel').style.display = 'block';
document.getElementById('save-instructions').style.display = 'none';
}
function salvarAlteracoes() {
// Clean up undefined values for JSON export
const eventosLimpos = eventos.map(function(ev) {
const obj = {};
Object.keys(ev).forEach(function(key) {
if (ev[key] !== undefined && ev[key] !== '') {
obj[key] = ev[key];
}
});
return obj;
});
const btnSalvar = document.querySelector('#save-panel .btn-salvar-global');
btnSalvar.disabled = true;
btnSalvar.textContent = '⏳ Salvando...';
fetch('https://eventos.papodesysadmin.org/api/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ eventos: eventosLimpos }),
})
.then(function(response) { return response.json(); })
.then(function(result) {
if (result.success) {
document.getElementById('save-instructions').style.display = 'block';
document.getElementById('save-instructions').innerHTML =
'✅ Salvo com sucesso! <strong>' + result.total + ' eventos</strong> atualizados no servidor e publicados automaticamente.';
alteracoesPendentes = false;
} else {
document.getElementById('save-instructions').style.display = 'block';
document.getElementById('save-instructions').innerHTML =
'❌ Erro ao salvar: ' + (result.error || 'Erro desconhecido');
document.getElementById('save-instructions').style.borderColor = '#f44336';
document.getElementById('save-instructions').style.color = '#ef9a9a';
}
})
.catch(function(err) {
document.getElementById('save-instructions').style.display = 'block';
document.getElementById('save-instructions').innerHTML =
'❌ Erro de conexão: ' + err.message;
document.getElementById('save-instructions').style.borderColor = '#f44336';
document.getElementById('save-instructions').style.color = '#ef9a9a';
})
.finally(function() {
btnSalvar.disabled = false;
btnSalvar.textContent = '💾 Salvar Alterações';
});
}
// ============================================================
// IMPORTAÇÃO VIA URL (Extração automática)
// ============================================================
// URL da API de extração (VPS)
const EXTRACT_API_URL = 'https://eventos.papodesysadmin.org/api/extract';
async function importarViaUrl(e) {
e.preventDefault();
const url = document.getElementById('import-url').value.trim();
const presencaTipo = document.getElementById('import-presenca').value;
const statusEl = document.getElementById('import-status');
const btnEl = document.getElementById('btn-importar');
if (!url) return false;
// Show loading
statusEl.className = 'import-status loading';
statusEl.innerHTML = '⏳ Extraindo dados do evento... (pode levar alguns segundos)';
btnEl.disabled = true;
btnEl.textContent = '⏳ Extraindo...';
try {
const response = await fetch(EXTRACT_API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: url }),
});
if (!response.ok) {
throw new Error('Erro HTTP ' + response.status);
}
const result = await response.json();
// Multiple events (markdown list)
if (result.multiple && result.events && result.events.length > 0) {
mostrarListaEventos(result.events, presencaTipo);
statusEl.className = 'import-status success';
statusEl.innerHTML = '✅ Encontrados <strong>' + result.events.length + ' eventos</strong> na página. Selecione os que deseja importar.';
return false;
}
// Single event
if (result.data && (result.data.nome || result.data.dataInicio)) {
preencherFormulario(result.data, presencaTipo);
const camposPreenchidos = Object.keys(result.data).filter(k => result.data[k]).length;
let msg = '✅ Dados extraídos com sucesso! (' + camposPreenchidos + ' campos preenchidos)';
if (result.missingFields && result.missingFields.length > 0) {
msg += '<br>⚠️ Campos não encontrados: <strong>' + result.missingFields.join(', ') + '</strong> — preencha manualmente abaixo.';
}
statusEl.className = 'import-status success';
statusEl.innerHTML = msg;
document.getElementById('add-form').scrollIntoView({ behavior: 'smooth', block: 'start' });
} else {
statusEl.className = 'import-status error';
statusEl.innerHTML = '❌ ' + (result.error || 'Não foi possível extrair dados desta URL. Tente adicionar manualmente.');
}
} catch (err) {
statusEl.className = 'import-status error';
statusEl.innerHTML = '❌ Erro ao conectar com a API de extração: ' + escapeHtml(err.message) +
'<br><small>Verifique se o serviço está rodando na VPS.</small>';
} finally {
btnEl.disabled = false;
btnEl.textContent = '🚀 Extrair';
}
return false;
}
function mostrarListaEventos(eventsList, presencaTipo) {
// Remove previous list if exists
const existing = document.getElementById('multi-events-list');
if (existing) existing.remove();
const container = document.createElement('div');
container.id = 'multi-events-list';
container.style.cssText = 'background:#1a1a2e;border:1px solid #ff9800;border-radius:8px;padding:1rem;margin-top:1rem;max-height:400px;overflow-y:auto;';
let html = '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:0.75rem;">';
html += '<strong style="color:#ff9800;">Selecione os eventos para importar:</strong>';
html += '<button onclick="importarSelecionados(\'' + escapeAttr(presencaTipo) + '\')" class="btn-import" style="padding:0.4rem 1rem;font-size:0.85rem;">Importar Selecionados</button>';
html += '</div>';
html += '<div style="margin-bottom:0.5rem;"><label style="color:#9a9ab0;font-size:0.8rem;cursor:pointer;"><input type="checkbox" id="select-all-events" onchange="toggleAllEvents(this.checked)" style="margin-right:0.4rem;">Selecionar todos</label></div>';
eventsList.forEach(function(ev, i) {
const checked = '';
html += '<label style="display:flex;align-items:center;gap:0.5rem;padding:0.4rem 0.5rem;border-bottom:1px solid #2a2a3a;cursor:pointer;font-size:0.85rem;color:#f0f0f5;">';
html += '<input type="checkbox" class="event-checkbox" data-index="' + i + '" ' + checked + '>';
html += '<span style="flex:1;">';
html += '<strong>' + escapeHtml(ev.nome) + '</strong>';
html += ' <span style="color:#9a9ab0;">— ' + (ev.dataInicio || '?') + '</span>';
if (ev.cidade) html += ' <span style="color:#666;">(' + escapeHtml(ev.cidade) + (ev.estado ? '/' + ev.estado : '') + ')</span>';
if (ev.formato) html += ' <span style="background:#333;color:#aaa;font-size:0.7rem;padding:0.1rem 0.3rem;border-radius:3px;">' + ev.formato + '</span>';
html += '</span>';
html += '</label>';
});
container.innerHTML = html;
// Store events data for later import
container.dataset.events = JSON.stringify(eventsList);
document.getElementById('import-status').after(container);
}
function toggleAllEvents(checked) {
document.querySelectorAll('.event-checkbox').forEach(function(cb) { cb.checked = checked; });
}
function importarSelecionados(presencaTipo) {
const container = document.getElementById('multi-events-list');
if (!container) return;
const eventsList = JSON.parse(container.dataset.events);
const checkboxes = container.querySelectorAll('.event-checkbox:checked');
if (checkboxes.length === 0) {
alert('Selecione ao menos um evento.');
return;
}
checkboxes.forEach(function(cb) {
const idx = parseInt(cb.dataset.index);
const ev = eventsList[idx];
const novoEvento = {
id: gerarId(),
nome: ev.nome,
dataInicio: ev.dataInicio,
local: ev.local || '',
cidade: ev.cidade || '',
estado: ev.estado || '',
pais: ev.pais || 'Brasil',
url: ev.url || '',
categoria: ev.categoria || 'Geral',
};
if (ev.dataFim) novoEvento.dataFim = ev.dataFim;
if (presencaTipo) {
novoEvento.presenca = { confirmada: true, tipo: presencaTipo };
}
eventos.push(novoEvento);
});
marcarAlteracoes();
renderizarTabela();
// Cleanup
container.remove();
const statusEl = document.getElementById('import-status');
statusEl.className = 'import-status success';
statusEl.innerHTML = '✅ ' + checkboxes.length + ' evento(s) importado(s) com sucesso! Clique em "Salvar Alterações" para baixar o JSON.';
}
function preencherFormulario(data, presencaTipo) {
if (data.nome) document.getElementById('add-nome').value = data.nome;
if (data.dataInicio) document.getElementById('add-dataInicio').value = data.dataInicio;
if (data.dataFim) document.getElementById('add-dataFim').value = data.dataFim;
if (data.local) document.getElementById('add-local').value = data.local;
if (data.cidade) document.getElementById('add-cidade').value = data.cidade;
if (data.estado) document.getElementById('add-estado').value = data.estado;
if (data.pais) document.getElementById('add-pais').value = data.pais;
if (data.url) document.getElementById('add-url').value = data.url;
if (data.categoria) document.getElementById('add-categoria').value = data.categoria;
if (data.descricao) document.getElementById('add-descricao').value = data.descricao;
if (presencaTipo) document.getElementById('add-presenca-tipo').value = presencaTipo;
}
function escapeHtml(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function escapeAttr(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
// ============================================================
// AUTOCOMPLETE DE CIDADES (base IBGE)
// ============================================================
var cidadesDB = [];
function carregarCidades() {
fetch('data/cidades-br.json')
.then(function(r) { return r.json(); })
.then(function(data) {
cidadesDB = data;
setupAutocomplete('add-cidade', 'add-estado');
})
.catch(function() { console.warn('Cidades BR não carregadas'); });
}
function setupAutocomplete(inputId, estadoId) {
var input = document.getElementById(inputId);
if (!input) return;
var wrapper = document.createElement('div');
wrapper.style.position = 'relative';
input.parentNode.insertBefore(wrapper, input);
wrapper.appendChild(input);
var dropdown = document.createElement('div');
dropdown.className = 'autocomplete-dropdown';
dropdown.style.cssText = 'position:absolute;top:100%;left:0;right:0;background:#1a1a2e;border:1px solid #444;border-radius:0 0 6px 6px;max-height:200px;overflow-y:auto;display:none;z-index:1000;';
wrapper.appendChild(dropdown);
input.addEventListener('input', function() {
var val = this.value.trim().toLowerCase();
if (val.length < 2) { dropdown.style.display = 'none'; return; }
var matches = cidadesDB.filter(function(c) {
return c.c.toLowerCase().startsWith(val);
}).slice(0, 15);
if (matches.length === 0) {
matches = cidadesDB.filter(function(c) {
return c.c.toLowerCase().includes(val);
}).slice(0, 10);
}
if (matches.length === 0) { dropdown.style.display = 'none'; return; }
dropdown.innerHTML = matches.map(function(m) {
return '<div class="ac-item" style="padding:6px 10px;cursor:pointer;color:#e0e0e0;font-size:0.85rem;border-bottom:1px solid #333;" data-cidade="' + escapeAttr(m.c) + '" data-uf="' + m.u + '">' +
escapeHtml(m.c) + ' <span style="color:#888;">/ ' + m.u + '</span></div>';
}).join('');
dropdown.style.display = 'block';
});
dropdown.addEventListener('click', function(e) {
var item = e.target.closest('.ac-item');
if (!item) return;
input.value = item.dataset.cidade;
document.getElementById(estadoId).value = item.dataset.uf;
dropdown.style.display = 'none';
});
input.addEventListener('blur', function() {
setTimeout(function() { dropdown.style.display = 'none'; }, 200);
});
input.addEventListener('keydown', function(e) {
if (e.key === 'Escape') dropdown.style.display = 'none';
});
}
// Carregar cidades imediatamente
carregarCidades();
</script>
</div><!-- end admin-content -->
</body>
</html>