|
|
@@ -515,3 +515,138 @@ function openConsole(vmName) {
|
|
|
alert('Error al abrir consola');
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+// Open ISO Management Modal
|
|
|
+function openISOManagementModal() {
|
|
|
+ const modal = new bootstrap.Modal(document.getElementById('isoManagementModal'));
|
|
|
+ loadISOs();
|
|
|
+ setupUploadISOForm();
|
|
|
+ modal.show();
|
|
|
+}
|
|
|
+
|
|
|
+// Load ISOs for management
|
|
|
+async function loadISOs() {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`${API_BASE}/isos`);
|
|
|
+ const data = await response.json();
|
|
|
+ const tbody = document.getElementById('isoTableBody');
|
|
|
+
|
|
|
+ if (!data.isos || data.isos.length === 0) {
|
|
|
+ tbody.innerHTML = '<tr><td colspan="2" class="text-center text-muted">No hay ISOs subidas</td></tr>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ tbody.innerHTML = data.isos.map(iso => `
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <i class="bi bi-disc"></i> ${iso.name}
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <button class="btn btn-sm btn-danger" onclick="deleteISO('${iso.name}')">
|
|
|
+ <i class="bi bi-trash"></i> Eliminar
|
|
|
+ </button>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `).join('');
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error loading ISOs:', error);
|
|
|
+ document.getElementById('isoTableBody').innerHTML = '<tr><td colspan="2" class="text-center text-danger">Error al cargar ISOs</td></tr>';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Setup ISO upload form
|
|
|
+function setupUploadISOForm() {
|
|
|
+ const form = document.getElementById('uploadIsoForm');
|
|
|
+ if (!form.dataset.listenerAdded) {
|
|
|
+ form.addEventListener('submit', uploadISO);
|
|
|
+ form.dataset.listenerAdded = 'true';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Upload ISO
|
|
|
+async function uploadISO(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ const isoFile = document.getElementById('isoFile');
|
|
|
+ const uploadBtn = document.getElementById('uploadBtn');
|
|
|
+ const progressContainer = document.getElementById('progressContainer');
|
|
|
+ const uploadProgress = document.getElementById('uploadProgress');
|
|
|
+
|
|
|
+ if (!isoFile.files.length) {
|
|
|
+ alert('Por favor selecciona un archivo');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', isoFile.files[0]);
|
|
|
+
|
|
|
+ uploadBtn.disabled = true;
|
|
|
+ progressContainer.style.display = 'block';
|
|
|
+
|
|
|
+ try {
|
|
|
+ const xhr = new XMLHttpRequest();
|
|
|
+
|
|
|
+ xhr.upload.addEventListener('progress', (e) => {
|
|
|
+ if (e.lengthComputable) {
|
|
|
+ const percentComplete = (e.loaded / e.total) * 100;
|
|
|
+ uploadProgress.style.width = percentComplete + '%';
|
|
|
+ uploadProgress.setAttribute('aria-valuenow', percentComplete);
|
|
|
+ uploadProgress.textContent = Math.round(percentComplete) + '%';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ xhr.addEventListener('load', () => {
|
|
|
+ if (xhr.status === 200) {
|
|
|
+ const result = JSON.parse(xhr.responseText);
|
|
|
+ alert(result.message || 'ISO subida correctamente');
|
|
|
+ document.getElementById('uploadIsoForm').reset();
|
|
|
+ progressContainer.style.display = 'none';
|
|
|
+ uploadProgress.style.width = '0%';
|
|
|
+ uploadProgress.textContent = '0%';
|
|
|
+ loadISOs();
|
|
|
+ loadISOsForSelect();
|
|
|
+ } else {
|
|
|
+ const result = JSON.parse(xhr.responseText);
|
|
|
+ alert(result.error || 'Error al subir ISO');
|
|
|
+ progressContainer.style.display = 'none';
|
|
|
+ }
|
|
|
+ uploadBtn.disabled = false;
|
|
|
+ });
|
|
|
+
|
|
|
+ xhr.addEventListener('error', () => {
|
|
|
+ alert('Error al subir ISO');
|
|
|
+ progressContainer.style.display = 'none';
|
|
|
+ uploadBtn.disabled = false;
|
|
|
+ });
|
|
|
+
|
|
|
+ xhr.open('POST', `${API_BASE}/upload-iso`);
|
|
|
+ xhr.send(formData);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error:', error);
|
|
|
+ alert(`Error: ${error.message}`);
|
|
|
+ uploadBtn.disabled = false;
|
|
|
+ progressContainer.style.display = 'none';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Delete ISO
|
|
|
+async function deleteISO(name) {
|
|
|
+ if (confirm(`¿Estás seguro de que quieres eliminar ${name}?`)) {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`${API_BASE}/isos/${name}`, { method: 'DELETE' });
|
|
|
+ const result = await response.json();
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ alert('ISO eliminada correctamente');
|
|
|
+ loadISOs();
|
|
|
+ loadISOsForSelect();
|
|
|
+ } else {
|
|
|
+ alert(result.error || 'Error al eliminar ISO');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error:', error);
|
|
|
+ alert(`Error: ${error.message}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|