Skip to content

Commit 22dfe93

Browse files
committed
- **Enhanced templates for improved styling and functionality:**
- Updated receipt type rendering in `vendor_detail.html` to use `get_receipt_type_display` for enhanced context. - Adjusted side menu column width in `content_layout_1.html` from `is-2` to `is-3` for better layout proportions. - Renamed "Ledger List" navigation label to "Ledger Detail" in `je_detail.html` for improved navigation clarity. - Simplified `<form>` tags in `je_detail_txs.html` to remove redundant `action` attribute and added minor spacing adjustments. - **Introduced theme toggle functionality and improvements to base layout:** - Added `<meta>` tag for light and dark color scheme support. - Implemented script managing light and dark theme toggling and persistence via localStorage. - Modified base template logic to dynamically load appropriate theme and synchronize state. - Updated stylesheet URLs for better CDN reliability. - **UI improvements in navigation bar (`nav.html`):** - Added theme toggle button with accessibility features, including icon and label updates based on current theme state. - Removed hardcoded `is-light` class to allow dynamic theme application. - **Enhanced template action URLs with `next` parameter (`ledgers_table.html`):** - Added `?next={{ current_path }}` to action links for locking, posting, hiding, and deleting ledgers to enhance navigation context. ### **Summary** Improved template structure and functionality by introducing a theme toggle feature, updating receipt type rendering, navigating labels, and fixing layout proportions. Added better context handling for action URLs and streamlined form elements across templates. ### **Backwards Compatibility** These changes are fully backwards compatible with existing workflows. Dynamic theme support is an additive improvement, and no logic impacting workflows was altered.
1 parent a65995f commit 22dfe93

File tree

7 files changed

+81
-15
lines changed

7 files changed

+81
-15
lines changed

django_ledger/templates/django_ledger/includes/nav.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% load i18n %}
55
{% now "Y" as current_year %}
66

7-
<nav class="navbar is-light" role="navigation" aria-label="main navigation">
7+
<nav class="navbar" role="navigation" aria-label="main navigation">
88
<div class="container">
99
<div class="navbar-brand">
1010
<a class="navbar-item" href="{% url 'django_ledger:home' %}">
@@ -27,6 +27,16 @@
2727
{% if tx_digest_context.IO_RESULT.ce_to_date %}
2828
<div class="navbar-item">CE TO: {{ tx_digest_context.IO_RESULT.ce_to_date | date }}</div>
2929
{% endif %}
30+
31+
<!-- Theme toggle -->
32+
<div class="navbar-item">
33+
<button id="djl-theme-toggle" class="button is-small is-text" type="button"
34+
aria-label="Toggle color mode" aria-pressed="false">
35+
<iconify-icon id="djl-theme-toggle-icon" icon="mdi:weather-sunny"></iconify-icon>
36+
<span id="djl-theme-toggle-label" class="ml-2">Light</span>
37+
</button>
38+
</div>
39+
3040
<div class="navbar-item">
3141
<form action="{% url 'django_ledger:logout' %}" method="POST">
3242
{% csrf_token %}

django_ledger/templates/django_ledger/journal_entry/je_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</a>
2222
<a class="button is-dark"
2323
href="{% url 'django_ledger:je-list' entity_slug=view.kwargs.entity_slug ledger_pk=view.kwargs.ledger_pk %}">
24-
{% trans 'Ledger List' %}
24+
{% trans 'Ledger Detail' %}
2525
</a>
2626
{% if journal_entry.can_unlock %}
2727
<a class="button is-warning"

django_ledger/templates/django_ledger/journal_entry/je_detail_txs.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<div class="column is-12">
1111
<div class="box">
1212

13-
<form action="{{ view.request.path }}" method="post">
13+
14+
<form method="post">
1415
{% csrf_token %}
1516

1617
<div class="columns is-multiline">
@@ -49,6 +50,8 @@
4950
{% endfor %}
5051

5152
</table>
53+
54+
5255
</div>
5356
<div class="column is-12 has-text-centered">
5457
<button class="button is-primary is-outlined">
@@ -85,6 +88,7 @@
8588
</div>
8689
</div>
8790
</form>
91+
8892
</div>
8993
</div>
9094
</div>

django_ledger/templates/django_ledger/layouts/base.html

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@
77
<head>
88
<meta charset="utf-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
<meta name="color-scheme" content="light dark">
1011
<title>{% block page_title %}{{ page_title }} | {{ entity_model.name | default:'' }}{% endblock %}</title>
1112

13+
<script>
14+
(function () {
15+
try {
16+
var saved = localStorage.getItem('djl-theme');
17+
var theme;
18+
if (saved === 'dark' || saved === 'light') {
19+
theme = saved;
20+
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
21+
theme = 'dark';
22+
} else {
23+
theme = 'light';
24+
}
25+
document.documentElement.setAttribute('data-theme', theme);
26+
} catch (e) {
27+
document.documentElement.setAttribute('data-theme', 'light');
28+
}
29+
})();
30+
</script>
31+
32+
<!-- Bulma base, then Bulmaswatch theme, then our overrides -->
1233
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
13-
<link rel="stylesheet" href="{% static 'django_ledger/css/djl_styles.css' %}">
1434
<link rel="stylesheet"
15-
href="https://cdn.rawgit.com/jenil/bulmaswatch/gh-pages/{{ DJANGO_LEDGER_THEME }}/bulmaswatch.min.css">
35+
href="https://cdn.jsdelivr.net/gh/jenil/bulmaswatch@gh-pages/{{ DJANGO_LEDGER_THEME }}/bulmaswatch.min.css">
36+
<link rel="stylesheet" href="{% static 'django_ledger/css/djl_styles.css' %}">
37+
1638
<script src="https://code.iconify.design/iconify-icon/2.3.0/iconify-icon.min.js"></script>
1739

1840
<link rel="shortcut icon" type="image/jpg" href="{% static 'django_ledger/logo/favicon.png' %}">
@@ -44,7 +66,6 @@
4466
{% block script_bottom %}
4567
<script src="{% static 'django_ledger/bundle/djetler.bundle.js' %}"></script>
4668

47-
4869
<script>
4970
{% if entity_slug %}
5071
let entitySlug = "{{ view.kwargs.entity_slug }}"
@@ -61,6 +82,37 @@
6182
datePickers.forEach(dp => djLedger.getCalendar(dp.attributes.id.value, dateNavigationUrl))
6283
{% endif %}
6384
</script>
85+
86+
<script>
87+
// Theme toggle logic
88+
(function () {
89+
function applyTheme(theme) {
90+
document.documentElement.setAttribute('data-theme', theme);
91+
try { localStorage.setItem('djl-theme', theme); } catch (e) {}
92+
var icon = document.getElementById('djl-theme-toggle-icon');
93+
var label = document.getElementById('djl-theme-toggle-label');
94+
var btn = document.getElementById('djl-theme-toggle');
95+
if (btn) btn.setAttribute('aria-pressed', theme === 'dark');
96+
if (icon) icon.setAttribute('icon', theme === 'dark' ? 'mdi:weather-night' : 'mdi:weather-sunny');
97+
if (label) label.textContent = theme === 'dark' ? 'Dark' : 'Light';
98+
}
99+
100+
function initThemeToggle() {
101+
var current = document.documentElement.getAttribute('data-theme') || 'light';
102+
applyTheme(current);
103+
var toggle = document.getElementById('djl-theme-toggle');
104+
if (!toggle) return;
105+
toggle.addEventListener('click', function () {
106+
var t = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
107+
applyTheme(t);
108+
});
109+
}
110+
111+
if (document.readyState === 'loading') {
112+
document.addEventListener('DOMContentLoaded', initThemeToggle);
113+
} else { initThemeToggle(); }
114+
})();
115+
</script>
64116
{% endblock %}
65117

66118
{% block bottom_extra_js %}{% endblock %}

django_ledger/templates/django_ledger/layouts/content_layout_1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{# SIDE MENU #}
1010
{% if not hide_menu %}
11-
<div class="column is-2 is-hidden-mobile is-hidden-tablet-only">
11+
<div class="column is-3 is-hidden-mobile is-hidden-tablet-only">
1212
<div class="columns is-multiline">
1313
{% block aux_menu %}{% endblock %}
1414
<div class="column is-12">

django_ledger/templates/django_ledger/ledger/tags/ledgers_table.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,33 @@
101101
<a href="{% url 'django_ledger:ledger-update' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
102102
class="dropdown-item has-text-success">{% trans 'Edit' %}</a>
103103
{% if ledger_model.can_lock %}
104-
<a href="{% url 'django_ledger:ledger-action-lock' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
104+
<a href="{% url 'django_ledger:ledger-action-lock' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
105105
class="dropdown-item has-text-info has-text-weight-bold">{% trans 'Lock' %}</a>
106106
{% endif %}
107107
{% if ledger_model.can_unlock %}
108-
<a href="{% url 'django_ledger:ledger-action-unlock' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
108+
<a href="{% url 'django_ledger:ledger-action-unlock' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
109109
class="dropdown-item has-text-warning has-text-weight-bold">{% trans 'UnLock' %}</a>
110110
{% endif %}
111111
{% if ledger_model.can_post %}
112-
<a href="{% url 'django_ledger:ledger-action-post' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
112+
<a href="{% url 'django_ledger:ledger-action-post' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
113113
class="dropdown-item has-text-info has-text-weight-bold">{% trans 'Post' %}</a>
114114
{% endif %}
115115
{% if ledger_model.can_unpost %}
116-
<a href="{% url 'django_ledger:ledger-action-unpost' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
116+
<a href="{% url 'django_ledger:ledger-action-unpost' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
117117
class="dropdown-item has-text-warning has-text-weight-bold">{% trans 'UnPost' %}</a>
118118
{% endif %}
119119

120120
{% if ledger_model.can_hide %}
121-
<a href="{% url 'django_ledger:ledger-action-hide' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
121+
<a href="{% url 'django_ledger:ledger-action-hide' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
122122
class="dropdown-item has-text-warning has-text-weight-bold">{% trans 'Hide' %}</a>
123123
{% endif %}
124124
{% if ledger_model.can_unhide %}
125-
<a href="{% url 'django_ledger:ledger-action-unhide' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
125+
<a href="{% url 'django_ledger:ledger-action-unhide' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
126126
class="dropdown-item has-text-danger has-text-weight-bold">{% trans 'UnHide' %}</a>
127127
{% endif %}
128128

129129
{% if ledger_model.can_delete %}
130-
<a href="{% url 'django_ledger:ledger-delete' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}"
130+
<a href="{% url 'django_ledger:ledger-delete' entity_slug=entity_slug ledger_pk=ledger_model.uuid %}?next={{ current_path }}"
131131
class="dropdown-item has-text-danger has-text-weight-bold">{% trans 'Delete' %}</a>
132132
{% endif %}
133133
</div>

django_ledger/templates/django_ledger/vendor/vendor_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h3 class="title is-4">
3333
<a href="{{ receipt.get_absolute_url }}">{{ receipt.receipt_number }}</a>
3434
</td>
3535
<td>{{ receipt.receipt_date }}</td>
36-
<td>{{ receipt.receipt_type|title }}</td>
36+
<td>{{ receipt.get_receipt_type_display|title }}</td>
3737
<td>
3838
{% if receipt.get_import_job_url %}
3939
<a class="button is-small is-primary"

0 commit comments

Comments
 (0)