1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

fix(ui): a form being sent shows it on its button

A form sent to the server showed nothing until the answer came: its
button stayed as it was and took a second click, though creating a
volume or starting a pool can take seconds. The button that sent it now
turns a spinner and takes no second click meanwhile, and a page's reload
or a job's result waits (submit_busy.js on every page, poll.js
pageInUse). It is as before when the page stays: its leaving asked about
unsaved work, or the browser's history brings it back. A form a script
sends itself is left alone.

The please-wait dialog of the VM start and the XML create, and the
sign-in forms' own spinner, go: they show the same as every other form.
This commit is contained in:
catborise 2026-11-21 21:13:01 +03:00
parent e79817e7db
commit fb81e7adca
20 changed files with 55 additions and 79 deletions

View file

@ -64,7 +64,7 @@
<div class="form-text">{% trans "Leave empty if you have not set up two-factor authentication." %}</div>
</div>
<button id="btn-signin" class="btn btn-primary w-100 py-2" type="submit" data-busy-text="{% trans "Verifying..." %}">
<button id="btn-signin" class="btn btn-primary w-100 py-2" type="submit">
<i class="bi bi-shield-lock-fill me-1"></i>
<span id="btn-text">{% trans "Verify & Sign In" %}</span>
</button>

View file

@ -54,7 +54,7 @@
<input type="hidden" name="next" value="{{ next }}">
<button id="btn-signin" class="btn btn-primary w-100 py-2" type="submit" data-busy-text="{% trans "Signing in..." %}">
<button id="btn-signin" class="btn btn-primary w-100 py-2" type="submit">
<i class="bi bi-box-arrow-in-right me-1"></i>
<span id="btn-text">{% trans "Sign In" %}</span>
</button>

View file

@ -10,7 +10,6 @@
{% endblock page_heading %}
{% block content %}
{% include 'pleasewaitdialog.html' %}
<div>
{% include "create_steps.html" with step=2 %}
@ -51,7 +50,7 @@
</button>
</h2>
<div class="accordion-collapse collapse{% if xml_error %} show{% endif %}" id="from-xml">
<form method="post" class="accordion-body" aria-label="{% trans "Create instance from XML" %}" data-please-wait>{% csrf_token %}
<form method="post" class="accordion-body" aria-label="{% trans "Create instance from XML" %}">{% csrf_token %}
{% if xml_error %}<div class="alert alert-danger form-errors" role="alert">{{ xml_error }}</div>{% endif %}
<input type="hidden" name="dom_xml" value="{{ xml }}">
<div class="xmlheight mb-3"><textarea id="editor" aria-label="{% trans "Domain XML" %}">{{ xml }}</textarea></div>

View file

@ -21,7 +21,6 @@
{% endblock page_heading %}
{% block content %}
{% include 'pleasewaitdialog.html' %}
<div>
{% include "create_steps.html" with step=3 %}

View file

@ -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 #}
<section class="card mb-3" aria-labelledby="vm-name" id="vm-summary" data-status="{{ instance.status }}"
data-status-url="{% url 'instances:status' instance.id %}" data-osinfo-url="{% url 'instances:osinfo' instance.id %}"

View file

@ -11,7 +11,7 @@
{% if instance.status not in power_states %}
<p class="mb-3">{% blocktrans with state=state.0 %}The VM's state: {{ state }}{% endblocktrans %}</p>
{% endif %}
<form method="post"{% if "poweron" in power_actions %} action="{% url 'instances:poweron' instance.id %}" data-please-wait{% endif %}>{% csrf_token %}
<form method="post"{% if "poweron" in power_actions %} action="{% url 'instances:poweron' instance.id %}"{% endif %}>{% csrf_token %}
<div class="row g-4">
<div class="col-12 col-md-4">
<div class="d-flex align-items-center gap-2 mb-2">
@ -62,7 +62,7 @@
</div>
</form>
{% if "poweron" in power_actions and instance.has_managed_save_image %}
<form method="post" action="{% url 'instances:poweron' instance.id %}" class="d-flex flex-wrap align-items-center gap-2 border-top mt-4 pt-3" data-please-wait>{% csrf_token %}
<form method="post" action="{% url 'instances:poweron' instance.id %}" class="d-flex flex-wrap align-items-center gap-2 border-top mt-4 pt-3">{% csrf_token %}
<span class="small me-auto">{% trans "The VM has a saved state: Power On resumes it as it was when saved." %}</span>
<button type="submit" class="btn btn-sm btn-outline-danger" name="fresh" value="1"
data-confirm="{% blocktrans with name=instance.name %}Start {{ name }} without its saved state? The saved state is discarded and the VM boots anew; what it had in memory is lost.{% endblocktrans %}">{% trans "Start Without Saved State" %}</button>

View file

@ -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={})

Binary file not shown.

View file

@ -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"

Binary file not shown.

View file

@ -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 "用途不能包含控制字符或换行符"

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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);
});

View file

@ -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();
});

View file

@ -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)
}

40
static/js/submit_busy.js Normal file
View file

@ -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", '<span class="spinner-border spinner-border-sm me-1" aria-hidden="true" data-busy-spinner></span>');
}, 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();
});

View file

@ -78,6 +78,7 @@
<!-- Bootstrap Core JavaScript -->
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'js/confirm_dialog.js' %}"></script>
<script src="{% static 'js/submit_busy.js' %}"></script>
<!-- Table sorting -->
<script src="{% static 'js/tablesort.min.js' %}"></script>
<script src="{% static 'js/tablesort.number.min.js' %}"></script>

View file

@ -1,18 +0,0 @@
{% load i18n static %}
<!-- Please wait dialog -->
<div class="modal fade" id="pleaseWaitDialog" tabindex="-1" aria-labelledby="pleaseWaitDialogLabel" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Processing" %}...</h5>
</div>
<div class="modal-body">
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated w-100" role="progressbar" aria-label="{% trans "Processing" %}" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
</div>
</div>
</div>
</div>
<script src="{% static 'js/please_wait.js' %}"></script>