Implantação da criação de romaneios
This commit is contained in:
@@ -10,7 +10,8 @@ import { Controller } from "@hotwired/stimulus"
|
||||
// plano inteiro. A regra de reconciliação (Romaneios::Importador) só funciona com
|
||||
// escrita por campo.
|
||||
export default class extends Controller {
|
||||
static targets = ["celula", "preview", "itemVeiculo", "motorista", "rotulo", "status", "linha", "busca", "contador"]
|
||||
static targets = ["celula", "preview", "itemVeiculo", "motorista", "rotulo", "status", "linha", "busca",
|
||||
"contador", "overlay", "caixaPreview", "tituloPreview"]
|
||||
static values = { url: String, pdfUrl: String, veiculo: String }
|
||||
|
||||
// Recarregar o PDF a cada tecla travaria a tela; 600ms depois do último save é o
|
||||
@@ -19,6 +20,10 @@ export default class extends Controller {
|
||||
|
||||
connect() {
|
||||
this.timerPreview = null
|
||||
// A prévia nasce fechada e DESATUALIZADA: o PDF só é gerado na primeira vez
|
||||
// que alguém pede para ver. Antes o iframe era montado a cada carregamento da
|
||||
// tela e gerava um PDF que muitas vezes ninguém olhava.
|
||||
this.previewDesatualizado = true
|
||||
// Com 72 carros a lista rola; sem isto, ao trocar de veículo o selecionado
|
||||
// pode nascer fora da área visível e parece que a seleção não pegou.
|
||||
const atual = this.itemVeiculoTargets.find((a) => a.dataset.atual === "1")
|
||||
@@ -124,12 +129,49 @@ export default class extends Controller {
|
||||
this.buscaTarget.focus()
|
||||
}
|
||||
|
||||
atualizarPreview() {
|
||||
// ── Prévia (sobreposição) ───────────────────────────────────────────────
|
||||
abrirPreview() {
|
||||
if (!this.hasOverlayTarget) return
|
||||
|
||||
this.overlayTarget.hidden = false
|
||||
// Trava o scroll do fundo: rolar a lista atrás de um modal aberto faz o
|
||||
// operador perder o lugar quando fecha.
|
||||
document.body.style.overflow = "hidden"
|
||||
if (this.previewDesatualizado) this.carregarPreview()
|
||||
}
|
||||
|
||||
fecharPreview() {
|
||||
if (!this.hasOverlayTarget || this.overlayTarget.hidden) return
|
||||
|
||||
this.overlayTarget.hidden = true
|
||||
document.body.style.overflow = ""
|
||||
}
|
||||
|
||||
// Clique no fundo escuro fecha; clique DENTRO da caixa não — senão mexer no
|
||||
// PDF fecharia a prévia sem querer.
|
||||
fecharPorFora(event) {
|
||||
if (this.hasCaixaPreviewTarget && this.caixaPreviewTarget.contains(event.target)) return
|
||||
this.fecharPreview()
|
||||
}
|
||||
|
||||
carregarPreview() {
|
||||
if (!this.hasPreviewTarget) return
|
||||
|
||||
// Cache-bust em vez de reload(): reload reinicializa o visualizador de PDF do
|
||||
// navegador e a tela pisca a cada salvamento.
|
||||
this.previewTarget.src =
|
||||
`${this.pdfUrlValue}?veiculo=${encodeURIComponent(this.veiculoValue)}&t=${Date.now()}`
|
||||
this.previewDesatualizado = false
|
||||
}
|
||||
|
||||
// Chamada depois de cada gravação. Com a prévia FECHADA não gera PDF nenhum —
|
||||
// só marca que o próximo "Ver prévia" precisa buscar de novo.
|
||||
atualizarPreview() {
|
||||
if (!this.hasOverlayTarget || this.overlayTarget.hidden) {
|
||||
this.previewDesatualizado = true
|
||||
return
|
||||
}
|
||||
this.carregarPreview()
|
||||
}
|
||||
|
||||
// ── Infra ───────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user