Actualizar configuracion.html
This commit is contained in:
@@ -1268,25 +1268,51 @@
|
|||||||
} catch(e) { console.error("Error creds"); }
|
} catch(e) { console.error("Error creds"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// LÓGICA PORTAL CLIENTE
|
// LÓGICA PORTAL CLIENTE
|
||||||
// ==========================================
|
// ==========================================
|
||||||
async function loadPortalConfig() {
|
async function loadPortalConfig() {
|
||||||
try {
|
try {
|
||||||
|
// 1. Cargamos TODOS tus gremios de la base de datos
|
||||||
|
const resGuilds = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
|
const dataGuilds = await resGuilds.json();
|
||||||
|
let allGuilds = dataGuilds.ok ? dataGuilds.guilds : [];
|
||||||
|
|
||||||
|
// 2. Cargamos la configuración del portal
|
||||||
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok && data.config) {
|
if (data.ok && data.config) {
|
||||||
document.getElementById('confCompanyName').value = data.config.full_name || "";
|
document.getElementById('confCompanyName').value = data.config.full_name || "";
|
||||||
if (data.config.company_logo) {
|
if (data.config.company_logo) {
|
||||||
document.getElementById('confLogoBase64').value = data.config.company_logo;
|
document.getElementById('confLogoBase64').value = data.config.company_logo;
|
||||||
document.getElementById('logoPreview').innerHTML = `<img src="${data.config.company_logo}" class="w-full h-full object-contain">`;
|
document.getElementById('logoPreview').innerHTML = `<img src="${data.config.company_logo}" class="w-full h-full object-contain">`;
|
||||||
}
|
}
|
||||||
if (data.config.portal_settings) {
|
|
||||||
const s = data.config.portal_settings;
|
const s = data.config.portal_settings || {};
|
||||||
if(s.m_start) document.getElementById('mStart').value = s.m_start;
|
if(s.m_start) document.getElementById('mStart').value = s.m_start;
|
||||||
if(s.m_end) document.getElementById('mEnd').value = s.m_end;
|
if(s.m_end) document.getElementById('mEnd').value = s.m_end;
|
||||||
if(s.a_start) document.getElementById('aStart').value = s.a_start;
|
if(s.a_start) document.getElementById('aStart').value = s.a_start;
|
||||||
if(s.a_end) document.getElementById('aEnd').value = s.a_end;
|
if(s.a_end) document.getElementById('aEnd').value = s.a_end;
|
||||||
|
|
||||||
|
// 3. Pintamos los checkboxes de los gremios
|
||||||
|
const visibleGuilds = s.visible_guilds || [];
|
||||||
|
const container = document.getElementById('portalGuildsList');
|
||||||
|
container.innerHTML = ''; // Limpiar el "Cargando..."
|
||||||
|
|
||||||
|
if(allGuilds.length === 0) {
|
||||||
|
container.innerHTML = '<p class="text-xs text-slate-400">No tienes gremios creados aún.</p>';
|
||||||
|
} else {
|
||||||
|
allGuilds.forEach(g => {
|
||||||
|
// Si el ID de este gremio está guardado, lo marcamos
|
||||||
|
const isChecked = visibleGuilds.includes(g.id) ? 'checked' : '';
|
||||||
|
container.innerHTML += `
|
||||||
|
<label class="flex items-center gap-3 p-3 bg-white border border-slate-200 rounded-xl cursor-pointer hover:bg-slate-50 hover:border-blue-300 transition-colors shadow-sm">
|
||||||
|
<input type="checkbox" value="${g.id}" class="portal-guild-cb w-4 h-4 text-blue-600 rounded border-slate-300 focus:ring-blue-500" ${isChecked}>
|
||||||
|
<span class="text-sm font-bold text-slate-700 truncate">${g.name}</span>
|
||||||
|
</label>
|
||||||
|
`;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) { console.error("Error portal"); }
|
} catch (e) { console.error("Error portal"); }
|
||||||
@@ -1307,12 +1333,19 @@
|
|||||||
const btn = document.getElementById('btnSavePortal'), original = btn.innerHTML;
|
const btn = document.getElementById('btnSavePortal'), original = btn.innerHTML;
|
||||||
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Guardando...';
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
|
// 🛠️ Recogemos todos los checkboxes que estén marcados
|
||||||
|
const selectedGuilds = Array.from(document.querySelectorAll('.portal-guild-cb:checked')).map(cb => parseInt(cb.value));
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
company_name: document.getElementById('confCompanyName').value,
|
company_name: document.getElementById('confCompanyName').value,
|
||||||
company_logo: document.getElementById('confLogoBase64').value,
|
company_logo: document.getElementById('confLogoBase64').value,
|
||||||
portal_settings: {
|
portal_settings: {
|
||||||
m_start: document.getElementById('mStart').value, m_end: document.getElementById('mEnd').value,
|
m_start: document.getElementById('mStart').value,
|
||||||
a_start: document.getElementById('aStart').value, a_end: document.getElementById('aEnd').value
|
m_end: document.getElementById('mEnd').value,
|
||||||
|
a_start: document.getElementById('aStart').value,
|
||||||
|
a_end: document.getElementById('aEnd').value,
|
||||||
|
visible_guilds: selectedGuilds // <--- Guardamos los IDs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user