summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-04-10 19:05:10 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2024-04-10 19:05:10 +0200
commitb73ed6ebd3cca86de065549cfb0d109a1d0461c5 (patch)
tree72e601618b215599cc6646bd2c6df058b053406f
parentf06e7e51f84e9260410108ed527f3c8cbe28fbdd (diff)
split js files and do local time conversion
-rw-r--r--src/jwebmail/__init__.py2
-rw-r--r--src/jwebmail/render_mail.py6
-rw-r--r--src/jwebmail/static/src/dh-select-all-mails.js11
-rw-r--r--src/jwebmail/static/src/dh-submit-sort-on-change.js12
-rw-r--r--src/jwebmail/static/src/dh-toggle-navbar.js13
-rw-r--r--src/jwebmail/static/src/displayheaders.js35
-rw-r--r--src/jwebmail/static/src/localtime.js5
-rw-r--r--src/jwebmail/static/src/multipart-alt-tabs.js (renamed from src/jwebmail/static/src/rendermail.js)0
-rw-r--r--src/jwebmail/templates/_main_table.html7
-rw-r--r--src/jwebmail/templates/displayheaders.html8
-rw-r--r--src/jwebmail/templates/readmail.html5
11 files changed, 62 insertions, 42 deletions
diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py
index 03f62ef..5962c8b 100644
--- a/src/jwebmail/__init__.py
+++ b/src/jwebmail/__init__.py
@@ -35,7 +35,7 @@ else:
toml_read_file = dict(load=toml_load, text=True)
-__version__ = "2.2.1.dev3"
+__version__ = "2.2.1.dev4"
csrf = CSRFProtect()
diff --git a/src/jwebmail/render_mail.py b/src/jwebmail/render_mail.py
index f597603..d348721 100644
--- a/src/jwebmail/render_mail.py
+++ b/src/jwebmail/render_mail.py
@@ -50,8 +50,7 @@ def render_multipart_alternative(_subtype, content, path):
C += "</div>"
T += "</ul></div>"
- script_url = url_for("static", filename="src/rendermail.js")
- return f'<script src="{script_url}"></script><div class="jwm-mail-body jwm-mail-body-multipart-alternative">\n{T}\n{C}\n</div>\n'
+ return f'<div class="jwm-mail-body jwm-mail-body-multipart-alternative">\n{T}\n{C}\n</div>\n'
def render_multipart(_subtype, content, path):
@@ -123,7 +122,8 @@ def render_message(subtype, msg, path):
R += _format_header(gettext("CC"), msg["head"].get("cc"))
R += _format_header(gettext("BCC"), msg["head"].get("bcc"))
R += f"<dt>{escape(gettext('Date'))}</dt>"
- R += f"<dd>{escape(msg['head']['date'])}</dd>\n"
+ date = escape(msg['head']['date'])
+ R += f"<dd><time datetime='{date}' class=jwm-tolocaltime>{date}</time></dd>\n"
R += f"<dt>{escape(gettext('Content-Type'))}</dt>"
R += f"<dd>{to_mime_type(msg['head']['mime'])}</dd>\n"
R += "</dl>\n"
diff --git a/src/jwebmail/static/src/dh-select-all-mails.js b/src/jwebmail/static/src/dh-select-all-mails.js
new file mode 100644
index 0000000..73f8ff3
--- /dev/null
+++ b/src/jwebmail/static/src/dh-select-all-mails.js
@@ -0,0 +1,11 @@
+function check_all() {
+ const setTo = this.checked;
+ const chkbox = document.getElementsByClassName('jwm-mail-checkbox');
+
+ for (const m of chkbox)
+ m.checked = setTo;
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+ document.getElementById("check-all").addEventListener("click", check_all);
+});
diff --git a/src/jwebmail/static/src/dh-submit-sort-on-change.js b/src/jwebmail/static/src/dh-submit-sort-on-change.js
new file mode 100644
index 0000000..6d0ab6d
--- /dev/null
+++ b/src/jwebmail/static/src/dh-submit-sort-on-change.js
@@ -0,0 +1,12 @@
+function sort_select_submit() {
+ this.children[0].form.submit();
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+ const sort_select = document.getElementById("sort");
+ const current_option_name = new URL(document.location).searchParams.get("sort");
+ if (current_option_name)
+ sort_select.value = current_option_name;
+
+ document.getElementById("sort-select").addEventListener("change", sort_select_submit);
+});
diff --git a/src/jwebmail/static/src/dh-toggle-navbar.js b/src/jwebmail/static/src/dh-toggle-navbar.js
new file mode 100644
index 0000000..1325516
--- /dev/null
+++ b/src/jwebmail/static/src/dh-toggle-navbar.js
@@ -0,0 +1,13 @@
+function toggle_navbar() {
+ // Get the target from the "data-target" attribute
+ const target = this.dataset.target;
+ const $target = document.getElementById(target);
+
+ // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
+ this.classList.toggle('is-active');
+ $target.classList.toggle('is-active');
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+ document.getElementById("navbar-toggle").addEventListener("click", toggle_navbar);
+});
diff --git a/src/jwebmail/static/src/displayheaders.js b/src/jwebmail/static/src/displayheaders.js
deleted file mode 100644
index 3c0936a..0000000
--- a/src/jwebmail/static/src/displayheaders.js
+++ /dev/null
@@ -1,35 +0,0 @@
-function toggle_navbar() {
- // Get the target from the "data-target" attribute
- const target = this.dataset.target;
- const $target = document.getElementById(target);
-
- // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
- this.classList.toggle('is-active');
- $target.classList.toggle('is-active');
-}
-
-function sort_select_submit() {
- this.children[0].form.submit();
-}
-
-function check_all() {
- const setTo = this.checked;
- const chkbox = document.getElementsByClassName('jwm-mail-checkbox');
-
- for (const m of chkbox)
- m.checked = setTo;
-}
-
-document.addEventListener("DOMContentLoaded", function() {
- {
- const sort_select = document.getElementById("sort");
- const current_option_name = new URL(document.location).searchParams.get("sort");
- if (current_option_name)
- sort_select.value = current_option_name;
- }
-
- document.getElementById("sort-select").addEventListener("change", sort_select_submit);
- document.getElementById("navbar-toggle").addEventListener("click", toggle_navbar);
- document.getElementById("check-all").addEventListener("click", check_all);
-});
-
diff --git a/src/jwebmail/static/src/localtime.js b/src/jwebmail/static/src/localtime.js
new file mode 100644
index 0000000..daa1455
--- /dev/null
+++ b/src/jwebmail/static/src/localtime.js
@@ -0,0 +1,5 @@
+document.querySelectorAll('time.jwm-tolocaltime').forEach($e => {
+ const dateTime = new Date($e.dateTime);
+ $e.innerHTML = new Intl.DateTimeFormat(document.documentElement.lang).
+ format(dateTime.toLocaleString());
+});
diff --git a/src/jwebmail/static/src/rendermail.js b/src/jwebmail/static/src/multipart-alt-tabs.js
index 1331913..1331913 100644
--- a/src/jwebmail/static/src/rendermail.js
+++ b/src/jwebmail/static/src/multipart-alt-tabs.js
diff --git a/src/jwebmail/templates/_main_table.html b/src/jwebmail/templates/_main_table.html
index 35fdeec..700d77c 100644
--- a/src/jwebmail/templates/_main_table.html
+++ b/src/jwebmail/templates/_main_table.html
@@ -18,7 +18,9 @@
<div class="column is-2">
{% if msg.head.date %}
- {{ parse_iso_date(msg.head.date)|datetimeformat }}
+ <time datetime="{{msg.head.date}}" class=jwm-tolocaltime>
+ {{ parse_iso_date(msg.head.date)|datetimeformat }}
+ </time>
{% else %}
{{ gettext("unknown") }}
{% endif %}
@@ -37,7 +39,8 @@
</div>
<div class=media-right>
- <input type="checkbox" name="{{ msg.message_handle }}" form="move-mail remove-mail" class="jwm-mail-checkbox">
+ <input type="checkbox" name="{{ msg.message_handle }}" form="move-mail remove-mail"
+ class="jwm-mail-checkbox">
</div>
</tag>
diff --git a/src/jwebmail/templates/displayheaders.html b/src/jwebmail/templates/displayheaders.html
index 7125a12..36a1f68 100644
--- a/src/jwebmail/templates/displayheaders.html
+++ b/src/jwebmail/templates/displayheaders.html
@@ -1,7 +1,13 @@
{% extends 'mainlayout.html' %}
{% block scripts %}
- <script src="{{ url_for('static', filename='src/displayheaders.js') }}" defer>
+ <script src="{{ url_for('static', filename='src/dh-select-all-mails.js') }}" defer>
+ </script>
+ <script src="{{ url_for('static', filename='src/dh-toggle-navbar.js') }}" defer>
+ </script>
+ <script src="{{ url_for('static', filename='src/dh-submit-sort-on-change.js') }}" defer>
+ </script>
+ <script src="{{ url_for('static', filename='src/localtime.js') }}" defer>
</script>
{% endblock %}
diff --git a/src/jwebmail/templates/readmail.html b/src/jwebmail/templates/readmail.html
index f41197a..75b0b13 100644
--- a/src/jwebmail/templates/readmail.html
+++ b/src/jwebmail/templates/readmail.html
@@ -1,5 +1,10 @@
{% extends 'mainlayout.html' %}
+{% block scripts %}
+ <script src="{{ url_for('static', filename='src/multipart-alt-tabs.js') }}" defer>
+ </script>
+{% endblock %}
+
{% block content %}
<div class="section container">