Revised the saveDescription method of the JavaScript JournalEntryLineItemEditor to accept the description editor instead of the separated description and account values.

This commit is contained in:
依瑪貓 2023-04-03 10:25:47 +08:00
parent f2a2fcdd32
commit e1a0380628
2 changed files with 14 additions and 15 deletions

View File

@ -122,7 +122,7 @@ class DescriptionEditor {
* The selected account. * The selected account.
* @type {DescriptionEditorAccount|null} * @type {DescriptionEditorAccount|null}
*/ */
#selectedAccount = null; selectedAccount = null;
/** /**
* The tab planes * The tab planes
@ -200,7 +200,7 @@ class DescriptionEditor {
*/ */
#onDescriptionChange() { #onDescriptionChange() {
this.#resetTabPlanes(); this.#resetTabPlanes();
this.#selectedAccount = null; this.selectedAccount = null;
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()) {
@ -282,9 +282,9 @@ class DescriptionEditor {
if (selectedAccount !== null) { if (selectedAccount !== null) {
selectedAccount.setActive(true); selectedAccount.setActive(true);
} }
this.#selectedAccount = selectedAccount; this.selectedAccount = selectedAccount;
if (this.#selectedAccount !== null) { if (this.selectedAccount !== null) {
this.#isAccountConfirmed &= this.#selectedAccount.isConfirmedAccount; this.#isAccountConfirmed &= this.selectedAccount.isConfirmedAccount;
} }
} }
@ -294,7 +294,7 @@ class DescriptionEditor {
*/ */
#submit() { #submit() {
bootstrap.Modal.getOrCreateInstance(this.#modal).hide(); bootstrap.Modal.getOrCreateInstance(this.#modal).hide();
this.lineItemEditor.saveDescription(this.description, this.#selectedAccount); this.lineItemEditor.saveDescription(this);
} }
/** /**

View File

@ -316,23 +316,22 @@ class JournalEntryLineItemEditor {
/** /**
* Saves the description from the description editor. * Saves the description from the description editor.
* *
* @param description {string} the description * @param editor {DescriptionEditor} the description editor
* @param account {DescriptionEditorAccount|null} the suggested account
*/ */
saveDescription(description, account = null) { saveDescription(editor) {
if (account !== null) { if (editor.selectedAccount !== null) {
this.#accountControl.classList.add("accounting-not-empty"); this.#accountControl.classList.add("accounting-not-empty");
this.account = account.copy(); this.account = editor.selectedAccount.copy();
this.#accountText.innerText = account.text; this.#accountText.innerText = editor.selectedAccount.text;
this.#validateAccount(); this.#validateAccount();
} }
if (description === "") { if (editor.description === "") {
this.#descriptionControl.classList.remove("accounting-not-empty"); this.#descriptionControl.classList.remove("accounting-not-empty");
} else { } else {
this.#descriptionControl.classList.add("accounting-not-empty"); this.#descriptionControl.classList.add("accounting-not-empty");
} }
this.description = description === ""? null: description; this.description = editor.description === ""? null: editor.description;
this.#descriptionText.innerText = description; this.#descriptionText.innerText = editor.description;
this.#validateDescription(); this.#validateDescription();
bootstrap.Modal.getOrCreateInstance(this.modal).show(); bootstrap.Modal.getOrCreateInstance(this.modal).show();
} }