Compare commits

..

No commits in common. "d4b3fe67b9a538de3058ff9a3a6ccfc3a8849c95" and "884e37fe1b29b546295861efd32c12ff22a694df" have entirely different histories.

6 changed files with 30 additions and 22 deletions

View File

@ -38,7 +38,7 @@ class AccountSelector {
* The entry type * The entry type
* @type {string} * @type {string}
*/ */
#entryType; entryType;
/** /**
* The prefix of the HTML ID and class * The prefix of the HTML ID and class
@ -90,7 +90,7 @@ class AccountSelector {
*/ */
constructor(entryEditor, entryType) { constructor(entryEditor, entryType) {
this.#entryEditor = entryEditor this.#entryEditor = entryEditor
this.#entryType = entryType; this.entryType = entryType;
this.#prefix = "accounting-account-selector-" + entryType; this.#prefix = "accounting-account-selector-" + entryType;
this.#query = document.getElementById(this.#prefix + "-query"); this.#query = document.getElementById(this.#prefix + "-query");
this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result"); this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result");
@ -143,7 +143,7 @@ class AccountSelector {
* @return {string[]} the account codes that are used in the form * @return {string[]} the account codes that are used in the form
*/ */
#getCodesUsedInForm() { #getCodesUsedInForm() {
const inUse = this.#entryEditor.form.getAccountCodesUsed(this.#entryType); const inUse = this.#entryEditor.form.getAccountCodesUsed(this.entryType);
if (this.#entryEditor.accountCode !== null) { if (this.#entryEditor.accountCode !== null) {
inUse.push(this.#entryEditor.accountCode); inUse.push(this.#entryEditor.accountCode);
} }

View File

@ -238,8 +238,8 @@ class JournalEntryEditor {
this.#amountError = document.getElementById(this.#prefix + "-amount-error"); this.#amountError = document.getElementById(this.#prefix + "-amount-error");
this.#summaryEditors = SummaryEditor.getInstances(this); this.#summaryEditors = SummaryEditor.getInstances(this);
this.#accountSelectors = AccountSelector.getInstances(this); this.#accountSelectors = AccountSelector.getInstances(this);
this.originalEntrySelector = new OriginalEntrySelector(this); this.originalEntrySelector = new OriginalEntrySelector();
this.#originalEntryControl.onclick = () => this.originalEntrySelector.onOpen() this.#originalEntryControl.onclick = () => this.originalEntrySelector.onOpen(this, this.originalEntryId)
this.#originalEntryDelete.onclick = () => this.clearOriginalEntry(); this.#originalEntryDelete.onclick = () => this.clearOriginalEntry();
this.#summaryControl.onclick = () => this.#summaryEditors[this.entryType].onOpen(); this.#summaryControl.onclick = () => this.#summaryEditors[this.entryType].onOpen();
this.#accountControl.onclick = () => this.#accountSelectors[this.entryType].onOpen(); this.#accountControl.onclick = () => this.#accountSelectors[this.entryType].onOpen();

View File

@ -28,18 +28,18 @@
*/ */
class OriginalEntrySelector { class OriginalEntrySelector {
/**
* The journal entry editor
* @type {JournalEntryEditor}
*/
entryEditor;
/** /**
* The prefix of the HTML ID and class * The prefix of the HTML ID and class
* @type {string} * @type {string}
*/ */
#prefix = "accounting-original-entry-selector"; #prefix = "accounting-original-entry-selector";
/**
* The modal of the original entry editor
* @type {HTMLDivElement}
*/
#modal;
/** /**
* The query input * The query input
* @type {HTMLInputElement} * @type {HTMLInputElement}
@ -70,6 +70,12 @@ class OriginalEntrySelector {
*/ */
#optionById; #optionById;
/**
* The journal entry editor
* @type {JournalEntryEditor}
*/
entryEditor;
/** /**
* The currency code * The currency code
* @type {string} * @type {string}
@ -84,10 +90,9 @@ class OriginalEntrySelector {
/** /**
* Constructs an original entry selector. * Constructs an original entry selector.
* *
* @param entryEditor {JournalEntryEditor} the journal entry editor
*/ */
constructor(entryEditor) { constructor() {
this.entryEditor = entryEditor; this.#modal = document.getElementById(this.#prefix + "-modal");
this.#query = document.getElementById(this.#prefix + "-query"); this.#query = document.getElementById(this.#prefix + "-query");
this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result"); this.#queryNoResult = document.getElementById(this.#prefix + "-option-no-result");
this.#optionList = document.getElementById(this.#prefix + "-option-list"); this.#optionList = document.getElementById(this.#prefix + "-option-list");
@ -176,12 +181,15 @@ class OriginalEntrySelector {
/** /**
* The callback when the original entry selector is shown. * The callback when the original entry selector is shown.
* *
* @param entryEditor {JournalEntryEditor} the journal entry editor
* @param originalEntryId {string|null} the ID of the original entry
*/ */
onOpen() { onOpen(entryEditor, originalEntryId = null) {
this.#currencyCode = this.entryEditor.getCurrencyCode(); this.entryEditor = entryEditor
this.#entryType = this.entryEditor.entryType; this.#currencyCode = entryEditor.getCurrencyCode();
this.#entryType = entryEditor.entryType;
for (const option of this.#options) { for (const option of this.#options) {
option.setActive(option.id === this.entryEditor.originalEntryId); option.setActive(option.id === originalEntryId);
} }
this.#query.value = ""; this.#query.value = "";
this.#updateNetBalances(); this.#updateNetBalances();

View File

@ -175,7 +175,7 @@ class MonthTab extends TabPlane {
let start = monthChooser.dataset.start; let start = monthChooser.dataset.start;
this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, { this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, {
restrictions: { restrictions: {
minDate: new Date(start), minDate: start,
}, },
display: { display: {
inline: true, inline: true,
@ -184,7 +184,7 @@ class MonthTab extends TabPlane {
clock: false, clock: false,
}, },
}, },
defaultDate: new Date(monthChooser.dataset.default), defaultDate: monthChooser.dataset.default,
}); });
monthChooser.addEventListener(tempusDominus.Namespace.events.change, (e) => { monthChooser.addEventListener(tempusDominus.Namespace.events.change, (e) => {
const date = e.detail.date; const date = e.detail.date;

View File

@ -132,7 +132,7 @@ class SummaryEditor {
this.currentTab = this.tabPlanes.general; this.currentTab = this.tabPlanes.general;
this.#initializeSuggestedAccounts(); this.#initializeSuggestedAccounts();
this.summary.onchange = () => this.#onSummaryChange(); this.summary.onchange = () => this.#onSummaryChange();
this.#offsetButton.onclick = () => this.#entryEditor.originalEntrySelector.onOpen(); this.#offsetButton.onclick = () => this.#entryEditor.originalEntrySelector.onOpen(this.#entryEditor);
this.#form.onsubmit = () => { this.#form.onsubmit = () => {
if (this.currentTab.validate()) { if (this.currentTab.validate()) {
this.#submit(); this.#submit();

View File

@ -32,7 +32,7 @@ First written: 2023/1/27
<script src="{{ url_for("babel_catalog") }}"></script> <script src="{{ url_for("babel_catalog") }}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js" integrity="sha384-QdsxGEq4Y0erX8WUIsZJDtfoSSyBF6dmNCnzRNYCa2AOM/xzNsyhHu0RbdFBAm+l" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js" integrity="sha384-QdsxGEq4Y0erX8WUIsZJDtfoSSyBF6dmNCnzRNYCa2AOM/xzNsyhHu0RbdFBAm+l" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.4.3/dist/js/tempus-dominus.min.js" integrity="sha384-2MkID2vkc9sxBCqs2us3mB8fV+c0o7uPtOvAPjaC8gKv9Bk21UHT0r2Q7Kv70+zO" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.2.10/dist/js/tempus-dominus.min.js" integrity="sha384-BiIgBzfRUwCKCLJTFUfZPl8n4yeDooQYkgtJBNVI4Gg6OAfIFO6FhEK6KiO1dvhA" crossorigin="anonymous"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
</head> </head>