Replaced the JavaScript prefix attributes that are only used in the class constructors with the prefix constant variables in the constructor.

This commit is contained in:
依瑪貓 2023-03-23 07:06:58 +08:00
parent 52807c5322
commit 7ed13dc0af
3 changed files with 32 additions and 56 deletions

View File

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

View File

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

View File

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