// The VM page (instance.html and its tabs). Page-wide values are data // attributes of #vm-summary; the others are on the element they belong to. (function () { var summary = document.getElementById("vm-summary"); // Open the tab whose control targets "#" function show_tab(target) { var controls = document.querySelectorAll('[data-bs-target], a[data-bs-toggle][href]'); for (var i = 0; i < controls.length; i++) { var c = controls[i]; if ((c.getAttribute('data-bs-target') || c.getAttribute('href')) === target) { bootstrap.Tab.getOrCreateInstance(c).show(); return; } } } function on(id, event, handler) { var element = document.getElementById(id); if (element) element.addEventListener(event, handler); } // the guest OS details, read through the guest agent function load_osinfo() { var error = $('#osinfo-error'); var silent = error[0].dataset.silent; $.getJSON(summary.dataset.osinfoUrl, function (data) { error.addClass('d-none'); $('#oshostname').text(data['host-name'] || ''); $('#osname').text(data.id || ''); $('#osprettyname').text(data['pretty-name'] || ''); $('#oskernelrelease').text(data['kernel-release'] || ''); $('#oskernelversion').text(data['kernel-version'] || ''); $('#osversion').text(data.version || ''); $('#ostimezone').text(data.zone ? data.zone + " / " + data.offset : ''); }).fail(function (xhr) { var message = xhr.responseJSON && xhr.responseJSON.error; error.text(message || silent).removeClass('d-none'); }); } function get_osinfo() { show_tab('#settings'); show_tab('#osinfo'); load_osinfo(); } on("os-details-button", "click", get_osinfo); on("osinfo-tab", "click", get_osinfo); on("clone-button", "click", function () { show_tab('#settings'); show_tab('#clone'); }); if (summary.dataset.vdiUrl) { $.get(summary.dataset.vdiUrl, function (data) { $("#vdi_url_input").attr("value", data); $("#vdi_url").attr("href", data); }); } // a switch whose form is sent as soon as it is flipped document.querySelectorAll("[data-submit-on-change]").forEach(function (input) { input.addEventListener("change", function () { input.form.submit(); }); }); // a memory snapshot freezes the guest by itself: the freeze option waits // until memory is unchecked, then is what it was on("snapshot-memory", "change", function () { var quiesce = document.getElementById('snapshot-quiesce'); if (!quiesce.dataset.offered) return; if (this.checked) quiesce.dataset.was = quiesce.checked; quiesce.disabled = this.checked; quiesce.checked = !this.checked && quiesce.dataset.was !== 'false'; }); // the Add disk dialog: the form goes where the chosen source is made, // and an existing volume is chosen from the volumes of its pool var addvol = document.getElementById('addvol'); if (addvol) { var addvolForm = document.getElementById('addvol-form'); choiceDialog(addvol, 'disk_source', function (source) { addvolForm.action = addvolForm.dataset[source]; }); } var pool = document.getElementById("selected_storage"); if (pool) { pool.addEventListener("change", function () { $.getJSON(pool.dataset.volumesUrl.replace("__pool__", encodeURIComponent(pool.value)), function (data) { var vols = $("#vols").empty(); $.each(data['vols'], function (i, item) { vols.append($("