Added the JavaScript getInstances method to the SummaryEditor and AccountSelector classes, so that it is easier to deal with the case when the debit and credit versions are not both exist.
This commit is contained in:
@ -206,4 +206,19 @@ class AccountSelector {
|
||||
this.#clearButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the account selector instances.
|
||||
*
|
||||
* @param entryEditor {JournalEntryEditor} the journal entry editor
|
||||
* @return {{debit: AccountSelector, credit: AccountSelector}}
|
||||
*/
|
||||
static getInstances(entryEditor) {
|
||||
const selectors = {}
|
||||
const modals = Array.from(document.getElementsByClassName("accounting-account-selector"));
|
||||
for (const modal of modals) {
|
||||
selectors[modal.dataset.entryType] = new AccountSelector(entryEditor, modal.dataset.entryType);
|
||||
}
|
||||
return selectors;
|
||||
}
|
||||
}
|
||||
|
@ -200,13 +200,13 @@ class JournalEntryEditor {
|
||||
* The summary editors
|
||||
* @type {{debit: SummaryEditor, credit: SummaryEditor}}
|
||||
*/
|
||||
#summaryEditors = {};
|
||||
#summaryEditors;
|
||||
|
||||
/**
|
||||
* The account selectors
|
||||
* @type {{debit: AccountSelector, credit: AccountSelector}}
|
||||
*/
|
||||
#accountSelectors = {};
|
||||
#accountSelectors;
|
||||
|
||||
/**
|
||||
* The original entry selector
|
||||
@ -236,12 +236,8 @@ 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");
|
||||
for (const entryType of ["debit", "credit"]) {
|
||||
this.#summaryEditors[entryType] = new SummaryEditor(this, entryType);
|
||||
}
|
||||
for (const entryType of ["debit", "credit"]) {
|
||||
this.#accountSelectors[entryType] = new AccountSelector(this, entryType);
|
||||
}
|
||||
this.#summaryEditors = SummaryEditor.getInstances(this);
|
||||
this.#accountSelectors = AccountSelector.getInstances(this);
|
||||
this.originalEntrySelector = new OriginalEntrySelector();
|
||||
this.#originalEntryControl.onclick = () => this.originalEntrySelector.onOpen(this, this.originalEntryId)
|
||||
this.#originalEntryDelete.onclick = () => this.clearOriginalEntry();
|
||||
|
@ -242,6 +242,21 @@ class SummaryEditor {
|
||||
}
|
||||
this.tabPlanes.general.switchToMe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary editor instances.
|
||||
*
|
||||
* @param entryEditor {JournalEntryEditor} the journal entry editor
|
||||
* @return {{debit: SummaryEditor, credit: SummaryEditor}}
|
||||
*/
|
||||
static getInstances(entryEditor) {
|
||||
const editors = {}
|
||||
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
|
||||
for (const form of forms) {
|
||||
editors[form.dataset.entryType] = new SummaryEditor(entryEditor, form.dataset.entryType);
|
||||
}
|
||||
return editors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user