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.

This commit is contained in:
依瑪貓 2023-03-19 10:20:40 +08:00
parent b69a519904
commit 5d0757c845
3 changed files with 15 additions and 15 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -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();