Added the "resetNo" method to the RecurringItemSubForm, CurrencySubForm, and LineItemSubForm forms to provide a simpler way to reset the order number, and removed the "elementId" getter and "no" setter.

This commit is contained in:
依瑪貓 2023-03-23 08:55:16 +08:00
parent 5f8b0dec98
commit cb397910f8
2 changed files with 18 additions and 51 deletions

View File

@ -180,10 +180,8 @@ class JournalEntryForm {
*/ */
#initializeDragAndDropReordering() { #initializeDragAndDropReordering() {
initializeDragAndDropReordering(this.#currencyList, () => { initializeDragAndDropReordering(this.#currencyList, () => {
const currencyId = Array.from(this.#currencyList.children).map((currency) => currency.id); for (const currency of this.#currencies) {
this.#currencies.sort((a, b) => currencyId.indexOf(a.elementId) - currencyId.indexOf(b.elementId)); currency.resetNo();
for (let i = 0; i < this.#currencies.length; i++) {
this.#currencies[i].no = i + 1;
} }
}); });
} }
@ -436,21 +434,12 @@ class CurrencySubForm {
} }
/** /**
* Returns the element ID. * Reset the order number.
* *
* @return {string|null} element ID
*/ */
get elementId() { resetNo() {
return this.#element.id; const siblings = Array.from(this.#element.parentElement.children);
} this.#no.value = String(siblings.indexOf(this.#element) + 1);
/**
* Sets the order number.
*
* @param value {number} the order number
*/
set no(value) {
this.#no.value = String(value);
} }
/** /**
@ -713,10 +702,8 @@ class DebitCreditSubForm {
*/ */
#initializeDragAndDropReordering() { #initializeDragAndDropReordering() {
initializeDragAndDropReordering(this.#lineItemList, () => { initializeDragAndDropReordering(this.#lineItemList, () => {
const lineItemId = Array.from(this.#lineItemList.children).map((lineItem) => lineItem.id); for (const lineItem of this.lineItems) {
this.lineItems.sort((a, b) => lineItemId.indexOf(a.elementId) - lineItemId.indexOf(b.elementId)); lineItem.resetNo();
for (let i = 0; i < this.lineItems.length; i++) {
this.lineItems[i].no = i + 1;
} }
}); });
} }
@ -900,21 +887,12 @@ class LineItemSubForm {
} }
/** /**
* Returns the element ID. * Reset the order number.
* *
* @return {string|null} element ID
*/ */
get elementId() { resetNo() {
return this.#element.id; const siblings = Array.from(this.#element.parentElement.children);
} this.#no.value = String(siblings.indexOf(this.#element) + 1);
/**
* Sets the order number.
*
* @param value {number} the order number
*/
set no(value) {
this.#no.value = String(value);
} }
/** /**

View File

@ -313,10 +313,8 @@ class RecurringExpenseIncomeSubForm {
*/ */
#initializeDragAndDropReordering() { #initializeDragAndDropReordering() {
initializeDragAndDropReordering(this.#itemList, () => { initializeDragAndDropReordering(this.#itemList, () => {
const itemId = Array.from(this.#itemList.children).map((item) => item.id); for (const item of this.#items) {
this.#items.sort((a, b) => itemId.indexOf(a.elementId) - itemId.indexOf(b.elementId)); item.resetNo();
for (let i = 0; i < this.#items.length; i++) {
this.#items[i].no = i + 1;
} }
}); });
} }
@ -463,21 +461,12 @@ class RecurringItemSubForm {
} }
/** /**
* Returns the element ID. * Reset the order number.
* *
* @return {string|null} element ID
*/ */
get elementId() { resetNo() {
return this.#element.id; const siblings = Array.from(this.#element.parentElement.children);
} this.#no.value = String(siblings.indexOf(this.#element) + 1);
/**
* Sets the order number.
*
* @param value {number} the order number
*/
set no(value) {
this.#no.value = String(value);
} }
/** /**