Replaced the isOriginalEntry dataset attribute with the isNeedOffset property in the JavaScript JournalEntryEditor. It does not make sense to store that information in the HTML.

This commit is contained in:
依瑪貓 2023-03-18 09:47:57 +08:00
parent 82b63e4bd4
commit 0a1bbbdd47

View File

@ -147,6 +147,12 @@ class JournalEntryEditor {
*/ */
#side; #side;
/**
* Whether the journal entry needs offset
* @type {boolean}
*/
isNeedOffset = false;
/** /**
* Constructs a new journal entry editor. * Constructs a new journal entry editor.
* *
@ -183,7 +189,7 @@ class JournalEntryEditor {
if (this.entry === null) { if (this.entry === null) {
this.entry = this.#side.addJournalEntry(); this.entry = this.#side.addJournalEntry();
} }
this.entry.save("isOriginalEntry" in this.#element.dataset, this.#originalEntry.dataset.id, this.#originalEntry.dataset.date, this.#originalEntry.dataset.text, this.#account.dataset.code, this.#account.dataset.text, this.#summary.dataset.value, this.#amount.value); this.entry.save(this.isNeedOffset, this.#originalEntry.dataset.id, this.#originalEntry.dataset.date, this.#originalEntry.dataset.text, this.#account.dataset.code, this.#account.dataset.text, this.#summary.dataset.value, this.#amount.value);
bootstrap.Modal.getInstance(this.#modal).hide(); bootstrap.Modal.getInstance(this.#modal).hide();
} }
return false; return false;
@ -196,7 +202,7 @@ class JournalEntryEditor {
* @param originalEntry {OriginalEntry} the original entry * @param originalEntry {OriginalEntry} the original entry
*/ */
saveOriginalEntry(originalEntry) { saveOriginalEntry(originalEntry) {
delete this.#element.dataset.isOriginalEntry; this.isNeedOffset = false;
this.#originalEntryContainer.classList.remove("d-none"); this.#originalEntryContainer.classList.remove("d-none");
this.#originalEntryControl.classList.add("accounting-not-empty"); this.#originalEntryControl.classList.add("accounting-not-empty");
this.#originalEntry.dataset.id = originalEntry.id; this.#originalEntry.dataset.id = originalEntry.id;
@ -226,7 +232,7 @@ class JournalEntryEditor {
* *
*/ */
clearOriginalEntry() { clearOriginalEntry() {
delete this.#element.dataset.isOriginalEntry; this.isNeedOffset = false;
this.#originalEntryContainer.classList.add("d-none"); this.#originalEntryContainer.classList.add("d-none");
this.#originalEntryControl.classList.remove("accounting-not-empty"); this.#originalEntryControl.classList.remove("accounting-not-empty");
this.#originalEntry.dataset.id = ""; this.#originalEntry.dataset.id = "";
@ -285,11 +291,7 @@ class JournalEntryEditor {
* @param isAccountOffsetNeeded {boolean} true if the journal entries in the account need offset, or false otherwise * @param isAccountOffsetNeeded {boolean} true if the journal entries in the account need offset, or false otherwise
*/ */
saveSummaryWithAccount(summary, accountCode, accountText, isAccountOffsetNeeded) { saveSummaryWithAccount(summary, accountCode, accountText, isAccountOffsetNeeded) {
if (isAccountOffsetNeeded) { this.isNeedOffset = isAccountOffsetNeeded;
this.#element.dataset.isOriginalEntry = "true";
} else {
delete this.#element.dataset.isOriginalEntry;
}
this.#accountControl.classList.add("accounting-not-empty"); this.#accountControl.classList.add("accounting-not-empty");
this.#account.dataset.code = accountCode; this.#account.dataset.code = accountCode;
this.#account.dataset.text = accountText; this.#account.dataset.text = accountText;
@ -312,7 +314,7 @@ class JournalEntryEditor {
* *
*/ */
clearAccount() { clearAccount() {
delete this.#element.dataset.isOriginalEntry; this.isNeedOffset = false;
this.#accountControl.classList.remove("accounting-not-empty"); this.#accountControl.classList.remove("accounting-not-empty");
this.#account.dataset.code = ""; this.#account.dataset.code = "";
this.#account.dataset.text = ""; this.#account.dataset.text = "";
@ -328,11 +330,7 @@ class JournalEntryEditor {
* @param isOffsetNeeded {boolean} true if the journal entries in the account need offset or false otherwise * @param isOffsetNeeded {boolean} true if the journal entries in the account need offset or false otherwise
*/ */
saveAccount(code, text, isOffsetNeeded) { saveAccount(code, text, isOffsetNeeded) {
if (isOffsetNeeded) { this.isNeedOffset = isOffsetNeeded;
this.#element.dataset.isOriginalEntry = "true";
} else {
delete this.#element.dataset.isOriginalEntry;
}
this.#accountControl.classList.add("accounting-not-empty"); this.#accountControl.classList.add("accounting-not-empty");
this.#account.dataset.code = code; this.#account.dataset.code = code;
this.#account.dataset.text = text; this.#account.dataset.text = text;
@ -444,7 +442,7 @@ class JournalEntryEditor {
this.#side = side; this.#side = side;
this.entryType = this.#side.entryType; this.entryType = this.#side.entryType;
this.#element.dataset.entryType = side.entryType; this.#element.dataset.entryType = side.entryType;
delete this.#element.dataset.isOriginalEntry; this.isNeedOffset = false;
this.#originalEntryContainer.classList.add("d-none"); this.#originalEntryContainer.classList.add("d-none");
this.#originalEntryControl.classList.remove("accounting-not-empty"); this.#originalEntryControl.classList.remove("accounting-not-empty");
this.#originalEntryControl.classList.remove("is-invalid"); this.#originalEntryControl.classList.remove("is-invalid");
@ -489,11 +487,7 @@ class JournalEntryEditor {
this.#side = entry.side; this.#side = entry.side;
this.entryType = this.#side.entryType; this.entryType = this.#side.entryType;
this.#element.dataset.entryType = entry.entryType; this.#element.dataset.entryType = entry.entryType;
if (entry.isOriginalEntry()) { this.isNeedOffset = entry.isOriginalEntry();
this.#element.dataset.isOriginalEntry = "true";
} else {
delete this.#element.dataset.isOriginalEntry;
}
if (originalEntryId === "") { if (originalEntryId === "") {
this.#originalEntryContainer.classList.add("d-none"); this.#originalEntryContainer.classList.add("d-none");
this.#originalEntryControl.classList.remove("accounting-not-empty"); this.#originalEntryControl.classList.remove("accounting-not-empty");