mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 12:16:49 +00:00
refactor(templates): the host pages' scripts load from static files
The host pages lose their last inline scripts: the overview's charts (host_graphs.js), the New pool, New network and New interface dialogs (pool_dialog.js, network_dialog.js, interface_dialog.js), a network's and a network filter's XML editors and dialogs (network_page.js, nwfilter_page.js, nwfilters_page.js), the secrets page's labels (secrets_page.js, its texts from the view as usage_texts) and a pool's page with the ISO upload (storage_page.js). Their URLs and messages are data attributes of the elements they belong to; the upload reads its token and address from its form. No template has an inline script or an inline event handler any more.
This commit is contained in:
parent
946629b035
commit
50dcaba699
23 changed files with 431 additions and 407 deletions
|
|
@ -11,3 +11,21 @@ class AddSecret(forms.Form):
|
|||
value = forms.CharField(required=False, strip=False)
|
||||
ephemeral = forms.BooleanField(required=False)
|
||||
private = forms.BooleanField(required=False)
|
||||
|
||||
|
||||
# what a secret's usage and value are, per usage type, for the page's labels
|
||||
USAGE_TEXTS = {
|
||||
"ceph": {"usage": _("Ceph secret name"),
|
||||
"usageHelp": _("The name a disk or pool names it by, e.g. client.libvirt secret, not the Ceph user; one secret per name."),
|
||||
"value": _("Key"), "valueHelp": _("The key as ceph auth get-key prints it.")},
|
||||
"iscsi": {"usage": _("iSCSI target"), "usageHelp": _("The name a disk or pool names it by, e.g. the target IQN."),
|
||||
"value": _("CHAP password"), "valueHelp": _("The password as it is typed.")},
|
||||
"volume": {"usage": _("Volume path"), "usageHelp": _("The path of the encrypted volume it unlocks."),
|
||||
"value": _("Passphrase"), "valueHelp": _("The passphrase as it is typed.")},
|
||||
"tls": {"usage": _("Name"), "usageHelp": _("A name for it; qemu.conf names it by its UUID."),
|
||||
"value": _("Passphrase"), "valueHelp": _("The passphrase of the TLS key, as it is typed.")},
|
||||
"vtpm": {"usage": _("Name"), "usageHelp": _("A name for it; a VM's vTPM names it by its UUID."),
|
||||
"value": _("Passphrase"), "valueHelp": _("The passphrase as it is typed.")},
|
||||
"none": {"value": _("Value"), "valueHelp": _("The value as it is typed.")},
|
||||
"later": _("Leave it blank to give it later."),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,50 +114,6 @@
|
|||
|
||||
{% block script %}
|
||||
{% if secrets_all %}<script src="{% static 'js/table_filter.js' %}"></script>{% endif %}
|
||||
<script>
|
||||
// what a secret's usage and value are, per usage type
|
||||
var usageTexts = {
|
||||
ceph: {usage: "{{ _('Ceph secret name')|escapejs }}", usageHelp: "{{ _('The name a disk or pool names it by, e.g. client.libvirt secret, not the Ceph user; one secret per name.')|escapejs }}",
|
||||
value: "{{ _('Key')|escapejs }}", valueHelp: "{{ _('The key as ceph auth get-key prints it.')|escapejs }}"},
|
||||
iscsi: {usage: "{{ _('iSCSI target')|escapejs }}", usageHelp: "{{ _('The name a disk or pool names it by, e.g. the target IQN.')|escapejs }}",
|
||||
value: "{{ _('CHAP password')|escapejs }}", valueHelp: "{{ _('The password as it is typed.')|escapejs }}"},
|
||||
volume: {usage: "{{ _('Volume path')|escapejs }}", usageHelp: "{{ _('The path of the encrypted volume it unlocks.')|escapejs }}",
|
||||
value: "{{ _('Passphrase')|escapejs }}", valueHelp: "{{ _('The passphrase as it is typed.')|escapejs }}"},
|
||||
tls: {usage: "{{ _('Name')|escapejs }}", usageHelp: "{{ _('A name for it; qemu.conf names it by its UUID.')|escapejs }}",
|
||||
value: "{{ _('Passphrase')|escapejs }}", valueHelp: "{{ _('The passphrase of the TLS key, as it is typed.')|escapejs }}"},
|
||||
vtpm: {usage: "{{ _('Name')|escapejs }}", usageHelp: "{{ _("A name for it; a VM's vTPM names it by its UUID.")|escapejs }}",
|
||||
value: "{{ _('Passphrase')|escapejs }}", valueHelp: "{{ _('The passphrase as it is typed.')|escapejs }}"},
|
||||
none: {value: "{{ _('Value')|escapejs }}", valueHelp: "{{ _('The value as it is typed.')|escapejs }}"},
|
||||
};
|
||||
|
||||
var usageType = document.getElementById("secret_usage_type");
|
||||
if (usageType) {
|
||||
var showUsage = function () {
|
||||
var texts = usageTexts[usageType.value];
|
||||
document.getElementById("secret_usage_label").textContent = texts.usage;
|
||||
document.getElementById("secret_usage_help").textContent = texts.usageHelp;
|
||||
document.getElementById("secret_value_label").textContent = texts.value;
|
||||
document.getElementById("secret_value_help").textContent = texts.valueHelp + " {{ _('Leave it blank to give it later.')|escapejs }}";
|
||||
};
|
||||
usageType.addEventListener("change", showUsage);
|
||||
showUsage();
|
||||
}
|
||||
|
||||
{% if secrets_all %}
|
||||
document.getElementById("SetSecretValue").addEventListener("show.bs.modal", function (event) {
|
||||
var row = event.relatedTarget.dataset;
|
||||
var texts = usageTexts[row.type] || usageTexts.none;
|
||||
var form = this.querySelector("form");
|
||||
form.reset(); // no value of another secret stays in the field
|
||||
form.elements.uuid.value = row.uuid;
|
||||
document.getElementById("value_usage").textContent = row.usage;
|
||||
document.getElementById("set_value_label").textContent = texts.value;
|
||||
document.getElementById("set_value_help").textContent = texts.valueHelp;
|
||||
// a passphrase's data stays encrypted with the old one
|
||||
var passphrase = ["volume", "tls", "vtpm"].includes(row.type);
|
||||
document.getElementById("set_value_note").hidden = !passphrase;
|
||||
form.elements.value.setAttribute("aria-describedby", passphrase ? "set_value_help set_value_note" : "set_value_help");
|
||||
});
|
||||
{% endif %}
|
||||
</script>
|
||||
{{ usage_texts|json_script:"usage-texts" }}
|
||||
<script src="{% static 'js/secrets_page.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from libvirt import libvirtError
|
|||
from logs.audit import audit
|
||||
from vrtManager.virtsecrets import wvmSecrets
|
||||
|
||||
from virtsecrets.forms import AddSecret
|
||||
from virtsecrets.forms import USAGE_TEXTS, AddSecret
|
||||
|
||||
|
||||
@superuser_only
|
||||
|
|
@ -60,4 +60,4 @@ def secrets(request, compute_id):
|
|||
|
||||
usage_choices = AddSecret.base_fields["usage_type"].choices
|
||||
return render(request, "secrets.html", {"secrets_all": secrets_all, "compute": compute,
|
||||
"usage_choices": usage_choices})
|
||||
"usage_choices": usage_choices, "usage_texts": USAGE_TEXTS})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue