Revised the JavaScript journal entry editor and summary editor so that the summary editor work with the journal entry editor and does not get into the detail of the journal entry editor.
This commit is contained in:
parent
fe87c3a7de
commit
6a671cac84
@ -94,34 +94,10 @@ class SummaryEditor {
|
|||||||
#selectedAccount = null;
|
#selectedAccount = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The modal of the journal entry form
|
* The journal entry editor
|
||||||
* @type {HTMLDivElement}
|
* @type {JournalEntryEditor}
|
||||||
*/
|
*/
|
||||||
#entryFormModal;
|
#entryEditor;
|
||||||
|
|
||||||
/**
|
|
||||||
* The control of the account on the journal entry form
|
|
||||||
* @type {HTMLDivElement}
|
|
||||||
*/
|
|
||||||
#formAccountControl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The account on the journal entry form
|
|
||||||
* @type {HTMLDivElement}
|
|
||||||
*/
|
|
||||||
#formAccount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The control of the summary on the journal entry form
|
|
||||||
* @type {HTMLDivElement}
|
|
||||||
*/
|
|
||||||
#formSummaryControl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The summary on the journal entry form
|
|
||||||
* @type {HTMLDivElement}
|
|
||||||
*/
|
|
||||||
#formSummary;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The tab planes
|
* The tab planes
|
||||||
@ -145,13 +121,6 @@ class SummaryEditor {
|
|||||||
// noinspection JSValidateTypes
|
// noinspection JSValidateTypes
|
||||||
this.#accountButtons = Array.from(document.getElementsByClassName(this.prefix + "-account"));
|
this.#accountButtons = Array.from(document.getElementsByClassName(this.prefix + "-account"));
|
||||||
|
|
||||||
// Things from the entry form
|
|
||||||
this.#entryFormModal = document.getElementById("accounting-entry-editor-modal");
|
|
||||||
this.#formAccountControl = document.getElementById("accounting-entry-editor-account-control");
|
|
||||||
this.#formAccount = document.getElementById("accounting-entry-editor-account");
|
|
||||||
this.#formSummaryControl = document.getElementById("accounting-entry-editor-summary-control");
|
|
||||||
this.#formSummary = document.getElementById("accounting-entry-editor-summary");
|
|
||||||
|
|
||||||
for (const cls of [GeneralTagTab, GeneralTripTab, BusTripTab, RegularPaymentTab, AnnotationTab]) {
|
for (const cls of [GeneralTagTab, GeneralTripTab, BusTripTab, RegularPaymentTab, AnnotationTab]) {
|
||||||
const tab = new cls(this);
|
const tab = new cls(this);
|
||||||
this.tabPlanes[tab.tabId()] = tab;
|
this.tabPlanes[tab.tabId()] = tab;
|
||||||
@ -239,31 +208,24 @@ class SummaryEditor {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#submit() {
|
#submit() {
|
||||||
if (this.summary.value === "") {
|
|
||||||
this.#formSummaryControl.classList.remove("accounting-not-empty");
|
|
||||||
} else {
|
|
||||||
this.#formSummaryControl.classList.add("accounting-not-empty");
|
|
||||||
}
|
|
||||||
if (this.#selectedAccount !== null) {
|
|
||||||
this.#formAccountControl.classList.add("accounting-not-empty");
|
|
||||||
this.#formAccount.dataset.code = this.#selectedAccount.dataset.code;
|
|
||||||
this.#formAccount.dataset.text = this.#selectedAccount.dataset.text;
|
|
||||||
this.#formAccount.innerText = this.#selectedAccount.dataset.text;
|
|
||||||
JournalEntryEditor.validateAccount();
|
|
||||||
}
|
|
||||||
this.#formSummary.dataset.value = this.summary.value;
|
|
||||||
this.#formSummary.innerText = this.summary.value;
|
|
||||||
bootstrap.Modal.getOrCreateInstance(this.#modal).hide();
|
bootstrap.Modal.getOrCreateInstance(this.#modal).hide();
|
||||||
bootstrap.Modal.getOrCreateInstance(this.#entryFormModal).show();
|
if (this.#selectedAccount !== null) {
|
||||||
|
this.#entryEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text);
|
||||||
|
} else {
|
||||||
|
this.#entryEditor.saveSummary(this.summary.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The callback when the summary editor is shown.
|
* The callback when the summary editor is shown.
|
||||||
*
|
*
|
||||||
|
* @param entryEditor {JournalEntryEditor} the journal entry editor
|
||||||
|
* @param summary {string} the summary
|
||||||
*/
|
*/
|
||||||
#onOpen() {
|
#onOpen(entryEditor, summary) {
|
||||||
|
this.#entryEditor = entryEditor;
|
||||||
this.#reset();
|
this.#reset();
|
||||||
this.summary.value = this.#formSummary.dataset.value;
|
this.summary.value = summary;
|
||||||
this.#onSummaryChange();
|
this.#onSummaryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,13 +253,20 @@ class SummaryEditor {
|
|||||||
*/
|
*/
|
||||||
static initialize() {
|
static initialize() {
|
||||||
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
|
const forms = Array.from(document.getElementsByClassName("accounting-summary-editor"));
|
||||||
const entryForm = document.getElementById("accounting-entry-editor");
|
|
||||||
const formSummaryControl = document.getElementById("accounting-entry-editor-summary-control");
|
|
||||||
for (const form of forms) {
|
for (const form of forms) {
|
||||||
const editor = new SummaryEditor(form);
|
const editor = new SummaryEditor(form);
|
||||||
this.#editors[editor.#entryType] = editor;
|
this.#editors[editor.#entryType] = editor;
|
||||||
}
|
}
|
||||||
formSummaryControl.onclick = () => this.#editors[entryForm.dataset.entryType].#onOpen()
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback when the summary editor is shown.
|
||||||
|
*
|
||||||
|
* @param entryEditor {JournalEntryEditor} the journal entry editor
|
||||||
|
* @param summary {string} the summary
|
||||||
|
*/
|
||||||
|
static start(entryEditor, summary) {
|
||||||
|
this.#editors[entryEditor.entryType].#onOpen(entryEditor, summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,6 +793,12 @@ class JournalEntryEditor {
|
|||||||
*/
|
*/
|
||||||
#modal;
|
#modal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entry type, either "debit" or "credit"
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
entryType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The control of the account
|
* The control of the account
|
||||||
* @type {HTMLDivElement}
|
* @type {HTMLDivElement}
|
||||||
@ -868,6 +874,9 @@ class JournalEntryEditor {
|
|||||||
this.#summaryError = document.getElementById("accounting-entry-editor-summary-error");
|
this.#summaryError = document.getElementById("accounting-entry-editor-summary-error");
|
||||||
this.#amount = document.getElementById("accounting-entry-editor-amount");
|
this.#amount = document.getElementById("accounting-entry-editor-amount");
|
||||||
this.#amountError = document.getElementById("accounting-entry-editor-amount-error");
|
this.#amountError = document.getElementById("accounting-entry-editor-amount-error");
|
||||||
|
this.#summaryControl.onclick = () => {
|
||||||
|
SummaryEditor.start(this, this.#summary.dataset.value);
|
||||||
|
};
|
||||||
this.#element.onsubmit = () => {
|
this.#element.onsubmit = () => {
|
||||||
if (this.#validate()) {
|
if (this.#validate()) {
|
||||||
if (this.#entry === null) {
|
if (this.#entry === null) {
|
||||||
@ -882,6 +891,38 @@ class JournalEntryEditor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the summary from the summary editor.
|
||||||
|
*
|
||||||
|
* @param summary {string} the summary
|
||||||
|
*/
|
||||||
|
saveSummary(summary) {
|
||||||
|
if (summary === "") {
|
||||||
|
this.#summaryControl.classList.remove("accounting-not-empty");
|
||||||
|
} else {
|
||||||
|
this.#summaryControl.classList.add("accounting-not-empty");
|
||||||
|
}
|
||||||
|
this.#summary.dataset.value = summary;
|
||||||
|
this.#summary.innerText = summary;
|
||||||
|
bootstrap.Modal.getOrCreateInstance(this.#modal).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the summary with the suggested account from the summary editor.
|
||||||
|
*
|
||||||
|
* @param summary {string} the summary
|
||||||
|
* @param accountCode {string} the account code
|
||||||
|
* @param accountText {string} the account text
|
||||||
|
*/
|
||||||
|
saveSummaryWithAccount(summary, accountCode, accountText) {
|
||||||
|
this.#accountControl.classList.add("accounting-not-empty");
|
||||||
|
this.#account.dataset.code = accountCode;
|
||||||
|
this.#account.dataset.text = accountText;
|
||||||
|
this.#account.innerText = accountText;
|
||||||
|
this.#validateAccount();
|
||||||
|
this.saveSummary(summary)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the form.
|
* Validates the form.
|
||||||
*
|
*
|
||||||
@ -950,6 +991,7 @@ class JournalEntryEditor {
|
|||||||
#onAddNew(side) {
|
#onAddNew(side) {
|
||||||
this.#entry = null;
|
this.#entry = null;
|
||||||
this.#side = side;
|
this.#side = side;
|
||||||
|
this.entryType = this.#side.entryType;
|
||||||
this.#element.dataset.entryType = side.entryType;
|
this.#element.dataset.entryType = side.entryType;
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
this.#accountControl.classList.remove("is-invalid");
|
this.#accountControl.classList.remove("is-invalid");
|
||||||
@ -980,6 +1022,7 @@ class JournalEntryEditor {
|
|||||||
#onEdit(entry, accountCode, accountText, summary, amount) {
|
#onEdit(entry, accountCode, accountText, summary, amount) {
|
||||||
this.#entry = entry;
|
this.#entry = entry;
|
||||||
this.#side = entry.side;
|
this.#side = entry.side;
|
||||||
|
this.entryType = this.#side.entryType;
|
||||||
this.#element.dataset.entryType = entry.entryType;
|
this.#element.dataset.entryType = entry.entryType;
|
||||||
if (accountCode === "") {
|
if (accountCode === "") {
|
||||||
this.#accountControl.classList.remove("accounting-not-empty");
|
this.#accountControl.classList.remove("accounting-not-empty");
|
||||||
|
Loading…
Reference in New Issue
Block a user