1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +00:00
webvirtcloud/instances/templates/instances/power_tab.html
catborise c401479cf9 feat(templates): every confirmation asks in the page's own dialog
Deleting or detaching a disk, deleting a network card, forcing a VM off,
reverting or deleting a snapshot, stopping or deleting a pool, a
network, an interface, a filter or a secret, and the other actions that
ask first opened the browser's yes/no box (confirm()), and the ISO
upload told its mistakes in the browser's alert().

One dialog in the base page now asks for all of them: its title and
confirming button carry the button's own words, its body the button's
question, the confirming button red for a destructive action. Confirmed,
the button is clicked again, so its form sends what it did before. A
button inside another dialog (the flavors) hides that one while asking
and shows it again after; Cancel gives the focus back, and the
confirming button acts once. The ISO upload's mistakes show in its
dialog's error box, announced.
2026-10-31 20:44:39 +03:00

59 lines
4.9 KiB
HTML

{% load i18n %}
{% load vm_states %}
<div class="tab-pane active mt-3" id="power" role="tabpanel">
{% if not can_power %}
<p>{% trans "Only the owners of this instance and administrators can change its power state." %}</p>
{% else %}
{# the actions the VM's state allows this user (states.allowed_actions): those that keep the guest's data, and those that cut the power #}
{% vm_state instance.status as state %}
<div class="card">
<div class="card-body">
<p class="small text-body-secondary mb-2">{% trans "Power" %} · {{ state.0 }}</p>
{% if "poweroff" in power_actions or "suspend" in power_actions or "resume" in power_actions or "poweron" in power_actions or "force_off" in power_actions or "powercycle" in power_actions %}
<div class="row g-3">
{% if "poweroff" in power_actions or "suspend" in power_actions or "resume" in power_actions or "poweron" in power_actions %}
<form class="col-12 col-md-6" method="post"{% if "poweron" in power_actions %} action="{% url 'instances:poweron' instance.id %}" onsubmit="showPleaseWaitDialog()"{% endif %}>{% csrf_token %}
<div class="btn-group mb-2" role="group" aria-label="{% trans "Power actions that keep the guest's data" %}">
{% if "poweron" in power_actions %}<button type="submit" class="btn btn-primary" name="poweron">{% trans "Power On" %}</button>{% endif %}
{% if "poweroff" in power_actions %}<button type="submit" class="btn btn-primary" name="poweroff" formaction="{% url 'instances:poweroff' instance.id %}">{% trans "Power Off" %}</button>{% endif %}
{% if "resume" in power_actions %}<button type="submit" class="btn btn-primary" name="resume" formaction="{% url 'instances:resume' instance.id %}">{% trans "Resume" %}</button>{% endif %}
{% if "suspend" in power_actions %}<button type="submit" class="btn btn-secondary" name="suspend" formaction="{% url 'instances:suspend' instance.id %}">{% trans "Suspend" %}</button>{% endif %}
</div>
<p class="small text-body-secondary mb-0">
{% if "poweron" in power_actions %}{% trans "Power On starts the VM." %}{% endif %}
{% if "poweroff" in power_actions %}{% trans "Power Off asks the guest to shut down; the guest decides." %}{% endif %}
{% if "resume" in power_actions %}{% trans "Resume lets the paused VM run on." %}{% endif %}
{% if "suspend" in power_actions %}{% trans "Suspend pauses its vCPUs; the VM stays in memory." %}{% endif %}
</p>
</form>
{% endif %}
{% if "force_off" in power_actions or "powercycle" in power_actions %}
<form class="col-12 col-md-6" method="post">{% csrf_token %}
<div class="btn-group mb-2" role="group" aria-label="{% trans "Power actions that cut the power" %}">
{% if "powercycle" in power_actions %}
<button type="submit" class="btn btn-danger" name="powercycle" formaction="{% url 'instances:powercycle' instance.id %}"
data-confirm="{% blocktrans with name=instance.name %}Power cycle {{ name }}? It stops at once, as after a power cut, and starts again; what the guest has not written to disk is lost.{% endblocktrans %}">{% trans "Power Cycle" %}</button>
{% endif %}
{% if "force_off" in power_actions %}
<button type="submit" class="btn btn-danger" name="powerforce" formaction="{% url 'instances:force_off' instance.id %}"
data-confirm="{% blocktrans with name=instance.name %}Force off {{ name }}? It stops at once, as after a power cut; what the guest has not written to disk is lost.{% endblocktrans %}">{% trans "Force Off" %}</button>
{% endif %}
</div>
<p class="small text-body-secondary mb-0">
{% trans "These cut the power: what the guest has not written to disk is lost." %}
{% if "powercycle" in power_actions %}{% trans "Power Cycle then starts the VM again, with the settings pending its next start." %}{% endif %}
</p>
</form>
{% endif %}
</div>
{% elif instance.status == 3 %}
<p class="mb-0">{% trans "The VM is paused. An administrator can resume it." %}</p>
{% elif instance.status == 5 and instance.is_template %}
<p class="mb-0">{% trans "A template is not started: clone it to make a VM." %}</p>
{% else %}
<p class="mb-0">{% trans "There is no power action for the VM in this state." %}</p>
{% endif %}
</div>
</div>
{% endif %}
</div>