This commit is contained in:
Lizandro Guarnizo
2026-01-21 22:31:46 -05:00
parent ab993302f9
commit 32f5f580f7
4 changed files with 119 additions and 8 deletions
+12 -3
View File
@@ -1100,14 +1100,20 @@ class WhatsAppBotManager {
async loadTemplates() {
try {
const response = await this.apiCall('get_templates.php');
let templates = [];
if (response && response.success && Array.isArray(response.data)) {
this.updateTemplatesTable(response.data);
templates = response.data;
} else if (response && Array.isArray(response)) {
// Retrocompatibilidad por si la API devuelve directamente el array
this.updateTemplatesTable(response);
templates = response;
} else {
this.showError('Error: formato de datos inválido para plantillas');
return;
}
// Guardar en memoria para usos posteriores (ej. confirmaciones más amigables)
this.templates = templates;
this.updateTemplatesTable(templates);
} catch (error) {
this.showError('Error cargando plantillas: ' + error.message);
}
@@ -1230,7 +1236,10 @@ class WhatsAppBotManager {
}
async deleteTemplate(templateId) {
if (!confirm('¿Estás seguro de que deseas eliminar esta plantilla?')) {
const tmpl = (this.templates || []).find(t => t.id === templateId) || {};
const name = tmpl.name || tmpl.template_name || `ID ${templateId}`;
if (!confirm(`¿Estás seguro de que deseas eliminar la plantilla "${name}"? Esta acción no se puede deshacer.`)) {
return;
}
+10 -1
View File
@@ -869,7 +869,10 @@ class SimpleWhatsAppManager {
const response = await this.apiCall('get_templates.php');
if (response && response.success) {
this.updateTemplatesList(response.data || []);
const tmpl = response.data || [];
this.templatesData = tmpl;
this.templates = tmpl; // compatibilidad con app.js
this.updateTemplatesList(tmpl);
} else {
this.showError('Error cargando plantillas');
}
@@ -1553,6 +1556,12 @@ class SimpleWhatsAppManager {
}
async deleteTemplateAction(templateId) {
// intentar obtener el nombre de la plantilla para confirmar
const tmpl = (this.templatesData || []).find(t => t.id === templateId) || {};
const name = tmpl.name || tmpl.template_name || `ID ${templateId}`;
if (!confirm(`¿Estás seguro de que quiere eliminar la plantilla "${name}"? Esta acción no se puede deshacer.`)) return;
this.log(`Eliminando plantilla ID: ${templateId}`);
try {