Revised the JavaScript to initialize the AccountSelector instances in JournalEntryEditor, so that the journal entry editor holds the AccountSelector instances. It can find the AccountSelector instance without needing to invoke its static methods. Removed the redundant static methods from the AccountSelector class.
This commit is contained in:
@ -202,6 +202,12 @@ class JournalEntryEditor {
|
||||
*/
|
||||
#summaryEditors;
|
||||
|
||||
/**
|
||||
* The account selectors
|
||||
* @type {{debit: AccountSelector, credit: AccountSelector}}
|
||||
*/
|
||||
#accountSelectors;
|
||||
|
||||
/**
|
||||
* Constructs a new journal entry editor.
|
||||
*
|
||||
@ -225,10 +231,11 @@ class JournalEntryEditor {
|
||||
this.#amount = document.getElementById(this.#prefix + "-amount");
|
||||
this.#amountError = document.getElementById(this.#prefix + "-amount-error");
|
||||
this.#summaryEditors = this.#initializeSummaryEditors();
|
||||
this.#accountSelectors = this.#initializeAccountSelectors();
|
||||
this.#originalEntryControl.onclick = () => OriginalEntrySelector.start(this, this.originalEntryId);
|
||||
this.#originalEntryDelete.onclick = () => this.clearOriginalEntry();
|
||||
this.#summaryControl.onclick = () => this.#summaryEditors[this.entryType].onOpen();
|
||||
this.#accountControl.onclick = () => AccountSelector.start(this);
|
||||
this.#accountControl.onclick = () => this.#accountSelectors[this.entryType].onOpen();
|
||||
this.#amount.onchange = () => this.#validateAmount();
|
||||
this.#element.onsubmit = () => {
|
||||
if (this.#validate()) {
|
||||
@ -258,6 +265,19 @@ class JournalEntryEditor {
|
||||
return editors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the account selectors.
|
||||
*
|
||||
* @return {{debit: AccountSelector, credit: AccountSelector}} the account selectors
|
||||
*/
|
||||
#initializeAccountSelectors() {
|
||||
const selectors = {};
|
||||
for (const entryType of ["debit", "credit"]) {
|
||||
selectors[entryType] = new AccountSelector(this, entryType);
|
||||
}
|
||||
return selectors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the original entry from the original entry selector.
|
||||
*
|
||||
|
Reference in New Issue
Block a user