1import AutoSubmitController from "controllers/auto_submit_controller" 2 3export default class extends AutoSubmitController { 4 static targets = ["capacity", "capacityToggle", "error", "summary", "availability", "ticket"] 5 6 save(event) { 7 // The series publish button has its own destination and still uses Turbo. 8 if (event.submitter?.formAction && event.submitter.formAction !== this.form.action) { 9 return 10 } 11 event.preventDefault() 12 this.changed() 13 } 14 15 async submitForm() { 16 try { 17 const response = await fetch(this.form.action, { 18 method: this.form.method.toUpperCase(), 19 body: new FormData(this.form), 20 headers: { Accept: "application/json", "X-Requested-With": "XMLHttpRequest" }, 21 credentials: "same-origin", 22 }) 23 const data = await response.json() 24 25 if (!response.ok) { 26 this.showError(data.error || "Changes couldn't be saved. Try again.", Boolean(data.errors?.capacity)) 27 return 28 } 29 30 this.showError("") 31 if (data.capacity) this.updateCapacity(data.capacity) 32 } catch { 33 this.showError("Changes couldn't be saved. Check your connection and try again.") 34 } 35 } 36 37 showError(message, invalidCapacity = false) { 38 this.errorTarget.textContent = message 39 this.errorTarget.hidden = !message 40 this.capacityTarget.setAttribute("aria-invalid", String(invalidCapacity)) 41 } 42 43 updateCapacity({ limit, used }) { 44 const remaining = limit > 0 ? Math.max(limit - used, 0) : null 45 this.capacityToggleTarget.dataset.capacityToggleDefaultValue = used + 1 46 this.summaryTarget.hidden = limit === 0 47 this.availabilityTarget.textContent = `${used} of ${limit} places used · ${remaining} remaining.` 48 49 this.ticketTargets.forEach((ticket) => { 50 const ticketRemaining = ticket.dataset.ticketRemaining === "" ? null : Number(ticket.dataset.ticketRemaining) 51 const limits = [ticketRemaining, remaining].filter((value) => value !== null) 52 ticket.textContent = limits.length ? `${Math.min(...limits)} seats remaining` : "Unlimited" 53 }) 54 } 55}
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.