PageSourceSearch

https://nutrebem.prod.nutrebem.com.br/assets/controllers/student_school_controller-68b0921e.js

js nutrebem.com.br collected 2026-10-01 16:40:46 UTC 2,135 bytes, 66 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Cadastro de aluno, passo da escola: escolher a escola carrega as series dela e mostra o
4// endereco.
5//
6// Os dois selects sao do select2, que anuncia a troca com `.trigger("change")` do jQuery e
7// nao gera evento DOM nativo — um `change->` no data-action nao dispararia aqui.
8export default class extends Controller {
9  static targets = ["escola", "serie", "info", "nome", "endereco", "cidade", "cep"]
10  static values = { seriesUrl: String, escolaUrl: String }
11
12  connect() {
13    const opcoes = { theme: "bootstrap-5", width: "100%" }
14    $(this.escolaTarget).select2(opcoes)
15    $(this.serieTarget).select2(opcoes)
16
17    this.infoTarget.style.display = "none"
18
19    $(this.escolaTarget).on("change.escola", () => this.#trocouDeEscola())
20  }
21
22  disconnect() {
23    $(this.escolaTarget).off(".escola")
24  }
25
26  async #trocouDeEscola() {
27    this.serieTarget.disabled = false
28    await Promise.all([this.#carregarSeries(), this.#carregarEndereco()])
29  }
30
31  async #carregarSeries() {
32    const series = await this.#buscar(this.seriesUrlValue)
33    if (!series) return
34
35    this.serieTarget.replaceChildren(
36      ...series.map((s) => new Option(s.name ?? s, s.name ?? s))
37    )
38    $(this.serieTarget).trigger("change.select2")
39  }
40
41  async #carregarEndereco() {
42    const escola = await this.#buscar(this.escolaUrlValue)
43    if (!escola) return
44
45    this.infoTarget.style.display = "block"
46    ;[this.nomeTarget, this.enderecoTarget, this.cidadeTarget, this.cepTarget].forEach(
47      (el) => (el.textContent = "")
48    )
49
50    if (escola.address == null) {
51      this.nomeTarget.textContent = "Endereço não cadastrado"
52      return
53    }
54
55    this.enderecoTarget.textContent = `${escola.address} - ${escola.address_number}`
56    this.cidadeTarget.textContent = `${escola.city} - ${escola.state}`
57    this.cepTarget.textContent = `CEP: ${escola.zipcode}`
58  }
59
60  async #buscar(modelo) {
61    const resposta = await fetch(modelo.replace("ID_DA_ESCOLA", $(this.escolaTarget).val()), {
62      headers: { Accept: "application/json" },
63    })
64    return resposta.ok ? resposta.json() : null
65  }
66}

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.