mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Templates move to the database (Admin -> Logbook templates: add, edit, delete, restore the built-in ones). The built-in preventive maintenance set is added once on first use; deletions stick. A template can set the entry type, logbook (picking the matching component) and certificate - Template list shows "Name — Part 43 App. A (c)(6), (c)(23)" instead of the doubled parentheses - Component total time and time since overhaul are worked out from the entry's airframe total time (current times shifted by the difference); blank when the entry predates the overhaul; typing them stops the automatic updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
// Fills a new logbook entry from a template: the wording, and when the
|
|
// template sets them, the entry type, the logbook (which also picks the
|
|
// matching component) and the kind of certificate, unless one is chosen.
|
|
export default class extends Controller {
|
|
static targets = [ "template", "text", "entryType", "logType", "certificate" ]
|
|
|
|
apply() {
|
|
const option = this.templateTarget.selectedOptions[0]
|
|
if (!option?.dataset.text) return
|
|
if (this.textTarget.value.trim() && !confirm("Replace the entry text with this template?")) return
|
|
const { text, entryType, logType, certificate } = option.dataset
|
|
this.textTarget.value = text
|
|
if (entryType && this.hasEntryTypeTarget) this.entryTypeTarget.value = entryType
|
|
if (logType && this.hasLogTypeTarget && this.logTypeTarget.value !== logType) {
|
|
this.logTypeTarget.value = logType
|
|
this.logTypeTarget.dispatchEvent(new Event("change", { bubbles: true }))
|
|
}
|
|
if (certificate && this.hasCertificateTarget && !this.certificateTarget.value) this.certificateTarget.value = certificate
|
|
this.textTarget.focus()
|
|
}
|
|
}
|