, correção para gerara prévia do romaneio
This commit is contained in:
@@ -10,8 +10,10 @@ 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 {
|
||||
// `overlay` é o <details> da prévia (nome mantido para não renomear em vão);
|
||||
// `caixaPreview` saiu junto com o modal.
|
||||
static targets = ["celula", "preview", "itemVeiculo", "motorista", "rotulo", "status", "linha", "busca",
|
||||
"contador", "overlay", "caixaPreview", "tituloPreview"]
|
||||
"contador", "overlay", "tituloPreview"]
|
||||
static values = { url: String, pdfUrl: String, veiculo: String }
|
||||
|
||||
// Recarregar o PDF a cada tecla travaria a tela; 600ms depois do último save é o
|
||||
@@ -129,38 +131,10 @@ export default class extends Controller {
|
||||
this.buscaTarget.focus()
|
||||
}
|
||||
|
||||
// ── Prévia (sobreposição) ───────────────────────────────────────────────
|
||||
abrirPreview() {
|
||||
if (!this.hasOverlayTarget) return
|
||||
|
||||
// Classe + atributo: só o atributo `hidden` não basta, porque a utility
|
||||
// `.flex` do Tailwind vence o `[hidden] { display:none }` do preflight —
|
||||
// foi assim que o modal ficou preso na tela do /admin/romaneios/13.
|
||||
this.overlayTarget.hidden = false
|
||||
this.overlayTarget.classList.remove("hidden")
|
||||
this.overlayTarget.classList.add("flex")
|
||||
// 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
|
||||
this.overlayTarget.classList.remove("flex")
|
||||
this.overlayTarget.classList.add("hidden")
|
||||
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()
|
||||
}
|
||||
|
||||
// ── Prévia (bloco <details> nativo) ─────────────────────────────────────
|
||||
// Abrir e fechar é do NAVEGADOR — o <details> não depende deste controller,
|
||||
// e é isso que mantém a prévia viva quando o JavaScript não carrega. O que
|
||||
// sobra aqui é só recarregar a folha depois de uma edição.
|
||||
carregarPreview() {
|
||||
if (!this.hasPreviewTarget) return
|
||||
|
||||
@@ -171,16 +145,25 @@ export default class extends Controller {
|
||||
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.
|
||||
// Chamada depois de cada gravação. Com o bloco FECHADO não gera PDF nenhum —
|
||||
// o `loading="lazy"` do iframe já garante isso, e recarregar o src de um
|
||||
// iframe escondido forçaria o servidor a montar um PDF que ninguém vai ver.
|
||||
atualizarPreview() {
|
||||
if (!this.hasOverlayTarget || this.overlayTarget.hidden) {
|
||||
if (!this.hasOverlayTarget || !this.overlayTarget.open) {
|
||||
this.previewDesatualizado = true
|
||||
return
|
||||
}
|
||||
this.carregarPreview()
|
||||
}
|
||||
|
||||
// O operador pode abrir a prévia depois de ter editado: neste caso o iframe
|
||||
// ainda mostra a folha antiga, então recarregamos no momento da abertura.
|
||||
aoAbrirPreview() {
|
||||
if (this.hasOverlayTarget && this.overlayTarget.open && this.previewDesatualizado) {
|
||||
this.carregarPreview()
|
||||
}
|
||||
}
|
||||
|
||||
// ── Infra ───────────────────────────────────────────────────────────────
|
||||
gravar(linhaId, campo, valor, input, botao, aoConcluir) {
|
||||
this.status("Salvando…")
|
||||
|
||||
Reference in New Issue
Block a user