From 7ed13dc0af90efab285141c31ec2373e2d92c5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 23 Mar 2023 07:06:58 +0800 Subject: [PATCH] Replaced the JavaScript prefix attributes that are only used in the class constructors with the prefix constant variables in the constructor. --- src/accounting/static/js/account-selector.js | 20 +++---- .../static/js/journal-entry-form.js | 58 ++++++++----------- src/accounting/static/js/period-chooser.js | 10 +--- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/src/accounting/static/js/account-selector.js b/src/accounting/static/js/account-selector.js index 7fd617f..db6f186 100644 --- a/src/accounting/static/js/account-selector.js +++ b/src/accounting/static/js/account-selector.js @@ -40,12 +40,6 @@ class AccountSelector { */ #debitCredit; - /** - * The prefix of the HTML ID and class - * @type {string} - */ - #prefix; - /** * The button to clear the account * @type {HTMLButtonElement} @@ -91,14 +85,14 @@ class AccountSelector { constructor(lineItemEditor, debitCredit) { this.#lineItemEditor = lineItemEditor this.#debitCredit = debitCredit; - this.#prefix = "accounting-account-selector-" + debitCredit; - this.#query = document.getElementById(this.#prefix + "-query"); - this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result"); - this.#optionList = document.getElementById(this.#prefix + "-option-list"); + const prefix = "accounting-account-selector-" + debitCredit; + this.#query = document.getElementById(prefix + "-query"); + this.#queryNoResult = document.getElementById(prefix + "-option-no-result"); + this.#optionList = document.getElementById(prefix + "-option-list"); // noinspection JSValidateTypes - this.#options = Array.from(document.getElementsByClassName(this.#prefix + "-option")); - this.#more = document.getElementById(this.#prefix + "-more"); - this.#clearButton = document.getElementById(this.#prefix + "-btn-clear"); + this.#options = Array.from(document.getElementsByClassName(prefix + "-option")); + this.#more = document.getElementById(prefix + "-more"); + this.#clearButton = document.getElementById(prefix + "-btn-clear"); this.#more.onclick = () => { this.#more.classList.add("d-none"); this.#filterOptions(); diff --git a/src/accounting/static/js/journal-entry-form.js b/src/accounting/static/js/journal-entry-form.js index 4dab709..f7022ae 100644 --- a/src/accounting/static/js/journal-entry-form.js +++ b/src/accounting/static/js/journal-entry-form.js @@ -363,12 +363,6 @@ class CurrencySubForm { */ index; - /** - * The prefix of the HTML ID and class - * @type {string} - */ - #prefix; - /** * The control * @type {HTMLDivElement} @@ -427,16 +421,16 @@ class CurrencySubForm { this.element = element; this.form = form; this.index = parseInt(this.element.dataset.index); - this.#prefix = "accounting-currency-" + String(this.index); - this.#control = document.getElementById(this.#prefix + "-control"); - this.#error = document.getElementById(this.#prefix + "-error"); - this.no = document.getElementById(this.#prefix + "-no"); - this.#code = document.getElementById(this.#prefix + "-code"); - this.#codeSelect = document.getElementById(this.#prefix + "-code-select"); - this.deleteButton = document.getElementById(this.#prefix + "-delete"); - const debitElement = document.getElementById(this.#prefix + "-debit"); + const prefix = "accounting-currency-" + String(this.index); + this.#control = document.getElementById(prefix + "-control"); + this.#error = document.getElementById(prefix + "-error"); + this.no = document.getElementById(prefix + "-no"); + this.#code = document.getElementById(prefix + "-code"); + this.#codeSelect = document.getElementById(prefix + "-code-select"); + this.deleteButton = document.getElementById(prefix + "-delete"); + const debitElement = document.getElementById(prefix + "-debit"); this.#debit = debitElement === null? null: new DebitCreditSubForm(this, debitElement, "debit"); - const creditElement = document.getElementById(this.#prefix + "-credit"); + const creditElement = document.getElementById(prefix + "-credit"); this.#credit = creditElement == null? null: new DebitCreditSubForm(this, creditElement, "credit"); this.#codeSelect.onchange = () => this.#code.value = this.#codeSelect.value; this.deleteButton.onclick = () => { @@ -771,12 +765,6 @@ class LineItemSubForm { */ isMatched; - /** - * The prefix of the HTML ID and class - * @type {string} - */ - #prefix; - /** * The control * @type {HTMLDivElement} @@ -867,20 +855,20 @@ class LineItemSubForm { this.debitCredit = element.dataset.debitCredit; this.lineItemIndex = parseInt(element.dataset.lineItemIndex); this.isMatched = element.classList.contains("accounting-matched-line-item"); - this.#prefix = "accounting-currency-" + element.dataset.currencyIndex + "-" + this.debitCredit + "-" + this.lineItemIndex; - this.#control = document.getElementById(this.#prefix + "-control"); - this.#error = document.getElementById(this.#prefix + "-error"); - this.no = document.getElementById(this.#prefix + "-no"); - this.#accountCode = document.getElementById(this.#prefix + "-account-code"); - this.#accountText = document.getElementById(this.#prefix + "-account-text"); - this.#description = document.getElementById(this.#prefix + "-description"); - this.#descriptionText = document.getElementById(this.#prefix + "-description-text"); - this.#originalLineItemId = document.getElementById(this.#prefix + "-original-line-item-id"); - this.#originalLineItemText = document.getElementById(this.#prefix + "-original-line-item-text"); - this.#offsets = document.getElementById(this.#prefix + "-offsets"); - this.#amount = document.getElementById(this.#prefix + "-amount"); - this.#amountText = document.getElementById(this.#prefix + "-amount-text"); - this.deleteButton = document.getElementById(this.#prefix + "-delete"); + const prefix = "accounting-currency-" + element.dataset.currencyIndex + "-" + this.debitCredit + "-" + this.lineItemIndex; + this.#control = document.getElementById(prefix + "-control"); + this.#error = document.getElementById(prefix + "-error"); + this.no = document.getElementById(prefix + "-no"); + this.#accountCode = document.getElementById(prefix + "-account-code"); + this.#accountText = document.getElementById(prefix + "-account-text"); + this.#description = document.getElementById(prefix + "-description"); + this.#descriptionText = document.getElementById(prefix + "-description-text"); + this.#originalLineItemId = document.getElementById(prefix + "-original-line-item-id"); + this.#originalLineItemText = document.getElementById(prefix + "-original-line-item-text"); + this.#offsets = document.getElementById(prefix + "-offsets"); + this.#amount = document.getElementById(prefix + "-amount"); + this.#amountText = document.getElementById(prefix + "-amount-text"); + this.deleteButton = document.getElementById(prefix + "-delete"); this.#control.onclick = () => this.debitCreditSubForm.currency.form.lineItemEditor.onEdit(this); this.deleteButton.onclick = () => { this.element.parentElement.removeChild(this.element); diff --git a/src/accounting/static/js/period-chooser.js b/src/accounting/static/js/period-chooser.js index be0a71d..abdf280 100644 --- a/src/accounting/static/js/period-chooser.js +++ b/src/accounting/static/js/period-chooser.js @@ -33,12 +33,6 @@ document.addEventListener("DOMContentLoaded", () => { */ class PeriodChooser { - /** - * The prefix of the HTML ID and class - * @type {string} - */ - prefix; - /** * The modal of the period chooser * @type {HTMLDivElement} @@ -56,8 +50,8 @@ class PeriodChooser { * */ constructor() { - this.prefix = "accounting-period-chooser"; - this.modal = document.getElementById(this.prefix + "-modal"); + const prefix = "accounting-period-chooser"; + this.modal = document.getElementById(prefix + "-modal"); for (const cls of [MonthTab, YearTab, DayTab, CustomTab]) { const tab = new cls(this); this.tabPlanes[tab.tabId()] = tab;