From be10a8d99e072e2cc811c8f19c0b0798f77f21aa 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 17:15:51 +0800 Subject: [PATCH] Revised the coding style with the JavaScript arrow functions for the transaction form. --- src/accounting/static/js/account-selector.js | 8 ++------ .../static/js/journal-entry-editor.js | 8 ++------ src/accounting/static/js/transaction-form.js | 20 +++++-------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/accounting/static/js/account-selector.js b/src/accounting/static/js/account-selector.js index 8ebc416..25b8801 100644 --- a/src/accounting/static/js/account-selector.js +++ b/src/accounting/static/js/account-selector.js @@ -106,13 +106,9 @@ class AccountSelector { this.#more.classList.add("d-none"); this.#filterOptions(); }; - this.#clearButton.onclick = () => { - this.#entryEditor.clearAccount(); - }; + this.#clearButton.onclick = () => this.#entryEditor.clearAccount(); for (const option of this.#options) { - option.onclick = () => { - this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-offset-needed")); - }; + option.onclick = () => this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-offset-needed")); } this.#query.addEventListener("input", () => { this.#filterOptions(); diff --git a/src/accounting/static/js/journal-entry-editor.js b/src/accounting/static/js/journal-entry-editor.js index 5e67608..6ca90a4 100644 --- a/src/accounting/static/js/journal-entry-editor.js +++ b/src/accounting/static/js/journal-entry-editor.js @@ -218,12 +218,8 @@ class JournalEntryEditor { this.#originalEntryControl.onclick = () => OriginalEntrySelector.start(this, this.originalEntryId); this.#originalEntryDelete.onclick = () => this.clearOriginalEntry(); this.#summaryControl.onclick = () => SummaryEditor.start(this, this.summary); - this.#accountControl.onclick = () => { - AccountSelector.start(this, this.entryType); - } - this.#amount.onchange = () => { - this.#validateAmount(); - } + this.#accountControl.onclick = () => AccountSelector.start(this, this.entryType); + this.#amount.onchange = () => this.#validateAmount(); this.#element.onsubmit = () => { if (this.#validate()) { if (this.entry === null) { diff --git a/src/accounting/static/js/transaction-form.js b/src/accounting/static/js/transaction-form.js index 388a4e8..3001ff5 100644 --- a/src/accounting/static/js/transaction-form.js +++ b/src/accounting/static/js/transaction-form.js @@ -128,12 +128,8 @@ class TransactionForm { }; this.#resetDeleteCurrencyButtons(); this.#initializeDragAndDropReordering(); - this.#date.onchange = () => { - this.#validateDate(); - }; - this.#note.onchange = () => { - this.#validateNote(); - } + this.#date.onchange = () => this.#validateDate(); + this.#note.onchange = () => this.#validateNote(); this.#element.onsubmit = () => { return this.#validate(); }; @@ -435,9 +431,7 @@ class CurrencySubForm { this.#debit = debitElement === null? null: new DebitCreditSideSubForm(this, debitElement, "debit"); const creditElement = document.getElementById(this.#prefix + "-credit"); this.#credit = creditElement == null? null: new DebitCreditSideSubForm(this, creditElement, "credit"); - this.#codeSelect.onchange = () => { - this.#code.value = this.#codeSelect.value; - }; + this.#codeSelect.onchange = () => this.#code.value = this.#codeSelect.value; this.deleteButton.onclick = () => { this.element.parentElement.removeChild(this.element); this.form.deleteCurrency(this); @@ -607,9 +601,7 @@ class DebitCreditSideSubForm { this.entries = Array.from(document.getElementsByClassName(this.#prefix)).map((element) => new JournalEntrySubForm(this, element)); this.#total = document.getElementById(this.#prefix + "-total"); this.#addEntryButton = document.getElementById(this.#prefix + "-add-entry"); - this.#addEntryButton.onclick = () => { - JournalEntryEditor.addNew(this); - }; + this.#addEntryButton.onclick = () => JournalEntryEditor.addNew(this); this.#resetDeleteJournalEntryButtons(); this.#initializeDragAndDropReordering(); } @@ -882,9 +874,7 @@ class JournalEntrySubForm { this.#amount = document.getElementById(this.#prefix + "-amount"); this.#amountText = document.getElementById(this.#prefix + "-amount-text"); this.deleteButton = document.getElementById(this.#prefix + "-delete"); - this.#control.onclick = () => { - JournalEntryEditor.edit(this, this.#originalEntryId.value, this.#originalEntryId.dataset.date, this.#originalEntryId.dataset.text, this.#summary.value, this.#accountCode.value, this.#accountCode.dataset.text, this.#amount.value, this.#amount.dataset.min); - }; + this.#control.onclick = () => JournalEntryEditor.edit(this, this.#originalEntryId.value, this.#originalEntryId.dataset.date, this.#originalEntryId.dataset.text, this.#summary.value, this.#accountCode.value, this.#accountCode.dataset.text, this.#amount.value, this.#amount.dataset.min); this.deleteButton.onclick = () => { this.element.parentElement.removeChild(this.element); this.side.deleteJournalEntry(this);