La scelta della lista passa da un wizard a tre passi, con anteprima del conteggio e lista congelata solo dopo la conferma. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
899 B
JavaScript
35 lines
899 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class extends Controller {
|
|
static targets = ["intent"]
|
|
|
|
refresh() {
|
|
this.persistOpenSections()
|
|
this.setIntent("preview")
|
|
this.element.requestSubmit()
|
|
}
|
|
|
|
apply() {
|
|
this.persistOpenSections()
|
|
this.setIntent("apply")
|
|
}
|
|
|
|
persistOpenSections() {
|
|
this.element.querySelectorAll("input[data-open-section]").forEach((input) => input.remove())
|
|
this.element.querySelectorAll("details[data-section]").forEach((details) => {
|
|
if (!details.open) return
|
|
|
|
const input = document.createElement("input")
|
|
input.type = "hidden"
|
|
input.name = "open_sections[]"
|
|
input.value = details.dataset.section
|
|
input.setAttribute("data-open-section", "")
|
|
this.element.appendChild(input)
|
|
})
|
|
}
|
|
|
|
setIntent(value) {
|
|
if (this.hasIntentTarget) this.intentTarget.value = value
|
|
}
|
|
}
|