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

View File

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