1/** 2 * Volume do curso enviado junto do evento de matrÃcula. São linhas da nota de 3 * histórico do HubSpot, não propriedades do contato. 4 * @returns {Object} 5 */ 6function detalhes_matricula_hubspot () { 7 const detalhes = {}; 8 if ( ! window.curso ) return detalhes; 9 // Zeros ficam de fora: curso presencial não tem módulo nem aula, e a linha 10 // "Módulos: 0" só poluiria a nota. 11 if ( Number( window.curso.qtd_modulos ) > 0 ) detalhes.qtd_modulos = window.curso.qtd_modulos; 12 if ( Number( window.curso.qtd_aulas ) > 0 ) detalhes.qtd_aulas = window.curso.qtd_aulas; 13 return detalhes; 14} 15 16document.addEventListener("DOMContentLoaded", async function () { 17 const btns_matricular = document.querySelectorAll(".-js-matricule-se"); 18 const modal_pagamento = document.querySelector(".-js-pagamento-modal"); 19 const trava_modal = document.querySelector(".-js-trava-modal"); 20 window.curso.o_projeto = await vAPI_cursos.get_project_by_id( curso.projeto ); 21 if (btns_matricular.length) { 22 btns_matricular.forEach((btn) => { 23 // CLICK NO BOTÃO DE MATRICULE-SE 24 btn.addEventListener("click", function (event) { 25 const current_btn = event.target; 26 if (!current_btn.classList.contains("-js-loading-user")) { 27 if (window.user && window.access_token) { 28 if (!current_btn.dataset.navigate) { 29 event.preventDefault(); 30 current_btn.innerHTML = "Aguarde..."; 31 vAPI_cursos.check_is_free(curso.id).then((is_free) => { 32 // à GRATUÃTO 33 if (is_free) { 34 vAPI_cursos.update_progresso( window.access_token, curso.id, curso.projeto, curso.id ).then(() => { 35 // Só atualiza o botão após a matrÃcula ser confirmada pela API 36 update_buttons_enrolled( window.access_token, true ); 37 // SEND TO HUBSPOT 38 vAPI_cursos.send_evento_hubspot( { 39 access_token: window.access_token, 40 user: window.user, 41 curso: window.curso, 42 evento: 'MatrÃcula Curso', 43 detalhes: detalhes_matricula_hubspot(), 44 // Zera o progresso: as propriedades descrevem o curso 45 // atual, e quem começa um curso novo não está mais no 46 // ponto em que parou no anterior. 47 propriedades: { progresso_do_curso: 0 }, 48 } ); 49 }); 50 // à PAGO 51 } else { 52 vAPI_cursos.get_perfil( window.access_token ).then( perfil => { 53 // ATENÃÃO: perfil_schema usa chaves em PT. Este validate só funcionará 54 // corretamente após a API retornar o perfil com chaves em português. 55 vAPI_cursos.validar_perfil( perfil ).then( validar => { 56 if ( validar ) { // Perfil COMPLETO, abre o modal de pagamento 57 if (modal_pagamento) { 58 modal_pagamento.classList.add( "active" ); 59 } 60 } else { // Perfil INCOMPLETO, abre o modal de exigência de perfil preenchido 61 if (trava_modal) { 62 trava_modal.classList.add( "active" ); 63 } 64 } 65 }); 66 }); 67 // Para curso pago, atualiza o botão
67imediatamente (sem nova matrÃcula ainda) 68 update_buttons_enrolled( window.access_token, true ); 69 } 70 }); 71 } 72 } else { 73 event.preventDefault(); 74 const modal = document.querySelector( ".user-modal__container" ); 75 if (modal) modal.classList.add("active"); 76 } 77 } else { 78 event.preventDefault(); 79 } 80 }); 81 }); 82 } 83 // CLOSE MODAL PAYMENT 84 if (modal_pagamento) { 85 const btn_close_modal_payment = modal_pagamento.querySelector( ".-js-close-pagamento-modal" ); 86 if (btn_close_modal_payment) { 87 btn_close_modal_payment.addEventListener("click", (event) => { 88 event.preventDefault(); 89 modal_pagamento.classList.remove("active"); 90 vAPI_cursos 91 .check_payment_curso(curso.id, window.access_token) 92 .then((response) => { 93 if (response && response.status) { 94 btns_matricular.forEach((btn) => { 95 if ("desconhecido" == response.status) { 96 btn.innerHTML = "Matricule-se"; 97 } else if (response.status == "concluido") { 98 btn.innerHTML = "Ir para as aulas"; 99 } else if (response.status == "pendente") { 100 btn.innerHTML = "Aguardando pagamento"; 101 } 102 }); 103 104 if ("concluido" == response.status) { 105 vAPI_cursos 106 .update_progresso( 107 window.access_token, 108 window.curso.id, 109 window.curso.projeto, 110 window.curso.id 111 ) 112 .then(() => { 113 // SEND HUBSPOT 114 update_buttons_enrolled( 115 window.access_token, 116 true, 117 ); 118 vAPI_cursos.send_evento_hubspot( { 119 access_token: window.access_token, 120 user: window.user, 121 curso: window.curso, 122 evento: 'MatrÃcula Curso', 123 detalhes: detalhes_matricula_hubspot(), 124 // Zera o progresso: as propriedades descrevem o curso 125 // atual, e quem começa um curso novo não está mais no 126 // ponto em que parou no anterior. 127 propriedades: { progresso_do_curso: 0 }, 128 } ); 129 }); 130 } 131 } 132 }); 133 }); 134 } 135 } 136 137 window.addEventListener("message", (event) => { 138 if (event.origin == helper_api_cursos.api_cursos) { 139 if (closeModalMatricula) { 140 closeModalMatricula.click(); 141 } 142 } 143 }); 144 145 const closeModalMatricula = document.querySelector( 146 ".-js-close-matricula-modal" 147 ); 148 if (closeModalMatricula) { 149 closeModalMatricula.addEventListener("click", function () { 150 const modal_matricula = document.querySelector( 151 ".-js-matriculado-modal" 152 ); 153 if (modal_matricula) modal_matricula.classList.remove("active"); 154 }); 155 } 156 157 const closeModalTrava = document.querySelector( ".-js-close-trava-modal" ); 158 if (closeModalTrava) { 159 closeModalTrava.addEventListener("click", function (event) { 160 event.preventDefault(); 161 trava_modal.classList.remove("active"); 162 }); 163 } 164 165 if (curso.id) { 166 vAPI_cursos.get_media_avaliacao_curso(curso.id).then((avaliacoes) => { 167 const constainer_notas = 168 document.querySelector(".-js-notes-display"); 169 let stars = avaliacoes?.data?.media; 170 let qtd = avaliacoes?.data?.qtd; 171 if (qtd) { 172 const porcent_icons = 173 document.querySelector(".-js-porcent-star"); 174 const star_text = document.querySelector(".-js-stars-num"); 175 176 const porcentagem = (stars * 100) / 5; 177 stars = Math.round(stars * 100) / 100; 178 stars = Number.isInteger(stars) 179 ? `${stars},0` 180 : stars.toString().replace(".", ","); 181 182 star_text.innerHTML = stars; 183 porcent_icons.style.width = `${porcentagem}%`; 184 constainer_notas.classList.remove("-hide"); 185 186 document.querySelector( 187 ".rating-amount strong" 188 ).innerHTML = `${qtd} avaliações`; 189 } else { 190 if (constainer_notas) constainer_notas.classList.add("-hide"); 191 } 192 }); 193 } 194}); 195 196firebase.auth().onAuthStateChanged((user) => { 197 window.user = user; 198 if (user) { 199 user.getIdToken().then(function (accessToken) { 200 window.access_token = accessToken; 201 update_buttons_enrolled(accessToken, false); 202 // CONSTRUIR SRC DO IFRAME DE COMPRA 203 vAPI_cursos.check_is_free(curso.id).then((is_free) => { 204 if (!is_free) { 205 const src_iframe_payment = vAPI_cursos.get_url_payment( 206 accessToken, 207 curso.id, 208 window.location.href 209 ); 210 if (src_iframe_payment) { 211 const modal_pagamento = document.querySelector(
212 ".-js-pagamento-modal" 213 ); 214 modal_pagamento.querySelector("iframe").src = 215 src_iframe_payment; 216 } 217 } 218 }); 219 }); 220 } else { 221 const btns = document.querySelectorAll(".-js-matricule-se"); 222 btns.forEach((btn) => { 223 btn.innerHTML = "Matricule-se"; 224 btn.classList.remove("-js-loading-user"); 225 }); 226 } 227 228}); 229 230// VERIFICANDO SE Jà ESTà MATRICULADO NO CURSO 231function update_buttons_enrolled(accessToken, click_matricula) { 232 const btns = document.querySelectorAll(".-js-matricule-se"); 233 const modal_matricula = document.querySelector(".-js-matriculado-modal"); 234 const modal_btn_matricula = document.querySelector(".-js-aula-link"); 235 let current_aula = ""; 236 // Checa o progresso do usuário no curso 237 vAPI_cursos.get_progresso(accessToken).then((progressos) => { 238 let ids_progresso = progressos.map((conteudo) => conteudo.conteudo); 239 // Checa se o curso está cadastrado no progresso do usuário 240 if ( ids_progresso.includes( curso.id.toString() ) ) { 241 vAPI_cursos.get_links_aulas(curso.id).then((aulas) => { 242 const debug = urlChecker(); 243 if (debug.debug){ 244 dump(aulas, 'console', 'aulas'); 245 dump(btns, 'console', 'btns'); 246 } 247 if ( aulas && typeof aulas == "object" && Object.keys(aulas).length ) { 248 249 vAPI_cursos.check_is_free(curso.id).then((is_free) => { 250 if (aulas.presencial) { 251 current_aula = aulas.presencial; 252 } else { 253 254 ids_aulas = Object.keys(aulas); 255 ids_aulas.sort((a, b) => { 256 return aulas[a].order - aulas[b].order; 257 }); 258 const primeira_aula = ids_aulas[0]; 259 current_aula = aulas[primeira_aula].link; 260 261 } 262 263 if (is_free) { 264 265 if (aulas.presencial) { 266 if (click_matricula == true){ 267 envio = vAPI_cursos.send_mail_registration(window.access_token, window.curso.id); 268 } 269 } else { 270 for (id_aula in aulas) { 271 if (ids_progresso.includes(id_aula)) { 272 current_aula = aulas[id_aula].link; 273 } 274 } 275 } 276 277 btns.forEach((btn) => { 278 btn.href = current_aula; 279 btn.innerHTML = "Ir para as aulas"; 280 btn.dataset.navigate = true; 281 btn.classList.remove("-js-loading-user"); 282 }); 283 if (modal_btn_matricula) 284 modal_btn_matricula.href = current_aula; 285 286 if (modal_matricula && click_matricula == true) 287 modal_matricula.classList.add("active"); 288 289 } else { 290 vAPI_cursos.check_payment_curso(curso.id, accessToken).then((response) => { 291 if (response && response.status) { 292 btns.forEach((btn) => { 293 if ("desconhecido" == response.status) { 294 btn.innerHTML = "Matricule-se"; 295 } else if (response.status == "concluido") { 296 btn.href = current_aula; 297 btn.dataset.navigate = true; 298 btn.innerHTML = "Ir para as aulas"; 299 300 // Adiciona o ID do curs
300o no progresso do usuário para liberar acesso as aulas 301 vAPI_cursos.update_progresso( window.access_token, curso.id, curso.projeto, curso.id ).then( resposta => { 302 if(resposta.curso != curso.id){ 303 console.warn('Erro ao atualizar progresso do curso'); 304 } 305 } ); 306 307 } else if (response.status == "pendente") { 308 btn.innerHTML = "Aguardando pagamento"; 309 } 310 btn.classList.remove("-js-loading-user"); 311 }); 312 } 313 }); 314 } 315 }); 316 } 317 }); 318 } else { // Caso não tenha o ID do curso no progresso do usuário, ele não está matriculado 319 320 // Checar se o curso é gratuito para alterar o botão 321 vAPI_cursos.check_is_free(curso.id).then((is_free) => { 322 if (is_free) { 323 // Caso seja gratuito, altera o botão para "Matricule-se", pois não está cadastrado no progresso do usuário 324 btns.forEach((btn) => { 325 btn.innerHTML = "Matricule-se"; 326 btn.classList.remove("-js-loading-user"); 327 }); 328 if (modal_matricula) modal_matricula.classList.remove("active"); 329 330 } else { 331 // Caso seja pago, verifica o status do pagamento 332 vAPI_cursos.check_payment_curso(curso.id, accessToken).then((response) => { 333 if (response && response.status) { 334 btns.forEach((btn) => { 335 btn.classList.remove("-js-loading-user"); 336 if ("desconhecido" == response.status) { 337 btn.innerHTML = "Matricule-se"; 338 } else if (response.status == "concluido") { 339 // Adiciona o ID do curso no progresso do usuário para liberar acesso as aulas 340 vAPI_cursos.update_progresso( window.access_token, curso.id, curso.projeto, curso.id ).then( resposta => { 341 if(resposta.curso != curso.id){ 342 console.warn('Erro ao atualizar progresso do curso'); 343 } 344 } ); 345 vAPI_cursos.get_links_aulas(curso.id).then((aulas) => { 346 347 if (aulas.presencial) { 348 current_aula = aulas.presencial; 349 } else { 350 ids_aulas = Object.keys(aulas); 351 ids_aulas.sort((a, b) => { 352 return aulas[a].order - aulas[b].order; 353 }); 354 const primeira_aula = ids_aulas[0]; 355 current_aula = aulas[primeira_aula].link; 356 } 357 358 btn.href = current_aula; 359 btn.innerHTML = "Ir para as aulas"; 360 btn.dataset.navigate = true; 361 }); 362 btn.classList.remove("-js-loading-user"); 363 } else if (response.status == "pendente") { 364 btn.innerHTML = "Aguardando pagamento"; 365 } 366 }); 367 } 368 }); 369 } 370 }); 371 } 372 }).catch((erro) => { 373 // Sem o progresso não dá para saber se a aluna está matriculada, então o 374 // botão continua inerte (a classe -js-loading-user faz o clique não fazer 375 // nada). O que muda é o texto: antes ficava "Aguarde..." para sempre, sem 376 // nenhum sinal de que a API está fora. 377 console.error('[curso] falha ao consultar o progresso:', erro); 378 btns.forEach((btn) => { 379 btn.innerHTML = "IndisponÃvel no momento"; 380 btn.title = "Não foi possÃvel conectar ao servidor de cursos. Tente novamente em alguns minutos."; 381 }); 382 }); 383}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.