Actualizar solicitar.html
This commit is contained in:
@@ -45,6 +45,15 @@
|
|||||||
|
|
||||||
<div id="servicesList" class="space-y-4 pb-24 hidden fade-in">
|
<div id="servicesList" class="space-y-4 pb-24 hidden fade-in">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="restrictedMsg" class="hidden text-center py-16 bg-white rounded-3xl border border-slate-100 shadow-sm mt-4 fade-in">
|
||||||
|
<div class="w-16 h-16 bg-rose-50 text-rose-500 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||||
|
<i data-lucide="lock" class="w-8 h-8"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="font-black text-slate-800 text-lg uppercase tracking-tight">Acceso Restringido</h3>
|
||||||
|
<p class="text-xs text-slate-400 font-medium mt-2 px-6">Tu perfil está configurado como "Operario Cerrado".<br><br>No puedes acceder a la bolsa libre. Por favor, atiende únicamente los servicios que te hayan sido asignados desde la oficina.</p>
|
||||||
|
<a href="asignados.html" class="inline-block mt-6 bg-slate-900 text-white text-xs font-black uppercase tracking-widest px-6 py-3 rounded-xl shadow-lg active:scale-95 transition-transform">Ver Mis Asignados</a>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
||||||
@@ -53,7 +62,7 @@
|
|||||||
<i data-lucide="layout-grid" class="w-6 h-6 mb-1"></i>
|
<i data-lucide="layout-grid" class="w-6 h-6 mb-1"></i>
|
||||||
<span class="text-[9px] font-black uppercase tracking-widest">Inicio</span>
|
<span class="text-[9px] font-black uppercase tracking-widest">Inicio</span>
|
||||||
</a>
|
</a>
|
||||||
<button onclick="loadAvailableServices()" class="flex flex-col items-center p-2 text-primary-dynamic transition-transform active:scale-95">
|
<button onclick="loadAvailableServices()" id="btnRecargar" class="flex flex-col items-center p-2 text-primary-dynamic transition-transform active:scale-95">
|
||||||
<i data-lucide="refresh-cw" class="w-6 h-6 mb-1"></i>
|
<i data-lucide="refresh-cw" class="w-6 h-6 mb-1"></i>
|
||||||
<span class="text-[9px] font-black uppercase tracking-widest">Recargar</span>
|
<span class="text-[9px] font-black uppercase tracking-widest">Recargar</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -112,6 +121,7 @@
|
|||||||
let userGuilds = [];
|
let userGuilds = [];
|
||||||
let myUserId = null;
|
let myUserId = null;
|
||||||
let myUserName = "";
|
let myUserName = "";
|
||||||
|
let isRestricted = false;
|
||||||
|
|
||||||
// --- SISTEMA DE TEMA DINÁMICO ---
|
// --- SISTEMA DE TEMA DINÁMICO ---
|
||||||
async function applyTheme() {
|
async function applyTheme() {
|
||||||
@@ -135,13 +145,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
|
if (!localStorage.getItem("token")) {
|
||||||
window.location.href = "index.html"; return;
|
window.location.href = "index.html"; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprobación de seguridad en caché primero
|
||||||
|
const currentRole = localStorage.getItem("role");
|
||||||
|
if (currentRole !== 'operario' && currentRole !== 'operario_cerrado') {
|
||||||
|
window.location.href = "index.html"; return;
|
||||||
|
}
|
||||||
|
|
||||||
await applyTheme();
|
await applyTheme();
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
await fetchUserData(); // Para saber qué zonas y gremios puede ver
|
await fetchUserData(); // Para saber qué zonas, gremios y rol tiene
|
||||||
|
|
||||||
|
// Si el backend nos confirmó que es un operario cerrado, paramos todo
|
||||||
|
if (isRestricted) {
|
||||||
|
document.getElementById('loader').classList.add('hidden');
|
||||||
|
document.getElementById('restrictedMsg').classList.remove('hidden');
|
||||||
|
document.getElementById('btnRecargar').style.display = 'none'; // Quitamos el botón de recargar
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si está libre, cargamos la bolsa
|
||||||
await loadStatuses();
|
await loadStatuses();
|
||||||
await loadGuilds();
|
await loadGuilds();
|
||||||
loadAvailableServices();
|
loadAvailableServices();
|
||||||
@@ -152,6 +179,12 @@
|
|||||||
const res = await fetch(`${API_URL}/auth/me`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/auth/me`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.ok && data.user) {
|
if (data.ok && data.user) {
|
||||||
|
|
||||||
|
// VALIDACIÓN DE ROL RESTRINGIDO
|
||||||
|
if (data.user.role === 'operario_cerrado') {
|
||||||
|
isRestricted = true;
|
||||||
|
}
|
||||||
|
|
||||||
myUserId = data.user.id;
|
myUserId = data.user.id;
|
||||||
myUserName = data.user.full_name;
|
myUserName = data.user.full_name;
|
||||||
userZones = Array.isArray(data.user.zones) ? data.user.zones.map(z => z.cps) : [];
|
userZones = Array.isArray(data.user.zones) ? data.user.zones.map(z => z.cps) : [];
|
||||||
@@ -183,6 +216,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadAvailableServices() {
|
async function loadAvailableServices() {
|
||||||
|
if (isRestricted) return; // Doble seguridad
|
||||||
|
|
||||||
document.getElementById('servicesList').classList.add('hidden');
|
document.getElementById('servicesList').classList.add('hidden');
|
||||||
document.getElementById('loader').classList.remove('hidden');
|
document.getElementById('loader').classList.remove('hidden');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user