From b73ed6ebd3cca86de065549cfb0d109a1d0461c5 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Wed, 10 Apr 2024 19:05:10 +0200 Subject: split js files and do local time conversion --- src/jwebmail/__init__.py | 2 +- src/jwebmail/render_mail.py | 6 ++-- src/jwebmail/static/src/dh-select-all-mails.js | 11 +++++++ .../static/src/dh-submit-sort-on-change.js | 12 ++++++++ src/jwebmail/static/src/dh-toggle-navbar.js | 13 ++++++++ src/jwebmail/static/src/displayheaders.js | 35 ---------------------- src/jwebmail/static/src/localtime.js | 5 ++++ src/jwebmail/static/src/multipart-alt-tabs.js | 21 +++++++++++++ src/jwebmail/static/src/rendermail.js | 21 ------------- src/jwebmail/templates/_main_table.html | 7 +++-- src/jwebmail/templates/displayheaders.html | 8 ++++- src/jwebmail/templates/readmail.html | 5 ++++ 12 files changed, 83 insertions(+), 63 deletions(-) create mode 100644 src/jwebmail/static/src/dh-select-all-mails.js create mode 100644 src/jwebmail/static/src/dh-submit-sort-on-change.js create mode 100644 src/jwebmail/static/src/dh-toggle-navbar.js delete mode 100644 src/jwebmail/static/src/displayheaders.js create mode 100644 src/jwebmail/static/src/localtime.js create mode 100644 src/jwebmail/static/src/multipart-alt-tabs.js delete mode 100644 src/jwebmail/static/src/rendermail.js 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 += "" T += "" - script_url = url_for("static", filename="src/rendermail.js") - return f'
\n{T}\n{C}\n
\n' + return f'
\n{T}\n{C}\n
\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"
{escape(gettext('Date'))}
" - R += f"
{escape(msg['head']['date'])}
\n" + date = escape(msg['head']['date']) + R += f"
\n" R += f"
{escape(gettext('Content-Type'))}
" R += f"
{to_mime_type(msg['head']['mime'])}
\n" R += "\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/multipart-alt-tabs.js b/src/jwebmail/static/src/multipart-alt-tabs.js new file mode 100644 index 0000000..1331913 --- /dev/null +++ b/src/jwebmail/static/src/multipart-alt-tabs.js @@ -0,0 +1,21 @@ +function tabSelection(evt) { + const self = evt.target; + + for (const ts of self.parentElement.parentElement.children) { + ts.classList.remove('is-active'); + } + self.parentNode.classList.add('is-active'); + + const bodies = self.parentElement.parentElement.parentElement.parentElement.children[1].children; + for (const ts of bodies) { + ts.classList.add('is-hidden'); + } + bodies[+self.parentElement.attributes.data.value].classList.remove('is-hidden'); +} + +document.addEventListener("DOMContentLoaded", function() { + const tabSections = document.getElementsByClassName("jwm-mail-body-multipart-alternative"); + for (const ts of tabSections) { + Array.from(ts.children[0].children[0].children).forEach(element => element.children[0].addEventListener('click', tabSelection)); + } +}) diff --git a/src/jwebmail/static/src/rendermail.js b/src/jwebmail/static/src/rendermail.js deleted file mode 100644 index 1331913..0000000 --- a/src/jwebmail/static/src/rendermail.js +++ /dev/null @@ -1,21 +0,0 @@ -function tabSelection(evt) { - const self = evt.target; - - for (const ts of self.parentElement.parentElement.children) { - ts.classList.remove('is-active'); - } - self.parentNode.classList.add('is-active'); - - const bodies = self.parentElement.parentElement.parentElement.parentElement.children[1].children; - for (const ts of bodies) { - ts.classList.add('is-hidden'); - } - bodies[+self.parentElement.attributes.data.value].classList.remove('is-hidden'); -} - -document.addEventListener("DOMContentLoaded", function() { - const tabSections = document.getElementsByClassName("jwm-mail-body-multipart-alternative"); - for (const ts of tabSections) { - Array.from(ts.children[0].children[0].children).forEach(element => element.children[0].addEventListener('click', tabSelection)); - } -}) 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 @@
{% if msg.head.date %} - {{ parse_iso_date(msg.head.date)|datetimeformat }} + {% else %} {{ gettext("unknown") }} {% endif %} @@ -37,7 +39,8 @@
- +
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 %} - + + + {% 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 %} + +{% endblock %} + {% block content %}
-- cgit v1.2.3