fix: insertar funciones JS faltantes (populateInstallerJobsSelect y escapeHtml) para popular el selector de instaladores

This commit is contained in:
DANYDHSV 2026-07-28 15:17:20 -06:00
parent e5242bf79c
commit d869499990

View File

@ -2638,6 +2638,69 @@ $installersData = json_decode($config['installersDataWhatsApp'] ?? '{"instalador
} }
renderTable(); renderTable();
function escapeHtml(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function populateInstallerJobsSelect() {
const select = document.getElementById('installerJobsSelect');
if (!select) return;
let installerList = Array.isArray(store.installers) ? [...store.installers] : [];
const installerIds = installerList.map(i => String(i.id));
if (Array.isArray(store.admins)) {
store.admins.forEach(admin => {
if (!installerIds.includes(String(admin.id))) {
installerList.push({
id: admin.id,
nombre: admin.nombre,
whatsapp: ''
});
}
});
}
const currentVal = select.value;
select.innerHTML = '<option value="">-- Selecciona un instalador --</option>' +
installerList.map(inst => {
const phoneInfo = inst.whatsapp ? ` (${inst.whatsapp})` : '';
return `<option value="${inst.id}">${escapeHtml(inst.nombre)}${phoneInfo}</option>`;
}).join('');
if (currentVal) select.value = currentVal;
}
window.onInstallerSelectChange = function(installerId) {
if (!installerId) {
document.getElementById('jobsEmptyState').style.display = 'block';
document.getElementById('jobsLoading').style.display = 'none';
document.getElementById('jobsTableWrapper').style.display = 'none';
document.getElementById('jobsNoResults').style.display = 'none';
return;
}
let installer = (store.installers || []).find(i => String(i.id) === String(installerId));
if (!installer && Array.isArray(store.admins)) {
const adminObj = store.admins.find(a => String(a.id) === String(installerId));
if (adminObj) installer = { id: adminObj.id, nombre: adminObj.nombre };
}
const installerName = installer ? installer.nombre : `ID ${installerId}`;
loadInstallerJobs(installerId, installerName);
};
window.openInstallerJobsFromCrud = function(installerId, installerName) {
switchTab('installer-jobs');
const select = document.getElementById('installerJobsSelect');
if (select) select.value = installerId;
loadInstallerJobs(installerId, installerName);
};
window.editInstaller = function(index) { window.editInstaller = function(index) {
const installer = store.installers[index]; const installer = store.installers[index];