Revised the #initializeSummaryEditors method of the JavaScript JournalEntryEditor class to construct the SummaryEditor instances with the entry type instead of the form element. Replaced the form element with the entry type in the constructor of the SummaryEditor class. Removed the unused accounting-summary-editor class and data-entry-type attributes from the template of the summary editor.

This commit is contained in:
依瑪貓 2023-03-18 19:44:15 +08:00
parent 01861f0b6a
commit 35dc513760
3 changed files with 8 additions and 10 deletions

View File

@ -259,10 +259,8 @@ class JournalEntryEditor {
*/
#initializeSummaryEditors() {
const editors = {};
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
for (const form of forms) {
const summaryEditor = new SummaryEditor(this, form);
editors[summaryEditor.entryType] = summaryEditor;
for (const entryType of ["debit", "credit"]) {
editors[entryType] = new SummaryEditor(this, entryType);
}
return editors;
}

View File

@ -110,13 +110,13 @@ class SummaryEditor {
* Constructs a summary editor.
*
* @param entryEditor {JournalEntryEditor} the journal entry editor
* @param form {HTMLFormElement} the summary editor form
* @param entryType {string} the entry type, either "debit" or "credit"
*/
constructor(entryEditor, form) {
constructor(entryEditor, entryType) {
this.#entryEditor = entryEditor;
this.#form = form;
this.entryType = form.dataset.entryType;
this.prefix = "accounting-summary-editor-" + form.dataset.entryType;
this.entryType = entryType;
this.prefix = "accounting-summary-editor-" + entryType;
this.#form = document.getElementById(this.prefix);
this.#modal = document.getElementById(this.prefix + "-modal");
this.summary = document.getElementById(this.prefix + "-summary");
this.#offsetButton = document.getElementById(this.prefix + "-offset");

View File

@ -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 }}" class="accounting-summary-editor" data-entry-type="{{ summary_editor.type }}">
<form id="accounting-summary-editor-{{ 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">