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:
parent
a2311aee24
commit
6d293a1aac
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
#}
|
||||
<div id="accounting-account-selector-{{ entry_type }}-modal" class="modal fade" data-entry-type="{{ entry_type }}" tabindex="-1" aria-labelledby="accounting-account-selector-{{ entry_type }}-modal-label" aria-hidden="true">
|
||||
<div id="accounting-account-selector-{{ entry_type }}-modal" class="modal fade accounting-account-selector" data-entry-type="{{ entry_type }}" tabindex="-1" aria-labelledby="accounting-account-selector-{{ entry_type }}-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
@ -19,7 +19,7 @@ summary-editor-modal.html: The modal of the summary editor
|
||||
Author: imacat@mail.imacat.idv.tw (imacat)
|
||||
First written: 2023/2/28
|
||||
#}
|
||||
<form id="accounting-summary-editor-{{ summary_editor.type }}">
|
||||
<form id="accounting-summary-editor-{{ summary_editor.type }}" class="accounting-summary-editor" data-entry-type="{{ summary_editor.type }}">
|
||||
<div id="accounting-summary-editor-{{ summary_editor.type }}-modal" class="modal fade" tabindex="-1" aria-labelledby="accounting-summary-editor-{{ summary_editor.type }}-modal-label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
Loading…
Reference in New Issue
Block a user