diff --git a/src/accounting/static/js/account-selector.js b/src/accounting/static/js/account-selector.js index 9d05c08..7bfc4c0 100644 --- a/src/accounting/static/js/account-selector.js +++ b/src/accounting/static/js/account-selector.js @@ -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; + } } diff --git a/src/accounting/static/js/journal-entry-editor.js b/src/accounting/static/js/journal-entry-editor.js index 345cfbc..6ac41d2 100644 --- a/src/accounting/static/js/journal-entry-editor.js +++ b/src/accounting/static/js/journal-entry-editor.js @@ -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(); diff --git a/src/accounting/static/js/summary-editor.js b/src/accounting/static/js/summary-editor.js index 147eb93..404e60f 100644 --- a/src/accounting/static/js/summary-editor.js +++ b/src/accounting/static/js/summary-editor.js @@ -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; + } } /** diff --git a/src/accounting/templates/accounting/transaction/include/account-selector-modal.html b/src/accounting/templates/accounting/transaction/include/account-selector-modal.html index 377edcb..7658244 100644 --- a/src/accounting/templates/accounting/transaction/include/account-selector-modal.html +++ b/src/accounting/templates/accounting/transaction/include/account-selector-modal.html @@ -19,7 +19,7 @@ account-selector-modal.html: The modal for the account selector Author: imacat@mail.imacat.idv.tw (imacat) First written: 2023/2/25 #} -