From b3777cffbf0b9096f88f7ec9ae30416044da19f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 4 Mar 2023 07:53:31 +0800 Subject: [PATCH] Replaced the traditional function expressions with ES6 arrow function expressions in the JavaScript for the transaction form. --- src/accounting/static/js/transaction-form.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/accounting/static/js/transaction-form.js b/src/accounting/static/js/transaction-form.js index 5cf93e8..13e25c6 100644 --- a/src/accounting/static/js/transaction-form.js +++ b/src/accounting/static/js/transaction-form.js @@ -22,7 +22,7 @@ */ // Initializes the page JavaScript. -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener("DOMContentLoaded", () => { initializeCurrencyForms(); initializeJournalEntries(); initializeFormValidation(); @@ -68,14 +68,14 @@ function initializeCurrencyForms() { const btnNew = document.getElementById("accounting-btn-new-currency"); const currencyList = document.getElementById("accounting-currency-list"); const deleteButtons = Array.from(document.getElementsByClassName("accounting-btn-delete-currency")); - const onReorder = function () { + const onReorder = () => { const currencies = Array.from(currencyList.children); for (let i = 0; i < currencies.length; i++) { const no = document.getElementById(currencies[i].dataset.prefix + "-no"); no.value = String(i + 1); } }; - btnNew.onclick = function () { + btnNew.onclick = () => { const currencies = Array.from(document.getElementsByClassName("accounting-currency")); let maxIndex = 0; for (const currency of currencies) { @@ -107,7 +107,7 @@ function initializeCurrencyForms() { */ function initializeBtnDeleteCurrency(button) { const target = document.getElementById(button.dataset.target); - button.onclick = function () { + button.onclick = () => { target.parentElement.removeChild(target); resetDeleteCurrencyButtons(); }; @@ -161,7 +161,7 @@ function initializeNewEntryButton(button) { const formSummaryError = document.getElementById("accounting-entry-form-summary-error"); const formAmount = document.getElementById("accounting-entry-form-amount"); const formAmountError = document.getElementById("accounting-entry-form-amount-error"); - button.onclick = function () { + button.onclick = () => { entryForm.dataset.currencyIndex = button.dataset.currencyIndex; entryForm.dataset.entryType = button.dataset.entryType; entryForm.dataset.entryIndex = button.dataset.entryIndex; @@ -191,7 +191,7 @@ function initializeNewEntryButton(button) { * @param entryList {HTMLUListElement} the journal entry list. */ function initializeJournalEntryListReorder(entryList) { - initializeDragAndDropReordering(entryList, function () { + initializeDragAndDropReordering(entryList, () => { const entries = Array.from(entryList.children); for (let i = 0; i < entries.length; i++) { const no = document.getElementById(entries[i].dataset.prefix + "-no"); @@ -216,7 +216,7 @@ function initializeJournalEntry(entry) { const formSummaryControl = document.getElementById("accounting-entry-form-summary-control"); const formSummary = document.getElementById("accounting-entry-form-summary"); const formAmount = document.getElementById("accounting-entry-form-amount"); - control.onclick = function () { + control.onclick = () => { entryForm.dataset.currencyIndex = entry.dataset.currencyIndex; entryForm.dataset.entryType = entry.dataset.entryType; entryForm.dataset.entryIndex = entry.dataset.entryIndex; @@ -252,7 +252,7 @@ function initializeJournalEntryFormModal() { const formAmount = document.getElementById("accounting-entry-form-amount"); const modal = document.getElementById("accounting-entry-form-modal"); formAmount.onchange = validateJournalEntryAmount; - entryForm.onsubmit = function () { + entryForm.onsubmit = () => { if (validateJournalEntryForm()) { saveJournalEntryForm(); bootstrap.Modal.getInstance(modal).hide(); @@ -398,7 +398,7 @@ function initializeDeleteJournalEntryButton(button) { const currencyIndex = target.dataset.currencyIndex; const entryType = target.dataset.entryType; const currency = document.getElementById("accounting-currency-" + currencyIndex); - button.onclick = function () { + button.onclick = () => { target.parentElement.removeChild(target); resetDeleteJournalEntryButtons(button.dataset.sameClass); updateBalance(currencyIndex, entryType);