Revised the JavaScript to initialize the SummaryEditor instances in JournalEntryEditor, so that the journal entry editor holds the SummaryEditor instances. It can find the SummaryEditor instance without needing to invoke its static methods. Removed the redundant static methods from the SummaryEditor class.

This commit is contained in:
2023-03-18 18:25:17 +08:00
parent 46e34bb89a
commit 12fbe36b9a
2 changed files with 36 additions and 46 deletions

View File

@ -196,6 +196,12 @@ class JournalEntryEditor {
*/
amount = "";
/**
* The summary editors
* @type {{debit: SummaryEditor, credit: SummaryEditor}}
*/
#summaryEditors;
/**
* Constructs a new journal entry editor.
*
@ -218,9 +224,10 @@ class JournalEntryEditor {
this.#accountError = document.getElementById(this.#prefix + "-account-error")
this.#amount = document.getElementById(this.#prefix + "-amount");
this.#amountError = document.getElementById(this.#prefix + "-amount-error");
this.#summaryEditors = this.#initializeSummaryEditors();
this.#originalEntryControl.onclick = () => OriginalEntrySelector.start(this, this.originalEntryId);
this.#originalEntryDelete.onclick = () => this.clearOriginalEntry();
this.#summaryControl.onclick = () => SummaryEditor.start(this);
this.#summaryControl.onclick = () => this.#summaryEditors[this.entryType].onOpen();
this.#accountControl.onclick = () => AccountSelector.start(this);
this.#amount.onchange = () => this.#validateAmount();
this.#element.onsubmit = () => {
@ -236,6 +243,21 @@ class JournalEntryEditor {
};
}
/**
* Initializes the summary editors.
*
* @return {{debit: SummaryEditor, credit: SummaryEditor}} the summary editors
*/
#initializeSummaryEditors() {
const editors = {};
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
for (const form of forms) {
const summaryEditor = new SummaryEditor(this, form);
editors[summaryEditor.entryType] = summaryEditor;
}
return editors;
}
/**
* Saves the original entry from the original entry selector.
*