@@ -7,108 +7,112 @@ import './lista.mjs';
7
7
/**
8
8
* Identifica o id do voluntário cujo perfil será exibido
9
9
*/
10
- document . querySelectorAll ( "tr" ) . forEach ( ( tr ) => {
11
- tr . addEventListener ( "click" , async ( ) => {
12
- const idPerfilVoluntario = tr . id ;
13
-
14
- /**
15
- * Exibe as informações mais relevantes do voluntário na tela de perfil
16
- */
17
- const docRef = doc ( db , "voluntario" , idPerfilVoluntario ) ;
18
- const perfil = await getDoc ( docRef ) ;
19
-
20
- if ( perfil . exists ( ) ) {
21
- //console.log("Document data:", perfil.data());
22
-
23
- /**
24
- * Dados Pessoais
25
- */
26
- document . getElementById ( "nomeCompletoDoVoluntario" ) . value = perfil . data ( ) . nome_completo_voluntario ;
27
- document . getElementById ( "cpfDoVoluntario" ) . value = perfil . data ( ) . cpf_voluntario ;
28
- document . getElementById ( "emailDoVoluntario" ) . value = perfil . data ( ) . contato . email_voluntario ;
29
- document . getElementById ( "telefoneDoVoluntario" ) . value = perfil . data ( ) . contato . celular_voluntario ;
30
-
31
- ( perfil . data ( ) . sexo_voluntario === "Masculino" )
32
- ? document . getElementById ( "sexoMasculino" ) . checked = true
33
- : document . getElementById ( "sexoFeminino" ) . checked = true ;
34
-
35
- perfil . data ( ) . faixa_etaria_voluntario . forEach ( ( faixaEtaria ) => {
36
- document . getElementById ( "faixaEtariaDoVoluntario" ) . value += faixaEtaria ;
37
- } ) ;
38
-
39
- /**
40
- * Contato de Emergência
41
- */
42
- document . getElementById ( "nomeContatoDoVoluntario" ) . value = perfil . data ( ) . contato . emergencia . nome_contato_emergencia ;
43
- document . getElementById ( "telefoneContatoDoVoluntario" ) . value = perfil . data ( ) . contato . emergencia . telefone_contato_emergencia ;
44
-
45
- /**
46
- * Endereço do Voluntário
47
- */
48
- document . getElementById ( "cepDoVoluntario" ) . setAttribute ( "readonly" , true ) ;
49
- document . getElementById ( "cepDoVoluntario" ) . value = perfil . data ( ) . endereco . cep ;
50
-
51
- document . getElementById ( "enderecoDoVoluntario" ) . value = perfil . data ( ) . endereco . logradouro ;
52
- document . getElementById ( "bairroDoVoluntario" ) . value = perfil . data ( ) . endereco . bairro ;
53
- document . getElementById ( "cidadeDoVoluntario" ) . value = perfil . data ( ) . endereco . cidade ;
54
- document . getElementById ( "estadoDoVoluntario" ) . value = perfil . data ( ) . endereco . estado ;
10
+ document . getElementById ( "corpoTabelaDeListagemDeVoluntarios" ) . addEventListener ( "click" , ( ) => {
11
+ document . querySelectorAll ( "tr" ) . forEach ( ( tr ) => {
12
+ tr . addEventListener ( "click" , async ( ) => {
13
+ const idPerfilVoluntario = tr . id ;
55
14
56
15
/**
57
- * Dados Adicionais
16
+ * Exibe as informações mais relevantes do voluntário na tela de perfil
58
17
*/
59
- document . getElementById ( "ascendente" ) . setAttribute ( "hidden" , true ) ;
60
- if ( perfil . data ( ) . descendencia_voluntario . descendente_japones === true ) {
61
- document . getElementById ( "descendenteSim" ) . checked = true ;
62
- document . getElementById ( "ascendente" ) . removeAttribute ( "hidden" ) ;
18
+ const docRef = doc ( db , "voluntario" , idPerfilVoluntario ) ;
19
+ const perfil = await getDoc ( docRef ) ;
20
+
21
+ if ( perfil . exists ( ) ) {
22
+ // Limpa os campos do modal de perfil do voluntário se houver algum valor
23
+ clearInputData ( ) ;
24
+ //console.log("Document data:", perfil.data());
25
+
26
+ /**
27
+ * Dados Pessoais
28
+ */
29
+ document . getElementById ( "nomeCompletoDoVoluntario" ) . value = perfil . data ( ) . nome_completo_voluntario ;
30
+ document . getElementById ( "cpfDoVoluntario" ) . value = perfil . data ( ) . cpf_voluntario ;
31
+ document . getElementById ( "emailDoVoluntario" ) . value = perfil . data ( ) . contato . email_voluntario ;
32
+ document . getElementById ( "telefoneDoVoluntario" ) . value = perfil . data ( ) . contato . celular_voluntario ;
33
+
34
+ ( perfil . data ( ) . dados_pessoais . sexo_voluntario === "Masculino" )
35
+ ? document . getElementById ( "sexoMasculino" ) . checked = true
36
+ : document . getElementById ( "sexoFeminino" ) . checked = true ;
37
+
38
+ perfil . data ( ) . dados_pessoais . faixa_etaria . forEach ( ( faixaEtaria ) => {
39
+ document . getElementById ( "faixaEtariaDoVoluntario" ) . value += faixaEtaria ;
40
+ } ) ;
41
+
42
+ /**
43
+ * Contato de Emergência
44
+ */
45
+ document . getElementById ( "nomeContatoDoVoluntario" ) . value = perfil . data ( ) . contato . emergencia . nome_contato_emergencia ;
46
+ document . getElementById ( "telefoneContatoDoVoluntario" ) . value = perfil . data ( ) . contato . emergencia . telefone_contato_emergencia ;
47
+
48
+ /**
49
+ * Endereço do Voluntário
50
+ */
51
+ document . getElementById ( "cepDoVoluntario" ) . setAttribute ( "readonly" , true ) ;
52
+ document . getElementById ( "cepDoVoluntario" ) . value = perfil . data ( ) . endereco . cep ;
53
+
54
+ document . getElementById ( "enderecoDoVoluntario" ) . value = perfil . data ( ) . endereco . logradouro ;
55
+ document . getElementById ( "bairroDoVoluntario" ) . value = perfil . data ( ) . endereco . bairro ;
56
+ document . getElementById ( "cidadeDoVoluntario" ) . value = perfil . data ( ) . endereco . cidade ;
57
+ document . getElementById ( "estadoDoVoluntario" ) . value = perfil . data ( ) . endereco . estado ;
58
+
59
+ /**
60
+ * Dados Adicionais
61
+ */
62
+ document . getElementById ( "ascendente" ) . setAttribute ( "hidden" , true ) ;
63
+ if ( perfil . data ( ) . dados_pessoais . descendencia . possui_descendencia_japonesa === true ) {
64
+ document . getElementById ( "descendenteSim" ) . checked = true ;
65
+ document . getElementById ( "ascendente" ) . removeAttribute ( "hidden" ) ;
66
+ } else {
67
+ document . getElementById ( "descendenteNao" ) . checked = true ;
68
+ document . getElementById ( "ascendente" ) . setAttribute ( "hidden" , true ) ;
69
+ }
70
+
71
+ perfil . data ( ) . dados_pessoais . descendencia . ascendencia_voluntario . forEach ( ( ascendencia ) => {
72
+ document . getElementById ( "ascendenciaDoVoluntarioDescendente" ) . value += ascendencia ;
73
+ } ) ;
74
+
75
+ // Idiomas
76
+ // Conhecimento em Ingl~Es
77
+ document . getElementById ( "idiomaVoluntarioIngles" ) . removeAttribute ( "checked" , true ) ;
78
+ ( perfil . data ( ) . carreira . escolaridade . conhecimento_linguas . idioma_ingles === true )
79
+ ? document . getElementById ( "idiomaVoluntarioIngles" ) . checked = true
80
+ : document . getElementById ( "idiomaVoluntarioIngles" ) . removeAttribute ( "checked" ) ;
81
+ // Conhecimento em Japonês
82
+ document . getElementById ( "idiomaVoluntarioJapones" ) . removeAttribute ( "checked" , true ) ;
83
+ ( perfil . data ( ) . carreira . escolaridade . conhecimento_linguas . idioma_japones === true )
84
+ ? document . getElementById ( "idiomaVoluntarioJapones" ) . checked = true
85
+ : document . getElementById ( "idiomaVoluntarioJapones" ) . removeAttribute ( "checked" ) ;
86
+ // Conhecimento em Espanhol
87
+ document . getElementById ( "idiomaVoluntarioEspanhol" ) . removeAttribute ( "checked" , true ) ;
88
+ ( perfil . data ( ) . carreira . escolaridade . conhecimento_linguas . idioma_espanhol === true )
89
+ ? document . getElementById ( "idiomaVoluntarioEspanhol" ) . checked = true
90
+ : document . getElementById ( "idiomaVoluntarioEspanhol" ) . removeAttribute ( "checked" ) ;
91
+
92
+ // Conhecimento em Libras
93
+ ( perfil . data ( ) . carreira . escolaridade . conhecimento_linguas . linguagem_de_sinais_brasileira === true )
94
+ ? document . getElementById ( "conhecimentoLibrasSim" ) . checked = true
95
+ : document . getElementById ( "conhecimentoLibrasNao" ) . checked = true ;
96
+
97
+ // Treinamento em Primeiros Socorros
98
+ ( perfil . data ( ) . treinamento_primeiros_socorros === true )
99
+ ? document . getElementById ( "treinamentoSim" ) . checked = true
100
+ : document . getElementById ( "treinamentoNao" ) . checked = true ;
101
+
102
+ // Escolaridade
103
+ perfil . data ( ) . carreira . escolaridade . nivel_escolaridade . forEach ( ( nivelEscolaridade ) => {
104
+ document . getElementById ( "nivelEscolaridadeVoluntario" ) . value += nivelEscolaridade ;
105
+ } ) ;
106
+
107
+ // Trabalho
108
+ ( perfil . data ( ) . carreira . profissao . trabalha_atualmente === true )
109
+ ? document . getElementById ( "trabalhaSim" ) . checked = true
110
+ : document . getElementById ( "trabalhaNao" ) . checked = true ;
63
111
} else {
64
- document . getElementById ( "descendenteNao" ) . checked = true ;
112
+ // perfil.data() retornará undefined
113
+ console . log ( "Não foi possível encontrar o perfil deste voluntário." ) ;
65
114
}
66
-
67
- perfil . data ( ) . descendencia_voluntario . ascendencia_voluntario . forEach ( ( ascendencia ) => {
68
- document . getElementById ( "ascendenciaDoVoluntarioDescendente" ) . value += ascendencia ;
69
- } ) ;
70
-
71
- // Idiomas
72
- // Conhecimento em Ingl~Es
73
- document . getElementById ( "idiomaVoluntarioIngles" ) . removeAttribute ( "checked" , true ) ;
74
- ( perfil . data ( ) . escolaridade_voluntario . conhecimento_voluntario . idioma_ingles === true )
75
- ? document . getElementById ( "idiomaVoluntarioIngles" ) . setAttribute ( "checked" , true )
76
- : document . getElementById ( "idiomaVoluntarioIngles" ) . removeAttribute ( "checked" ) ;
77
- // Conhecimento em Japonês
78
- document . getElementById ( "idiomaVoluntarioJapones" ) . removeAttribute ( "checked" , true ) ;
79
- ( perfil . data ( ) . escolaridade_voluntario . conhecimento_voluntario . idioma_japones === true )
80
- ? document . getElementById ( "idiomaVoluntarioJapones" ) . setAttribute ( "checked" , true )
81
- : document . getElementById ( "idiomaVoluntarioJapones" ) . removeAttribute ( "checked" ) ;
82
- // Conhecimento em Espanhol
83
- document . getElementById ( "idiomaVoluntarioEspanhol" ) . removeAttribute ( "checked" , true ) ;
84
- ( perfil . data ( ) . escolaridade_voluntario . conhecimento_voluntario . idioma_espanhol === true )
85
- ? document . getElementById ( "idiomaVoluntarioEspanhol" ) . setAttribute ( "checked" , true )
86
- : document . getElementById ( "idiomaVoluntarioEspanhol" ) . removeAttribute ( "checked" ) ;
87
-
88
- // Conhecimento em Libras
89
- ( perfil . data ( ) . escolaridade_voluntario . conhecimento_voluntario . linguagem_libras === true )
90
- ? document . getElementById ( "conhecimentoLibrasSim" ) . checked = true
91
- : document . getElementById ( "conhecimentoLibrasNao" ) . checked = true ;
92
-
93
- // Treinamento em Primeiros Socorros
94
- ( perfil . data ( ) . escolaridade_voluntario . treinamento_primeiros_socorros === true )
95
- ? document . getElementById ( "treinamentoSim" ) . checked = true
96
- : document . getElementById ( "treinamentoNao" ) . checked = true ;
97
-
98
- // Escolaridade
99
- perfil . data ( ) . escolaridade_voluntario . nivel_escolaridade_voluntario . forEach ( ( nivelEscolaridade ) => {
100
- document . getElementById ( "nivelEscolaridadeVoluntario" ) . value += nivelEscolaridade ;
101
- } ) ;
102
-
103
- // Trabalho
104
- ( perfil . data ( ) . carreira_voluntario . trabalha_atualmente === true )
105
- ? document . getElementById ( "trabalhaSim" ) . checked = true
106
- : document . getElementById ( "trabalhaNao" ) . checked = true ;
107
- } else {
108
- // perfil.data() retornará undefined
109
- console . log ( "Não foi possível encontrar o perfil deste voluntário." ) ;
110
- }
111
-
115
+ } ) ;
112
116
} ) ;
113
117
} ) ;
114
118
0 commit comments