up
This commit is contained in:
+12
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user