Shortened the names of the #filterAccountOptions, #getAccountCodeUsedInForm, and #shouldAccountOptionShow methods to #filterOptions, #getCodesUsedInForm, and #shouldOptionShow, respectively, in the JavaScript AccountSelector class.

This commit is contained in:
依瑪貓 2023-03-10 14:03:38 +08:00
parent 107d161379
commit edf0c00e34

View File

@ -98,7 +98,7 @@ class AccountSelector {
this.#clearButton = document.getElementById(this.#prefix + "-btn-clear"); this.#clearButton = document.getElementById(this.#prefix + "-btn-clear");
this.#more.onclick = () => { this.#more.onclick = () => {
this.#more.classList.add("d-none"); this.#more.classList.add("d-none");
this.#filterAccountOptions(); this.#filterOptions();
}; };
this.#clearButton.onclick = () => { this.#clearButton.onclick = () => {
AccountSelector.#formAccountControl.classList.remove("accounting-not-empty"); AccountSelector.#formAccountControl.classList.remove("accounting-not-empty");
@ -117,19 +117,19 @@ class AccountSelector {
}; };
} }
this.#query.addEventListener("input", () => { this.#query.addEventListener("input", () => {
this.#filterAccountOptions(); this.#filterOptions();
}); });
} }
/** /**
* Filters the account options. * Filters the options.
* *
*/ */
#filterAccountOptions() { #filterOptions() {
const codesInUse = this.#getAccountCodeUsedInForm(); const codesInUse = this.#getCodesUsedInForm();
let shouldAnyShow = false; let shouldAnyShow = false;
for (const option of this.#options) { for (const option of this.#options) {
const shouldShow = this.#shouldAccountOptionShow(option, this.#more, codesInUse, this.#query); const shouldShow = this.#shouldOptionShow(option, this.#more, codesInUse, this.#query);
if (shouldShow) { if (shouldShow) {
option.classList.remove("d-none"); option.classList.remove("d-none");
shouldAnyShow = true; shouldAnyShow = true;
@ -151,7 +151,7 @@ class AccountSelector {
* *
* @return {string[]} the account codes that are used in the form * @return {string[]} the account codes that are used in the form
*/ */
#getAccountCodeUsedInForm() { #getCodesUsedInForm() {
const accountCodes = Array.from(document.getElementsByClassName("accounting-" + this.#prefix + "-account-code")); const accountCodes = Array.from(document.getElementsByClassName("accounting-" + this.#prefix + "-account-code"));
const inUse = [AccountSelector.#formAccount.dataset.code]; const inUse = [AccountSelector.#formAccount.dataset.code];
for (const accountCode of accountCodes) { for (const accountCode of accountCodes) {
@ -161,15 +161,15 @@ class AccountSelector {
} }
/** /**
* Returns whether an account option should show. * Returns whether an option should show.
* *
* @param option {HTMLLIElement} the account option * @param option {HTMLLIElement} the option
* @param more {HTMLLIElement} the more account element * @param more {HTMLLIElement} the more element
* @param inUse {string[]} the account codes that are used in the form * @param inUse {string[]} the account codes that are used in the form
* @param query {HTMLInputElement} the query element, if any * @param query {HTMLInputElement} the query element, if any
* @return {boolean} true if the account option should show, or false otherwise * @return {boolean} true if the option should show, or false otherwise
*/ */
#shouldAccountOptionShow(option, more, inUse, query) { #shouldOptionShow(option, more, inUse, query) {
const isQueryMatched = () => { const isQueryMatched = () => {
if (query.value === "") { if (query.value === "") {
return true; return true;
@ -198,7 +198,7 @@ class AccountSelector {
#onOpen() { #onOpen() {
this.#query.value = ""; this.#query.value = "";
this.#more.classList.remove("d-none"); this.#more.classList.remove("d-none");
this.#filterAccountOptions(); this.#filterOptions();
for (const option of this.#options) { for (const option of this.#options) {
if (option.dataset.code === AccountSelector.#formAccount.dataset.code) { if (option.dataset.code === AccountSelector.#formAccount.dataset.code) {
option.classList.add("active"); option.classList.add("active");