mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46: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
|
|
@ -130,22 +130,5 @@
|
|||
</div>
|
||||
</div>
|
||||
<script src="{% static 'js/choice_dialog.js' %}"></script>
|
||||
<script>
|
||||
// the IPv6 fields show with their box; a NAT or routed network needs a
|
||||
// subnet (after the page's scripts, Bootstrap's among them)
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var ipv6 = document.getElementById('net_ipv6');
|
||||
function showIpv6() {
|
||||
var fields = document.getElementById('net_ipv6_fields');
|
||||
fields.hidden = !ipv6.checked;
|
||||
fields.querySelectorAll('input').forEach(function (input) { input.disabled = !ipv6.checked; });
|
||||
document.getElementById('net_subnet6').required = ipv6.checked;
|
||||
}
|
||||
ipv6.addEventListener('change', showIpv6);
|
||||
choiceDialog(document.getElementById('AddNetPool'), 'forward', function (mode) {
|
||||
document.getElementById('net_subnet').required = mode === 'nat' || mode === 'route';
|
||||
showIpv6();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="{% static 'js/network_dialog.js' %}"></script>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -449,47 +449,5 @@
|
|||
{% block script %}
|
||||
{% if fixed_addresses %}<script src="{% static 'js/table_filter.js' %}"></script>{% endif %}
|
||||
<script src="{% static "js/ace/ace.js" %}"></script>
|
||||
<script>
|
||||
var editor = ace.edit("edit_editor");
|
||||
editor.getSession().setMode("ace/mode/xml");
|
||||
var editInput = $('input[name="edit_xml"]');
|
||||
editor.getSession().on("change", function () {
|
||||
editInput.val(editor.getSession().getValue());
|
||||
});
|
||||
// the editor measures itself when its section is shown
|
||||
document.getElementById("network-xml").addEventListener("shown.bs.collapse", () => editor.resize());
|
||||
|
||||
// a dialog opened by a row's button gets that row's values, one opened by an Add button starts empty
|
||||
function fillFrom(dialogId, fill) {
|
||||
var dialog = document.getElementById(dialogId);
|
||||
if (dialog) dialog.addEventListener("show.bs.modal", function (event) {
|
||||
fill(dialog.querySelector("form"), event.relatedTarget.dataset);
|
||||
});
|
||||
}
|
||||
fillFrom("FixedAddress", function (form, data) {
|
||||
form.elements.original.value = data.original || "";
|
||||
form.elements.address.value = data.address || "";
|
||||
form.elements.mac.value = data.mac || "";
|
||||
form.elements.name.value = data.name || "";
|
||||
// Add starts from the first subnet, not the one a row chose before
|
||||
form.elements.ip_index.value = data.ipIndex || form.elements.ip_index.options[0].value;
|
||||
document.getElementById("fixed_subnet_row").hidden = Boolean(data.original);
|
||||
});
|
||||
fillFrom("DhcpRange", function (form, data) {
|
||||
form.elements.ip_index.value = data.ipIndex;
|
||||
form.elements.range_start.value = data.start;
|
||||
form.elements.range_end.value = data.end;
|
||||
document.getElementById("dhcp_subnet").textContent = data.subnet;
|
||||
});
|
||||
fillFrom("QosLimit", function (form, data) {
|
||||
var direction = form.elements.qos_direction;
|
||||
direction.querySelectorAll("option").forEach(function (option) {
|
||||
option.disabled = data.direction ? option.value !== data.direction : option.hasAttribute("data-taken");
|
||||
});
|
||||
direction.value = data.direction || direction.querySelector("option:not(:disabled)").value;
|
||||
form.elements.qos_average.value = data.average || "";
|
||||
form.elements.qos_peak.value = data.peak || "";
|
||||
form.elements.qos_burst.value = data.burst || "";
|
||||
});
|
||||
</script>
|
||||
<script src="{% static 'js/network_page.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue