-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal_send_range.html
More file actions
121 lines (105 loc) · 4.9 KB
/
Copy pathmodal_send_range.html
File metadata and controls
121 lines (105 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
textarea {
width: 100%;
height: 150px;
resize: vertical;
}
</style>
</head>
<body>
<h2>Enviar Certificados por Rango de Filas</h2>
<form id="sendRangeForm" onsubmit="return false;">
<label for="sheetUrl">URL de la hoja de cálculo:</label><br>
<input type="text" id="sheetUrl" name="sheetUrl" required><br><br>
<label for="folderUrl">URL de la carpeta con los certificados:</label><br>
<input type="text" id="folderUrl" name="folderUrl" required><br><br>
<label for="mensajeEmail">Texto adicional al correo electrónico:</label><br>
<textarea id="mensajeEmail" name="mensajeEmail" placeholder="Ingrese la información adicional que debe ser agregada al correo electrónico..."></textarea><br><br>
<label for="startRow">Fila inicial (mínimo 1):</label><br>
<input type="number" id="startRow" name="startRow" min="1" required><br><br>
<label for="endRow">Fila final (máx. 30 filas por ejecución):</label><br>
<input type="number" id="endRow" name="endRow" min="1" required><br><br>
<input type="button" id="sendBtn" value="Enviar Certificados" onclick="iniciarEnvioPorRango()">
<input type="button" id="stopBtn" value="Detener" onclick="detenerEnvio()" disabled>
</form>
<!-- Modal de Logs -->
<div id="logModal" style="display:none; position:fixed; top:10%; left:50%; transform:translateX(-50%); width:80%; max-height:70%; overflow:auto; background:white; border:2px solid #444; padding:15px; z-index:9999; box-shadow: 0px 4px 8px rgba(0,0,0,0.3); border-radius: 10px;">
<h3>📝 Registro de Ejecución</h3>
<pre id="logContenido" style="white-space: pre-wrap;"></pre>
<button onclick="cerrarLogModal()">Cerrar</button>
</div>
<script>
function iniciarEnvioPorRango() {
const sheetUrl = document.getElementById('sheetUrl').value.trim();
const folderUrl = document.getElementById('folderUrl').value.trim();
const mensajeEmail = document.getElementById('mensajeEmail').value.trim();
const startRow = parseInt(document.getElementById('startRow').value.trim(), 10);
const endRow = parseInt(document.getElementById('endRow').value.trim(), 10);
if (!sheetUrl || !folderUrl || isNaN(startRow) || isNaN(endRow)) {
alert("Por favor, completa todos los campos obligatorios.");
logMensaje("❌ Campos requeridos incompletos. Operación cancelada.");
return;
}
if (startRow < 1 || endRow < 1 || endRow < startRow) {
alert("El rango ingresado no es válido.");
logMensaje("❌ Rango inválido: inicio=" + startRow + ", fin=" + endRow);
return;
}
const cantidad = endRow - startRow + 1;
if (cantidad < 5 || cantidad > 30) {
alert("Solo puedes enviar entre 5 y 30 certificados por ejecución.");
logMensaje("❌ Se solicitó enviar " + cantidad + " certificados. Límite: 5–30.");
return;
}
bloquearFormulario(true);
logMensaje("📥 Iniciando envío de certificados por rango...");
logMensaje(`🔗 Hoja de cálculo: ${sheetUrl}`);
logMensaje(`📁 Carpeta de certificados: ${folderUrl}`);
logMensaje(`📌 Rango de filas: ${startRow} a ${endRow}`);
google.script.run
.withSuccessHandler(() => {
logMensaje("✅ Certificados enviados satisfactoriamente.");
bloquearFormulario(false);
})
.withFailureHandler((error) => {
alert("Error en el envío: " + error.message);
logMensaje("❌ Error en el envío: " + error.message);
bloquearFormulario(false);
})
.procesarYEnviarCertificadosPorRango(startRow, endRow, sheetUrl, folderUrl, mensajeEmail);
}
function detenerEnvio() {
google.script.run
.withSuccessHandler(() => {
alert("Proceso detenido.");
bloquearFormulario(false);
logMensaje("⛔ Proceso detenido por el usuario.");
})
.detenerEnvioCertificados();
}
function bloquearFormulario(bloquear) {
document.getElementById('sheetUrl').disabled = bloquear;
document.getElementById('folderUrl').disabled = bloquear;
document.getElementById('mensajeEmail').disabled = bloquear;
document.getElementById('startRow').disabled = bloquear;
document.getElementById('endRow').disabled = bloquear;
document.getElementById('sendBtn').disabled = bloquear;
document.getElementById('stopBtn').disabled = !bloquear;
}
function logMensaje(msg) {
const logModal = document.getElementById("logModal");
const logContenido = document.getElementById("logContenido");
logModal.style.display = "block";
const hora = new Date().toLocaleTimeString();
logContenido.textContent += `[${hora}] ${msg}\n`;
}
function cerrarLogModal() {
document.getElementById("logModal").style.display = "none";
}
</script>
</body>
</html>