diff --git a/accounts/templates/accounts/otp_login.html b/accounts/templates/accounts/otp_login.html index a4d2192d..d8e0c1f9 100644 --- a/accounts/templates/accounts/otp_login.html +++ b/accounts/templates/accounts/otp_login.html @@ -64,7 +64,7 @@
{% trans "Leave empty if you have not set up two-factor authentication." %}
- diff --git a/accounts/templates/login.html b/accounts/templates/login.html index ae386c97..089e78f0 100644 --- a/accounts/templates/login.html +++ b/accounts/templates/login.html @@ -54,7 +54,7 @@ - diff --git a/instances/templates/create_instance_w1.html b/instances/templates/create_instance_w1.html index 47e461b3..662e867f 100644 --- a/instances/templates/create_instance_w1.html +++ b/instances/templates/create_instance_w1.html @@ -10,7 +10,6 @@ {% endblock page_heading %} {% block content %} - {% include 'pleasewaitdialog.html' %}
{% include "create_steps.html" with step=2 %} @@ -51,7 +50,7 @@
-
{% csrf_token %} + {% csrf_token %} {% if xml_error %}{% endif %}
diff --git a/instances/templates/create_instance_w2.html b/instances/templates/create_instance_w2.html index a90d4c66..f27a6bda 100644 --- a/instances/templates/create_instance_w2.html +++ b/instances/templates/create_instance_w2.html @@ -21,7 +21,6 @@ {% endblock page_heading %} {% block content %} - {% include 'pleasewaitdialog.html' %}
{% include "create_steps.html" with step=3 %} diff --git a/instances/templates/instance.html b/instances/templates/instance.html index aef3a70e..a2ff2b18 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -14,7 +14,6 @@ {% block page_header %}{% endblock page_header %}{# the card below has the heading #} {% block content %} - {% include 'pleasewaitdialog.html' %} {# the VM at a glance in one card: who and where it is, what it has, and its sections as the card's footer #}
{% blocktrans with state=state.0 %}The VM's state: {{ state }}{% endblocktrans %}

{% endif %} - {% csrf_token %} + {% csrf_token %}
@@ -62,7 +62,7 @@
{% if "poweron" in power_actions and instance.has_managed_save_image %} -
{% csrf_token %} + {% csrf_token %} {% trans "The VM has a saved state: Power On resumes it as it was when saved." %} diff --git a/instances/tests/test_page_controls.py b/instances/tests/test_page_controls.py index f1db22b2..ab8c8200 100644 --- a/instances/tests/test_page_controls.py +++ b/instances/tests/test_page_controls.py @@ -225,8 +225,8 @@ class PageControlsTestCase(PageControls, TestCase): self.assertTrue(all(b.get("data-confirm") for b in danger)) if user == owner: self.assertIn("An administrator can resume it.", tab.text_content()) - if status == 5: - self.assertEqual(tab.xpath(".//form/@data-please-wait"), [""]) + if status == 5: # Start is sent to poweron + self.assertTrue(tab.xpath(".//form/@action")[0].endswith("/poweron/")) def test_a_vm_with_a_saved_state_says_so_and_can_start_without_it(self): owner = self.user("power_saved_owner", owner={}) diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index b4191059..16bac01b 100644 Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po index 34970f07..7544554c 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -411,10 +411,6 @@ msgstr "OTP'yi mi kaybettiniz?" msgid "Leave empty if you have not set up two-factor authentication." msgstr "İki aşamalı doğrulamayı kurmadıysanız boş bırakın." -#: accounts/templates/accounts/otp_login.html:59 -msgid "Verifying..." -msgstr "Doğrulanıyor..." - #: accounts/templates/accounts/otp_login.html:61 msgid "Verify & Sign In" msgstr "Doğrula ve oturum aç" @@ -512,10 +508,6 @@ msgstr "Sanallaştırma Yönetim Konsolu" msgid "Incorrect username or password." msgstr "Kullanıcı adı veya parola hatalı." -#: accounts/templates/login.html:48 -msgid "Signing in..." -msgstr "Oturum açılıyor..." - #: accounts/templates/profile.html:6 accounts/templates/profile.html:8 #: templates/navbar.html:54 msgid "Profile" @@ -10319,10 +10311,6 @@ msgstr "Sanal makine raporu (.xlsx)" msgid "Log Out" msgstr "Oturumu Kapat" -#: templates/pleasewaitdialog.html:7 templates/pleasewaitdialog.html:11 -msgid "Processing" -msgstr "İşleniyor" - #: virtsecrets/forms.py:19 msgid "The usage cannot have control characters or line breaks" msgstr "Kullanım denetim karakteri ya da satır sonu içeremez" diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index e702c526..3f782f6e 100644 Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po index 004e1f9a..557a8b74 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -406,10 +406,6 @@ msgstr "无法获取验证码?" msgid "Leave empty if you have not set up two-factor authentication." msgstr "如果未设置双因素认证,请留空。" -#: accounts/templates/accounts/otp_login.html:59 -msgid "Verifying..." -msgstr "正在验证…" - #: accounts/templates/accounts/otp_login.html:61 msgid "Verify & Sign In" msgstr "验证并登录" @@ -505,10 +501,6 @@ msgstr "虚拟化管理控制台" msgid "Incorrect username or password." msgstr "用户名或密码错误。" -#: accounts/templates/login.html:48 -msgid "Signing in..." -msgstr "正在登录…" - #: accounts/templates/profile.html:6 accounts/templates/profile.html:8 #: templates/navbar.html:54 msgid "Profile" @@ -9708,10 +9700,6 @@ msgstr "虚拟机报告 (.xlsx)" msgid "Log Out" msgstr "退出登录" -#: templates/pleasewaitdialog.html:7 templates/pleasewaitdialog.html:11 -msgid "Processing" -msgstr "处理中" - #: virtsecrets/forms.py:19 msgid "The usage cannot have control characters or line breaks" msgstr "用途不能包含控制字符或换行符" diff --git a/operations/static/operations/job_panel.js b/operations/static/operations/job_panel.js index c54b11b7..2093eab4 100644 --- a/operations/static/operations/job_panel.js +++ b/operations/static/operations/job_panel.js @@ -24,7 +24,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) { (initialIds || []).forEach(function (id) { pending[id] = true; }); var last = { jobs: [], others: [], short_operation: false, worker_last_seen: null, worker_gone: false }; var rendered = null; // the panel's last html: an unchanged one is not rebuilt (focus stays) - var holding = false; // the panel set backgroundJobRunning (the please-wait dialog sets it too) + var holding = false; // the panel set backgroundJobRunning (no other script holds it) if (initialIds && initialIds.length) { // a remembered job must not be lost to a status reload before the first poll answers window.backgroundJobRunning = true; diff --git a/operations/tests/js/job_panel.test.js b/operations/tests/js/job_panel.test.js index bdfb102f..1f5bcc1c 100644 --- a/operations/tests/js/job_panel.test.js +++ b/operations/tests/js/job_panel.test.js @@ -149,7 +149,7 @@ advance(3000); answer("/r", { ...empty, jobs: [{ ...running, state: "uncertain", error: "check the disks" }] }); assert.strictEqual(writes, 1, "an unchanged answer leaves the panel alone"); -// the panel showing nothing leaves a flag the please-wait dialog set alone +// the panel showing nothing leaves a flag another script set alone open = []; timers = []; jobPanel({ innerHTML: "", addEventListener() {} }, urls, "tok"); window.backgroundJobRunning = true; diff --git a/static/js/bulk_power.js b/static/js/bulk_power.js index bf2779bb..b05f0632 100644 --- a/static/js/bulk_power.js +++ b/static/js/bulk_power.js @@ -14,7 +14,7 @@ var boxes = onScreen(); var chosen = boxes.filter(function (box) { return box.checked; }).length; var tooMany = chosen > Number(count.dataset.max); // the server takes at most that many - form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = tooMany; }); + form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = tooMany || !!button.dataset.busy; }); // not one being sent (submit_busy.js) count.textContent = (tooMany ? count.dataset.tooMany : count.dataset.text).replace("%(count)s", chosen); count.classList.toggle("text-danger", tooMany); // the bar at the window's foot, while any VM is chosen; the page ends above it diff --git a/static/js/login_form.js b/static/js/login_form.js index 66e58779..b50f8871 100644 --- a/static/js/login_form.js +++ b/static/js/login_form.js @@ -1,6 +1,6 @@ // The sign-in forms (login, OTP login): the eye button shows or hides the -// password, a line says when Caps Lock is on, and while the form is sent its -// button is disabled and says so. +// password, and a line says when Caps Lock is on. While the form is sent, its +// button shows it as every form's does (submit_busy.js). document.getElementById("btn-toggle-pwd").addEventListener("click", function () { var password = document.getElementById("id_password"); var shown = password.type === "password"; @@ -20,12 +20,3 @@ document.getElementById("btn-toggle-pwd").addEventListener("click", function () document.getElementById("id_password").addEventListener("blur", function () { document.getElementById("caps-lock").classList.add("d-none"); }); - -document.getElementById("form-signin").addEventListener("submit", function () { - var button = document.getElementById("btn-signin"); - button.disabled = true; - var spinner = document.createElement("span"); - spinner.className = "spinner-border spinner-border-sm me-2"; - spinner.setAttribute("aria-hidden", "true"); - button.replaceChildren(spinner, button.dataset.busyText); -}); diff --git a/static/js/please_wait.js b/static/js/please_wait.js deleted file mode 100644 index c70bb64e..00000000 --- a/static/js/please_wait.js +++ /dev/null @@ -1,12 +0,0 @@ -// The please-wait dialog (pleasewaitdialog.html) of a page that submits a long request. -function showPleaseWaitDialog() { - var pleaseModal = new bootstrap.Modal(document.getElementById('pleaseWaitDialog'), { - keyboard: false - }); - pleaseModal.show(); - backgroundJobRunning = true; -} -// a form marked data-please-wait shows the dialog while it is sent -document.addEventListener("submit", function (event) { - if (event.target.matches("form[data-please-wait]")) showPleaseWaitDialog(); -}); diff --git a/static/js/poll.js b/static/js/poll.js index 43391837..325b5666 100644 --- a/static/js/poll.js +++ b/static/js/poll.js @@ -57,5 +57,6 @@ function pageInUse() { return !!document.querySelector(".modal.show") || !!(active && active.matches && active.matches("input, select, textarea")) || !!(window.xmlEditUnsaved && window.xmlEditUnsaved()) - || (typeof bulkPowerChosen === "function" && bulkPowerChosen()); // the VM list's bulk form in use (bulk_power.js) + || (typeof bulkPowerChosen === "function" && bulkPowerChosen()) // the VM list's bulk form in use (bulk_power.js) + || !!document.querySelector("button[data-busy]"); // a form being sent (submit_busy.js) } diff --git a/static/js/submit_busy.js b/static/js/submit_busy.js new file mode 100644 index 00000000..d32013d4 --- /dev/null +++ b/static/js/submit_busy.js @@ -0,0 +1,40 @@ +// A form sent to the server shows it: the button that sent it turns a spinner +// and takes no second click until the answer comes; a page's reload or a job's +// result waits meanwhile (poll.js pageInUse). It is as before when the page +// stays: its leaving asked about unsaved work (an XML edit, an ISO upload) or +// the browser's history brings it back. A form a script sends itself (it +// prevents the submit) is left as it is. +function submitBusyEnd() { + document.querySelectorAll("button[data-busy]").forEach(function (button) { + button.disabled = false; + delete button.dataset.busy; + button.querySelectorAll("[data-busy-spinner]").forEach(function (spinner) { spinner.remove(); }); + }); +} +var submitLeaveAsked = false; +document.addEventListener("submit", function (event) { + var button = event.submitter; + if (event.target.method !== "post" || !button || button.tagName !== "BUTTON") return; + // after the submit: the form's data, which has the button's name and value, is taken by then + setTimeout(function () { + if (event.defaultPrevented || submitLeaveAsked) { + submitLeaveAsked = false; + return; + } + button.disabled = true; + button.dataset.busy = "1"; + button.insertAdjacentHTML("afterbegin", ''); + }, 0); +}); +// after the page's own handlers (they are added as it loads): one asks before leaving +window.addEventListener("load", function () { + window.addEventListener("beforeunload", function (event) { + if (event.defaultPrevented) { + submitLeaveAsked = true; + submitBusyEnd(); + } + }); +}); +window.addEventListener("pageshow", function (event) { + if (event.persisted) submitBusyEnd(); +}); diff --git a/templates/base.html b/templates/base.html index 4534a16a..ac70ec29 100644 --- a/templates/base.html +++ b/templates/base.html @@ -78,6 +78,7 @@ + diff --git a/templates/pleasewaitdialog.html b/templates/pleasewaitdialog.html deleted file mode 100644 index 1a9a1951..00000000 --- a/templates/pleasewaitdialog.html +++ /dev/null @@ -1,18 +0,0 @@ -{% load i18n static %} - - -