Revised the JavaScript DescriptionEditor class so that the #reset() method is triggered by the #onDescriptionChange event, but not the onOpen event, so that user-edited description updates also clear the tab planes.

This commit is contained in:
依瑪貓 2023-04-03 10:06:19 +08:00
parent 08732c1e66
commit 8033921181

View File

@ -199,6 +199,7 @@ class DescriptionEditor {
* *
*/ */
#onDescriptionChange() { #onDescriptionChange() {
this.#reset();
this.description = this.description.trim(); this.description = this.description.trim();
for (const tabPlane of [this.tabPlanes.recurring, this.tabPlanes.bus, this.tabPlanes.travel, this.tabPlanes.general]) { for (const tabPlane of [this.tabPlanes.recurring, this.tabPlanes.bus, this.tabPlanes.travel, this.tabPlanes.general]) {
if (tabPlane.populate()) { if (tabPlane.populate()) {
@ -208,6 +209,17 @@ class DescriptionEditor {
this.tabPlanes.annotation.populate(); this.tabPlanes.annotation.populate();
} }
/**
* Resets the description editor.
*
*/
#reset() {
for (const tabPlane of Object.values(this.tabPlanes)) {
tabPlane.reset();
}
this.tabPlanes.general.switchToMe();
}
/** /**
* Updates the current suggested accounts. * Updates the current suggested accounts.
* *
@ -289,10 +301,9 @@ class DescriptionEditor {
* *
*/ */
onOpen() { onOpen() {
this.#reset();
this.#setConfirmedAccount();
this.description = this.lineItemEditor.description === null? "": this.lineItemEditor.description; this.description = this.lineItemEditor.description === null? "": this.lineItemEditor.description;
this.#onDescriptionChange(); this.#onDescriptionChange();
this.#setConfirmedAccount();
} }
/** /**
@ -311,18 +322,6 @@ class DescriptionEditor {
this.selectAccount(this.#confirmedAccount); this.selectAccount(this.#confirmedAccount);
} }
/**
* Resets the description editor.
*
*/
#reset() {
this.description = "";
for (const tabPlane of Object.values(this.tabPlanes)) {
tabPlane.reset();
}
this.tabPlanes.general.switchToMe();
}
/** /**
* Returns the description editor instances. * Returns the description editor instances.
* *