Replaced the long parameter list with the JournalEntrySubForm instance in the onEdit method of the JavaScript JournalEntryEditor, to simplify the code.
This commit is contained in:
parent
ca928636fd
commit
f5149a0c37
@ -519,51 +519,43 @@ class JournalEntryEditor {
|
|||||||
* The callback when editing a journal entry.
|
* The callback when editing a journal entry.
|
||||||
*
|
*
|
||||||
* @param entry {JournalEntrySubForm} the journal entry sub-form
|
* @param entry {JournalEntrySubForm} the journal entry sub-form
|
||||||
* @param originalEntryId {string} the ID of the original entry
|
|
||||||
* @param originalEntryDate {string} the date of the original entry
|
|
||||||
* @param originalEntryText {string} the text of the original entry
|
|
||||||
* @param summary {string} the summary
|
|
||||||
* @param accountCode {string} the account code
|
|
||||||
* @param accountText {string} the account text
|
|
||||||
* @param amount {string} the amount
|
|
||||||
* @param amountMin {string} the minimal amount
|
|
||||||
*/
|
*/
|
||||||
onEdit(entry, originalEntryId, originalEntryDate, originalEntryText, summary, accountCode, accountText, amount, amountMin) {
|
onEdit(entry) {
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.#side = entry.side;
|
this.#side = entry.side;
|
||||||
this.entryType = this.#side.entryType;
|
this.entryType = this.#side.entryType;
|
||||||
this.isNeedOffset = entry.isNeedOffset();
|
this.isNeedOffset = entry.isNeedOffset();
|
||||||
if (originalEntryId === "") {
|
this.originalEntryId = entry.getOriginalEntryId();
|
||||||
|
this.originalEntryDate = entry.getOriginalEntryDate();
|
||||||
|
this.originalEntryText = entry.getOriginalEntryText();
|
||||||
|
this.#originalEntry.innerText = this.originalEntryText;
|
||||||
|
if (this.originalEntryId === null) {
|
||||||
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");
|
||||||
} else {
|
} else {
|
||||||
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.originalEntryId = originalEntryId === ""? null: originalEntryId;
|
this.#setEnableSummaryAccount(!entry.isMatched && this.originalEntryId === null);
|
||||||
this.originalEntryDate = originalEntryDate === ""? null: originalEntryDate;
|
this.summary = entry.getSummary();
|
||||||
this.originalEntryText = originalEntryText === ""? null: originalEntryText;
|
if (this.summary === null) {
|
||||||
this.#originalEntry.innerText = originalEntryText;
|
|
||||||
this.#setEnableSummaryAccount(!entry.isMatched && originalEntryId === "");
|
|
||||||
if (summary === "") {
|
|
||||||
this.#summaryControl.classList.remove("accounting-not-empty");
|
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||||
} else {
|
} else {
|
||||||
this.#summaryControl.classList.add("accounting-not-empty");
|
this.#summaryControl.classList.add("accounting-not-empty");
|
||||||
}
|
}
|
||||||
this.summary = summary === ""? null: summary;
|
this.#summary.innerText = this.summary === null? "": this.summary;
|
||||||
this.#summary.innerText = summary;
|
if (entry.getAccountCode() === null) {
|
||||||
if (accountCode === "") {
|
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
} else {
|
} else {
|
||||||
this.#accountControl.classList.add("accounting-not-empty");
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
}
|
}
|
||||||
this.accountCode = accountCode;
|
this.accountCode = entry.getAccountCode();
|
||||||
this.accountText = accountText;
|
this.accountText = entry.getAccountText();
|
||||||
this.#account.innerText = accountText;
|
this.#account.innerText = this.accountText;
|
||||||
this.#amount.value = amount;
|
this.#amount.value = entry.getAmount() === null? "": String(entry.getAmount());
|
||||||
const maxAmount = this.#getMaxAmount();
|
const maxAmount = this.#getMaxAmount();
|
||||||
this.#amount.max = maxAmount === null? "": maxAmount;
|
this.#amount.max = maxAmount === null? "": maxAmount;
|
||||||
this.#amount.min = amountMin;
|
this.#amount.min = entry.getAmountMin() === null? "": String(entry.getAmountMin());
|
||||||
this.#validate();
|
this.#validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,7 +881,7 @@ class JournalEntrySubForm {
|
|||||||
this.#amount = document.getElementById(this.#prefix + "-amount");
|
this.#amount = document.getElementById(this.#prefix + "-amount");
|
||||||
this.#amountText = document.getElementById(this.#prefix + "-amount-text");
|
this.#amountText = document.getElementById(this.#prefix + "-amount-text");
|
||||||
this.deleteButton = document.getElementById(this.#prefix + "-delete");
|
this.deleteButton = document.getElementById(this.#prefix + "-delete");
|
||||||
this.#control.onclick = () => this.side.currency.form.entryEditor.onEdit(this, this.#originalEntryId.value, this.#originalEntryId.dataset.date, this.#originalEntryId.dataset.text, this.#summary.value, this.#accountCode.value, this.#accountCode.dataset.text, this.#amount.value, this.#amount.dataset.min);
|
this.#control.onclick = () => this.side.currency.form.entryEditor.onEdit(this);
|
||||||
this.deleteButton.onclick = () => {
|
this.deleteButton.onclick = () => {
|
||||||
this.element.parentElement.removeChild(this.element);
|
this.element.parentElement.removeChild(this.element);
|
||||||
this.side.deleteJournalEntry(this);
|
this.side.deleteJournalEntry(this);
|
||||||
@ -915,6 +915,24 @@ class JournalEntrySubForm {
|
|||||||
return this.#originalEntryId.dataset.date === ""? null: this.#originalEntryId.dataset.date;
|
return this.#originalEntryId.dataset.date === ""? null: this.#originalEntryId.dataset.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the text of the original entry.
|
||||||
|
*
|
||||||
|
* @return {string|null} the text of the original entry
|
||||||
|
*/
|
||||||
|
getOriginalEntryText() {
|
||||||
|
return this.#originalEntryId.dataset.text === ""? null: this.#originalEntryId.dataset.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the summary.
|
||||||
|
*
|
||||||
|
* @return {string|null} the summary
|
||||||
|
*/
|
||||||
|
getSummary() {
|
||||||
|
return this.#summary.value === ""? null: this.#summary.value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the account code.
|
* Returns the account code.
|
||||||
*
|
*
|
||||||
@ -924,6 +942,15 @@ class JournalEntrySubForm {
|
|||||||
return this.#accountCode.value === ""? null: this.#accountCode.value;
|
return this.#accountCode.value === ""? null: this.#accountCode.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the account text.
|
||||||
|
*
|
||||||
|
* @return {string|null} the account text
|
||||||
|
*/
|
||||||
|
getAccountText() {
|
||||||
|
return this.#accountCode.dataset.text === ""? null: this.#accountCode.dataset.text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the amount.
|
* Returns the amount.
|
||||||
*
|
*
|
||||||
@ -933,6 +960,15 @@ class JournalEntrySubForm {
|
|||||||
return this.#amount.value === ""? null: new Decimal(this.#amount.value);
|
return this.#amount.value === ""? null: new Decimal(this.#amount.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimal amount.
|
||||||
|
*
|
||||||
|
* @return {Decimal|null} the minimal amount
|
||||||
|
*/
|
||||||
|
getAmountMin() {
|
||||||
|
return this.#amount.dataset.min === ""? null: new Decimal(this.#amount.dataset.min);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the form.
|
* Validates the form.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user