From 35dc513760d467217e0be8d15902edd086d45e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 18 Mar 2023 19:44:15 +0800 Subject: [PATCH] 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. --- src/accounting/static/js/journal-entry-editor.js | 6 ++---- src/accounting/static/js/summary-editor.js | 10 +++++----- .../transaction/include/summary-editor-modal.html | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/accounting/static/js/journal-entry-editor.js b/src/accounting/static/js/journal-entry-editor.js index 7e9b544..9041fea 100644 --- a/src/accounting/static/js/journal-entry-editor.js +++ b/src/accounting/static/js/journal-entry-editor.js @@ -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; } diff --git a/src/accounting/static/js/summary-editor.js b/src/accounting/static/js/summary-editor.js index 6e93ed4..dad7d2f 100644 --- a/src/accounting/static/js/summary-editor.js +++ b/src/accounting/static/js/summary-editor.js @@ -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"); diff --git a/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html b/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html index 67a1aa2..559a2b0 100644 --- a/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html +++ b/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html @@ -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 #} -
+