|
58 | 58 | var form = document.getElementById('upc-form'); |
59 | 59 | var spinner = document.getElementById('spinner'); |
60 | 60 | var submitBtn = document.getElementById('netejar-btn'); |
| 61 | + var fileInput = document.getElementById('pdf_file'); |
61 | 62 | var downloadIframe = document.getElementById('download-iframe'); |
62 | 63 | var originalBtnText = submitBtn ? submitBtn.textContent : 'Netejar'; |
63 | 64 | var alertShown = false; |
|
69 | 70 | // Ocultar spinner |
70 | 71 | spinner.style.display = 'none'; |
71 | 72 |
|
| 73 | + // Habilitar botón e input |
| 74 | + submitBtn.disabled = false; |
| 75 | + fileInput.disabled = false; |
| 76 | + submitBtn.style.opacity = '1'; |
| 77 | + submitBtn.style.cursor = 'pointer'; |
| 78 | + fileInput.style.opacity = '1'; |
| 79 | + fileInput.style.cursor = 'pointer'; |
| 80 | + |
72 | 81 | alertShown = false; |
73 | 82 | } |
74 | 83 |
|
75 | 84 | if (form && downloadIframe) { |
| 85 | + var safetyTimeout = null; |
| 86 | + |
76 | 87 | form.addEventListener('submit', function(e) { |
77 | 88 | // Cambiar texto del botón a "Netejant..." |
78 | 89 | submitBtn.textContent = 'Netejant...'; |
79 | 90 |
|
80 | 91 | // Mostrar spinner |
81 | 92 | spinner.style.display = 'inline-block'; |
82 | 93 |
|
| 94 | + // Bloquear botón e input mientras procesa |
| 95 | + submitBtn.disabled = true; |
| 96 | + fileInput.disabled = true; |
| 97 | + submitBtn.style.opacity = '0.6'; |
| 98 | + submitBtn.style.cursor = 'not-allowed'; |
| 99 | + fileInput.style.opacity = '0.6'; |
| 100 | + fileInput.style.cursor = 'not-allowed'; |
| 101 | + |
83 | 102 | alertShown = false; |
84 | 103 |
|
| 104 | + // Timeout de seguridad: SIEMPRE desbloquear después de 30 segundos |
| 105 | + if (safetyTimeout) clearTimeout(safetyTimeout); |
| 106 | + safetyTimeout = setTimeout(function() { |
| 107 | + resetForm(); |
| 108 | + }, 30000); |
| 109 | + |
85 | 110 | // Después de 5 segundos, mostrar mensaje informativo (pero mantener spinner) |
86 | 111 | setTimeout(function() { |
87 | 112 | if (!alertShown) { |
|
93 | 118 |
|
94 | 119 | // Detectar cuando el iframe ha terminado de cargar (descarga completada) |
95 | 120 | downloadIframe.addEventListener('load', function() { |
96 | | - // Esperar un poco más para asegurar que la descarga comenzó |
| 121 | + // Cancelar el timeout de seguridad si el iframe carga correctamente |
| 122 | + if (safetyTimeout) { |
| 123 | + clearTimeout(safetyTimeout); |
| 124 | + safetyTimeout = null; |
| 125 | + } |
| 126 | + |
| 127 | + // Esperar 5 segundos para asegurar que la descarga está completa |
97 | 128 | setTimeout(function() { |
98 | 129 | resetForm(); |
99 | | - }, 2000); |
| 130 | + }, 5000); |
100 | 131 | }); |
101 | 132 | } |
102 | 133 | }); |
|
0 commit comments