From 5d0757c845183a2e67796d653feeea6e64e8b051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 19 Mar 2023 10:20:40 +0800 Subject: [PATCH] Added the JavaScript JournalEntryEditor instance to the parameters of the constructor of the JavaScript OriginalEntrySelector class, so that it always have access to the JournalEntryEditor instance. Removed the JournalEntryEditor instance from the parameters of the onOpen method of the JournalEntryEditor class. --- .../static/js/journal-entry-editor.js | 4 ++-- .../static/js/original-entry-selector.js | 24 +++++++++---------- src/accounting/static/js/summary-editor.js | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/accounting/static/js/journal-entry-editor.js b/src/accounting/static/js/journal-entry-editor.js index 6ac41d2..1f9eb09 100644 --- a/src/accounting/static/js/journal-entry-editor.js +++ b/src/accounting/static/js/journal-entry-editor.js @@ -238,8 +238,8 @@ class JournalEntryEditor { this.#amountError = document.getElementById(this.#prefix + "-amount-error"); this.#summaryEditors = SummaryEditor.getInstances(this); this.#accountSelectors = AccountSelector.getInstances(this); - this.originalEntrySelector = new OriginalEntrySelector(); - this.#originalEntryControl.onclick = () => this.originalEntrySelector.onOpen(this, this.originalEntryId) + this.originalEntrySelector = new OriginalEntrySelector(this); + this.#originalEntryControl.onclick = () => this.originalEntrySelector.onOpen(this.originalEntryId) this.#originalEntryDelete.onclick = () => this.clearOriginalEntry(); this.#summaryControl.onclick = () => this.#summaryEditors[this.entryType].onOpen(); this.#accountControl.onclick = () => this.#accountSelectors[this.entryType].onOpen(); diff --git a/src/accounting/static/js/original-entry-selector.js b/src/accounting/static/js/original-entry-selector.js index f7eb2db..b006128 100644 --- a/src/accounting/static/js/original-entry-selector.js +++ b/src/accounting/static/js/original-entry-selector.js @@ -28,6 +28,12 @@ */ class OriginalEntrySelector { + /** + * The journal entry editor + * @type {JournalEntryEditor} + */ + entryEditor; + /** * The prefix of the HTML ID and class * @type {string} @@ -64,12 +70,6 @@ class OriginalEntrySelector { */ #optionById; - /** - * The journal entry editor - * @type {JournalEntryEditor} - */ - entryEditor; - /** * The currency code * @type {string} @@ -84,8 +84,10 @@ class OriginalEntrySelector { /** * Constructs an original entry selector. * + * @param entryEditor {JournalEntryEditor} the journal entry editor */ - constructor() { + constructor(entryEditor) { + this.entryEditor = entryEditor; this.#query = document.getElementById(this.#prefix + "-query"); this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result"); this.#optionList = document.getElementById(this.#prefix + "-option-list"); @@ -174,13 +176,11 @@ class OriginalEntrySelector { /** * The callback when the original entry selector is shown. * - * @param entryEditor {JournalEntryEditor} the journal entry editor * @param originalEntryId {string|null} the ID of the original entry */ - onOpen(entryEditor, originalEntryId = null) { - this.entryEditor = entryEditor - this.#currencyCode = entryEditor.getCurrencyCode(); - this.#entryType = entryEditor.entryType; + onOpen(originalEntryId = null) { + this.#currencyCode = this.entryEditor.getCurrencyCode(); + this.#entryType = this.entryEditor.entryType; for (const option of this.#options) { option.setActive(option.id === originalEntryId); } diff --git a/src/accounting/static/js/summary-editor.js b/src/accounting/static/js/summary-editor.js index 404e60f..9dc07e8 100644 --- a/src/accounting/static/js/summary-editor.js +++ b/src/accounting/static/js/summary-editor.js @@ -132,7 +132,7 @@ class SummaryEditor { this.currentTab = this.tabPlanes.general; this.#initializeSuggestedAccounts(); this.summary.onchange = () => this.#onSummaryChange(); - this.#offsetButton.onclick = () => this.#entryEditor.originalEntrySelector.onOpen(this.#entryEditor); + this.#offsetButton.onclick = () => this.#entryEditor.originalEntrySelector.onOpen(); this.#form.onsubmit = () => { if (this.currentTab.validate()) { this.#submit();