El helper apiFetch estaba copiado en checada/becario/panel, y el arreglo de
"Content-Type solo si hay body" solo se había puesto en panel. Ahora vive una
sola vez en theme.js (window.Theme.apiFetch) y las tres páginas lo consumen con
`const { apiFetch } = Theme;`. Mismo comportamiento que antes —mismo origen,
credentials:'include', mapeo de error por code/status/data— solo cambia de
dónde viene, no qué hace.
El helper unificado ya no declara Content-Type en un POST sin cuerpo (el logout
del becario dejaba de dar un 400 que se tragaba el catch). Con el arreglo de
backend es doble red: el servidor ya tolera el cuerpo vacío de todos modos.
Verificado: las tres páginas montan y hacen su primer apiFetch real en Chrome
headless (panel→login, becario→acceso, checada→estado sin token); aprobar/baja/
rechazar/logout sin body → 200; peticiones con body → 201; checada y becario
conservan su comportamiento (candado).
608 lines
37 KiB
JavaScript
608 lines
37 KiB
JavaScript
/*
|
|
* theme.js — base visual compartida de las tres pantallas (panel/becario/checada).
|
|
*
|
|
* Sin build step: se carga como <script src="theme.js"> DESPUÉS de React/ReactDOM
|
|
* y ANTES del <script type="text/babel"> de cada página. Expone window.Theme con:
|
|
* - COLORS paleta unificada (base común de los tres + primaryDark/accentBg del panel)
|
|
* - FONT stack tipográfico del sistema
|
|
* - SPACE escala de espaciado (para el rediseño)
|
|
* - RADIUS escala de radios
|
|
* - makeUI(flavor) → { Btn, Card, Input, Badge, Field, Estado }
|
|
*
|
|
* Los componentes viven UNA sola vez aquí; makeUI(flavor) los liga a las medidas
|
|
* exactas de cada página ('panel' escritorio, 'becario'/'checada' móvil) para que
|
|
* el resultado se vea idéntico al de hoy. El rediseño se hace tocando este archivo.
|
|
*/
|
|
window.Theme = (function () {
|
|
var COLORS = {
|
|
bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C",
|
|
border: "#DDE2E7", primary: "#2A6FB0", primaryDark: "#1E4E7E",
|
|
success: "#2E7D5B", successBg: "#E7F3EC", warn: "#B7791F", warnBg: "#FBF2E1",
|
|
danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5", accentBg: "#EAF2FA",
|
|
};
|
|
|
|
var FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
|
|
var SPACE = { none: "0", xs: "4px", sm: "8px", md: "12px", lg: "16px", xl: "20px", "2xl": "24px", "3xl": "32px" };
|
|
var RADIUS = { sm: "8px", md: "10px", lg: "12px", xl: "14px", "2xl": "16px", pill: "999px" };
|
|
|
|
// ── Rediseño móvil: paleta crema + fuentes de marca (flavors 'checada' y 'becario') ──
|
|
// No afecta a panel: sus componentes siguen usando COLORS/FONT.
|
|
var CREAM = {
|
|
bg: "#F3EBDD",
|
|
bgGradient: "radial-gradient(120% 80% at 50% -10%, #FBF5EA 0%, #F3EBDD 55%, #EFE5D3 100%)",
|
|
surface: "#FFFFFF", cardBorder: "#F0E8DA",
|
|
ink: "#2E2A24", inkSoft: "#8A8175", label: "#6E6559", placeholder: "#B4A99A", line: "#E4D9C6",
|
|
brand: "#16406B", primary: "#2E77B8", primaryDark: "#25689F",
|
|
green: "#2F8A63", greenDark: "#287854", amber: "#B7791F", danger: "#C0392B",
|
|
greenTint: "#E4F1E9", blueTint: "#E7F0F8", amberTint: "#FBF0DC", dangerTint: "#FBEBE8",
|
|
errBg: "#FBEBE8", errBorder: "#F3D3CC", errText: "#B4362A",
|
|
warnBg: "#FBF0DC", warnBorder: "#EFD9A8", warnText: "#8A5A12",
|
|
inputBorder: "#ECE3D4", inputBg: "#FBF8F2", track: "#EDE4D5", dashed: "#C7DBEC",
|
|
// Portal del becario:
|
|
neutralTint: "#EEE7D9", softTint: "#F1EADC", // píldora neutra / círculos y toggle
|
|
okBorder: "#C4E3D2", okText: "#207A52", // nota de éxito verde
|
|
metaBorder: "#CDE7D9", gold: "#F2B705", goldDark: "#E0A800", // "meta cumplida" + estrella
|
|
};
|
|
var FONT_TITLE = "'Bricolage Grotesque', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
|
|
var FONT_BODY = "'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
|
|
|
|
// Vocabulario de tonos de Badge, unión de los dos que usaban panel y becario.
|
|
var TONES = {
|
|
chip: { bg: COLORS.chip, color: COLORS.inkSoft },
|
|
success: { bg: COLORS.successBg, color: COLORS.success },
|
|
warn: { bg: COLORS.warnBg, color: COLORS.warn },
|
|
danger: { bg: COLORS.dangerBg, color: COLORS.danger },
|
|
primary: { bg: COLORS.accentBg, color: COLORS.primaryDark },
|
|
pendiente: { bg: COLORS.warnBg, color: COLORS.warn },
|
|
activo: { bg: COLORS.successBg, color: COLORS.success },
|
|
baja: { bg: COLORS.chip, color: COLORS.inkSoft },
|
|
};
|
|
|
|
// Medidas exactas por página (reproducen el look actual, píxel por píxel).
|
|
var FLAVORS = {
|
|
panel: {
|
|
card: { radius: RADIUS.lg, pad: "20px", shadow: "0 1px 3px rgba(0,0,0,0.04)", mb: undefined },
|
|
input: { pad: "9px 11px", radius: RADIUS.sm, font: "14px" },
|
|
badge: { pad: "2px 9px", nowrap: true },
|
|
btn: {
|
|
block: false, weight: 600, radius: RADIUS.sm, disabledInk: true, transition: "opacity .15s",
|
|
sizes: { sm: { pad: "6px 12px", font: "13px" }, md: { pad: "10px 18px", font: "14px" } },
|
|
defaultSize: "md",
|
|
},
|
|
},
|
|
becario: {
|
|
card: { radius: RADIUS.xl, pad: "18px", shadow: undefined, mb: "14px" },
|
|
input: { pad: "12px 14px", radius: RADIUS.md, font: "16px" },
|
|
badge: { pad: "3px 10px", nowrap: false },
|
|
btn: {
|
|
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
|
|
sizes: { md: { pad: "13px", font: "15px" } }, defaultSize: "md",
|
|
},
|
|
},
|
|
checada: {
|
|
card: { radius: RADIUS["2xl"], pad: "24px", shadow: undefined, mb: undefined },
|
|
input: { pad: "13px 14px", radius: RADIUS.md, font: "16px" },
|
|
badge: { pad: "3px 10px", nowrap: false },
|
|
btn: {
|
|
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
|
|
sizes: { md: { pad: "14px", font: "16px" } }, defaultSize: "md",
|
|
},
|
|
},
|
|
};
|
|
|
|
function btnVariant(v) {
|
|
switch (v) {
|
|
case "success": return { bg: COLORS.success, color: "#fff", border: "none" };
|
|
case "danger": return { bg: COLORS.danger, color: "#fff", border: "none" };
|
|
case "ghost": return { bg: "transparent", color: COLORS.primary, border: "1px solid " + COLORS.border };
|
|
case "subtle": return { bg: COLORS.chip, color: COLORS.ink, border: "none" };
|
|
default: return { bg: COLORS.primary, color: "#fff", border: "none" };
|
|
}
|
|
}
|
|
|
|
// ── Íconos de línea del rediseño (name -> función(opts) -> <svg>) ──
|
|
// opts: { size, color, sw (stroke-width), style }. Sin dependencias externas.
|
|
function makeIcons(React) {
|
|
var h = React.createElement;
|
|
function ic(paths, o) {
|
|
o = o || {};
|
|
var kids = paths.map(function (p, i) { return h(p[0], Object.assign({ key: i }, p[1])); });
|
|
return h("svg", {
|
|
width: o.size || 28, height: o.size || 28, viewBox: "0 0 24 24", fill: "none",
|
|
stroke: o.color || "currentColor", strokeWidth: o.sw || 1.7,
|
|
strokeLinecap: "round", strokeLinejoin: "round", style: o.style,
|
|
}, kids);
|
|
}
|
|
return {
|
|
nfc: function (o) { return ic([["rect",{x:6,y:2.5,width:9,height:19,rx:2.5}],["path",{d:"M18 8a5 5 0 0 1 0 8"}],["path",{d:"M20.6 5.4a8.5 8.5 0 0 1 0 13.2"}]], o); },
|
|
sunrise: function (o) { return ic([["path",{d:"M12 2.6v2.6"}],["path",{d:"M4.7 8 6.3 9.6"}],["path",{d:"M19.3 8 17.7 9.6"}],["path",{d:"M2.4 15h3"}],["path",{d:"M18.6 15h3"}],["path",{d:"M8 15a4 4 0 0 1 8 0"}],["path",{d:"M1.6 19h20.8"}]], o); },
|
|
moon: function (o) { return ic([["path",{d:"M20 14.6A8 8 0 1 1 9.4 4a6.5 6.5 0 0 0 10.6 10.6z"}]], o); },
|
|
check: function (o) { return ic([["path",{d:"M21.6 11.1V12a9.6 9.6 0 1 1-5.7-8.8"}],["path",{d:"M8.6 11.5 12 15l9.6-9.6"}]], o); },
|
|
hourglass: function (o) { return ic([["path",{d:"M6.5 3h11"}],["path",{d:"M6.5 21h11"}],["path",{d:"M7.5 3v3.1a5 5 0 0 0 2.8 4.5L12 12l1.7-1.4A5 5 0 0 0 16.5 6.1V3"}],["path",{d:"M7.5 21v-3.1a5 5 0 0 1 2.8-4.5L12 12l1.7 1.4a5 5 0 0 1 2.5 4.5V21"}]], o); },
|
|
clock: function (o) { return ic([["circle",{cx:12,cy:12,r:8.6}],["path",{d:"M12 7.2V12l3.2 2"}]], o); },
|
|
refresh: function (o) { return ic([["path",{d:"M3.2 12a8.8 8.8 0 0 1 15.1-6.1L21 8"}],["path",{d:"M21 3.6V8h-4.4"}],["path",{d:"M20.8 12a8.8 8.8 0 0 1-15.1 6.1L3 16"}],["path",{d:"M3 20.4V16h4.4"}]], o); },
|
|
lock: function (o) { o = o || {}; return ic([["rect",{x:4.5,y:10.5,width:15,height:10.5,rx:3}],["path",{d:"M8 10.5V7a4 4 0 0 1 8 0v3.5"}],["circle",{cx:12,cy:15.6,r:1.4,fill:o.color||"currentColor",stroke:"none"}]], o); },
|
|
alertCircle: function (o) { return ic([["circle",{cx:12,cy:12,r:9.2}],["path",{d:"M12 7.6v5"}],["path",{d:"M12 16.2h.01"}]], o); },
|
|
alertTriangle: function (o) { return ic([["path",{d:"M12 3 2.6 20h18.8L12 3z"}],["path",{d:"M12 9.6v4"}],["path",{d:"M12 17h.01"}]], o); },
|
|
calendar: function (o) { return ic([["rect",{x:3.5,y:5,width:17,height:16,rx:3}],["path",{d:"M3.5 9.5h17"}],["path",{d:"M8 3v4"}],["path",{d:"M16 3v4"}]], o); },
|
|
star: function (o) {
|
|
o = o || {};
|
|
return h("svg", { width: o.size || 20, height: o.size || 20, viewBox: "0 0 24 24",
|
|
fill: o.color || CREAM.gold, stroke: o.stroke || CREAM.goldDark, strokeWidth: 1, strokeLinejoin: "round", style: o.style },
|
|
h("path", { d: "M12 2.4l2.9 5.9 6.5.95-4.7 4.57 1.1 6.48L12 17.8l-5.8 3.06 1.1-6.48L2.6 9.25l6.5-.95z" }));
|
|
},
|
|
plus: function (o) { return ic([["path",{d:"M12 5v14"}],["path",{d:"M5 12h14"}]], o); },
|
|
chevronLeft: function (o) { return ic([["path",{d:"M14 6l-6 6 6 6"}]], o); },
|
|
x: function (o) { return ic([["path",{d:"M6 6l12 12"}],["path",{d:"M18 6 6 18"}]], o); },
|
|
users: function (o) { return ic([["circle",{cx:9,cy:8,r:3.4}],["path",{d:"M3.5 20a5.5 5.5 0 0 1 11 0"}],["path",{d:"M17 8h4"}],["path",{d:"M19 6v4"}]], o); },
|
|
listCheck: function (o) { return ic([["path",{d:"M4 6h11"}],["path",{d:"M4 11h8"}],["path",{d:"M4 16h6"}],["path",{d:"m14.5 16.5 2 2 4-4"}]], o); },
|
|
spinner: function (o) {
|
|
o = o || {};
|
|
return h("svg", { width: o.size || 18, height: o.size || 18, viewBox: "0 0 24 24", fill: "none",
|
|
style: Object.assign({ animation: "tb-spin .8s linear infinite" }, o.style || {}) },
|
|
[ h("circle", { key: 0, cx: 12, cy: 12, r: 9, stroke: o.track || "rgba(255,255,255,.35)", strokeWidth: 3 }),
|
|
h("path", { key: 1, d: "M21 12a9 9 0 0 0-9-9", stroke: o.color || "#fff", strokeWidth: 3, strokeLinecap: "round" }) ]);
|
|
},
|
|
};
|
|
}
|
|
|
|
// ── Set de componentes "cream" para el flavor 'checada' (rediseño visual) ──
|
|
// Devuelve su propia API (Logo, IconBadge, Card, Btn, Input, Aviso, Estado,
|
|
// palette, fonts, icons). Independiente del camino panel/becario.
|
|
function makeCream(React) {
|
|
var h = React.createElement;
|
|
var C = CREAM;
|
|
var fonts = { title: FONT_TITLE, body: FONT_BODY };
|
|
var icons = makeIcons(React);
|
|
// tone (string) -> stroke del glifo, tinte del círculo, color del título.
|
|
var STATE = {
|
|
green: { stroke: C.green, tint: C.greenTint, title: C.green },
|
|
blue: { stroke: C.primary, tint: C.blueTint, title: C.ink },
|
|
amber: { stroke: C.amber, tint: C.amberTint, title: C.amber },
|
|
danger: { stroke: C.danger, tint: C.dangerTint, title: C.danger },
|
|
neutral: { stroke: C.inkSoft, tint: C.softTint, title: C.ink },
|
|
};
|
|
|
|
function Logo(props) {
|
|
return h("img", { src: "logo-taboada.png", alt: "Fundación Taboada",
|
|
style: Object.assign({ height: "108px", width: "auto", display: "block" }, (props && props.style) || {}) });
|
|
}
|
|
|
|
function IconBadge(props) {
|
|
var t = STATE[props.tone] || STATE.blue;
|
|
var sz = props.size || 64;
|
|
var glyph = icons[props.icon] ? icons[props.icon]({ color: t.stroke, size: Math.round(sz * 0.47), sw: 1.7 }) : null;
|
|
return h("div", { style: { width: sz + "px", height: sz + "px", borderRadius: "50%", background: t.tint,
|
|
display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 16px" } }, glyph);
|
|
}
|
|
|
|
function Card(props) {
|
|
return h("div", { style: Object.assign({
|
|
background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "26px",
|
|
padding: "24px", boxShadow: "0 20px 44px -28px rgba(33,28,22,.35)",
|
|
}, props.style || {}) }, props.children);
|
|
}
|
|
|
|
function Btn(props) {
|
|
var ghost = props.variant === "ghost"; // secundario: contorno azul, sin relleno
|
|
var success = props.variant === "success";
|
|
var disabled = props.disabled;
|
|
var style = {
|
|
width: "100%", boxSizing: "border-box", padding: "15px", borderRadius: "16px",
|
|
fontFamily: fonts.body, fontSize: "15px", fontWeight: 700,
|
|
cursor: disabled ? "not-allowed" : (props.loading ? "progress" : "pointer"),
|
|
display: "flex", alignItems: "center", justifyContent: "center", gap: "10px",
|
|
};
|
|
if (ghost) {
|
|
style.background = "transparent";
|
|
style.border = "1.5px solid " + (disabled ? "#C6CFD8" : C.primary);
|
|
style.color = disabled ? "#B7C4D2" : C.primary;
|
|
style.boxShadow = "none";
|
|
} else {
|
|
var bg = success ? C.green : C.primary;
|
|
var shadow = success ? "0 12px 22px -10px rgba(47,138,99,.75)" : "0 12px 22px -10px rgba(46,119,184,.75)";
|
|
style.border = "none";
|
|
style.background = disabled ? "#C6CFD8" : bg;
|
|
style.color = disabled ? "#F4F8FC" : "#fff";
|
|
style.boxShadow = disabled ? "none" : shadow;
|
|
}
|
|
var kids = [];
|
|
if (props.loading) kids.push(h("span", { key: "s", style: { display: "inline-flex" } },
|
|
icons.spinner({ size: 18, color: ghost ? C.primary : "#fff", track: ghost ? C.line : undefined })));
|
|
kids.push(h("span", { key: "t" }, props.children));
|
|
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, kids);
|
|
}
|
|
|
|
function Input(props) {
|
|
var rest = Object.assign({}, props); delete rest.style;
|
|
var style = Object.assign({
|
|
width: "100%", boxSizing: "border-box", padding: "14px 15px",
|
|
border: "1.5px solid " + C.inputBorder, borderRadius: "15px", background: C.inputBg,
|
|
fontFamily: fonts.body, fontSize: "15px", color: C.ink, outline: "none",
|
|
}, props.style || {});
|
|
return h("input", Object.assign(rest, { style: style }));
|
|
}
|
|
|
|
function Aviso(props) {
|
|
var v = props.variant;
|
|
var box = v === "warn" ? { bg: C.warnBg, bd: C.warnBorder, text: C.warnText, ink: C.amber }
|
|
: v === "success" ? { bg: C.greenTint, bd: C.okBorder, text: C.okText, ink: C.green }
|
|
: { bg: C.errBg, bd: C.errBorder, text: C.errText, ink: C.danger };
|
|
var glyph = icons[props.icon] ? icons[props.icon]({ color: box.ink, size: 18, style: { flexShrink: 0 } }) : null;
|
|
return h("div", { style: { display: "flex", gap: "10px", alignItems: "flex-start",
|
|
background: box.bg, border: "1px solid " + box.bd, borderRadius: "14px", padding: "11px 13px", marginBottom: "14px" } },
|
|
[ glyph ? h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0, marginTop: "1px" } }, glyph) : null,
|
|
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "13px", fontWeight: 500, color: box.text, lineHeight: 1.45 } }, props.children) ]);
|
|
}
|
|
|
|
// Patrón ícono-en-círculo + título + mensaje (+ progreso / acción opcionales).
|
|
// props.tone: "green" | "blue" | "amber" | "danger"; props.icon: nombre en icons.
|
|
function Estado(props) {
|
|
var t = STATE[props.tone] || STATE.blue;
|
|
var cardStyle = { textAlign: "center", padding: "28px 24px" };
|
|
if (props.dashed) cardStyle.border = "1.5px dashed " + C.dashed;
|
|
var kids = [
|
|
h(IconBadge, { key: "i", icon: props.icon, tone: props.tone }),
|
|
h("h2", { key: "t", style: { margin: "0 0 8px", fontFamily: fonts.title, fontWeight: 600,
|
|
fontSize: "21px", color: t.title, letterSpacing: "-.01em", lineHeight: 1.2 } }, props.title),
|
|
];
|
|
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, fontFamily: fonts.body,
|
|
fontWeight: 400, fontSize: "14px", color: C.inkSoft, lineHeight: 1.55 } }, props.sub));
|
|
if (typeof props.progress === "number") kids.push(
|
|
h("div", { key: "pg", style: { height: "8px", borderRadius: "99px", background: C.track, marginTop: "16px", overflow: "hidden" } },
|
|
h("div", { style: { height: "100%", width: Math.max(0, Math.min(100, props.progress)) + "%", borderRadius: "99px", background: C.green } })));
|
|
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "18px" } }, props.action));
|
|
return Card({ style: cardStyle, children: kids });
|
|
}
|
|
|
|
// Píldora de estado. tone = string de estado real (activo/pendiente/cerrada/
|
|
// abierta/revision/baja/autorizada/rechazada); mapea al color, no al revés.
|
|
var BADGE = {
|
|
activo: [C.greenTint, C.green], cerrada: [C.greenTint, C.green], autorizada: [C.greenTint, C.green],
|
|
pendiente: [C.amberTint, C.amber], revision: [C.amberTint, C.amber],
|
|
abierta: [C.neutralTint, C.inkSoft],
|
|
baja: [C.dangerTint, C.danger], rechazada: [C.dangerTint, C.danger],
|
|
};
|
|
function StatusBadge(props) {
|
|
var t = BADGE[props.tone] || [C.neutralTint, C.inkSoft];
|
|
return h("span", { style: { display: "inline-block", padding: "3px 10px", borderRadius: "99px",
|
|
fontFamily: fonts.body, fontSize: "11px", fontWeight: 600, background: t[0], color: t[1], whiteSpace: "nowrap" } }, props.children);
|
|
}
|
|
|
|
// Tarjeta de horas con barra de avance. Al 100% muestra "¡Meta cumplida!".
|
|
// Pinta valores del backend (total/meta/porcentaje/sub); no calcula nada.
|
|
function HorasCard(props) {
|
|
var pct = Math.max(0, Math.min(100, props.porcentaje || 0));
|
|
var done = (props.porcentaje || 0) >= 100;
|
|
var kids = [];
|
|
if (done) {
|
|
kids.push(h("div", { key: "stripe", style: { position: "absolute", top: 0, left: 0, right: 0, height: "4px",
|
|
background: "linear-gradient(90deg," + C.green + "," + C.gold + ")" } }));
|
|
kids.push(h("div", { key: "hdr", style: { display: "flex", alignItems: "center", gap: "8px", marginBottom: "8px" } },
|
|
[ h("span", { key: "s", style: { display: "inline-flex" } }, icons.star({ size: 20 })),
|
|
h("span", { key: "t", style: { fontFamily: fonts.title, fontWeight: 700, fontSize: "15px", color: C.green } }, "¡Meta cumplida!") ]));
|
|
} else {
|
|
kids.push(h("div", { key: "lbl", style: { fontFamily: fonts.body, fontWeight: 500, fontSize: "13px", color: C.inkSoft, marginBottom: "4px" } }, "Horas acumuladas"));
|
|
}
|
|
kids.push(h("div", { key: "num", style: { fontFamily: fonts.title, fontWeight: 700, fontSize: "30px", color: C.brand, letterSpacing: "-.01em", lineHeight: 1.1 } },
|
|
[ props.total, " ", h("span", { key: "m", style: { fontFamily: fonts.body, fontWeight: 500, fontSize: "15px", color: C.inkSoft } }, "de " + props.meta) ]));
|
|
kids.push(h("div", { key: "trk", style: { height: "9px", background: C.track, borderRadius: "99px", overflow: "hidden", margin: "13px 0 8px" } },
|
|
h("div", { style: { height: "100%", width: pct + "%", background: done ? C.green : C.primary, borderRadius: "99px" } })));
|
|
kids.push(h("div", { key: "sub", style: { fontFamily: fonts.body, fontWeight: 400, fontSize: "12px", color: done ? C.green : C.inkSoft } }, props.sub));
|
|
return h("div", { style: { background: C.surface, border: "1px solid " + (done ? C.metaBorder : C.cardBorder),
|
|
borderRadius: "20px", padding: "20px", boxShadow: "0 16px 34px -28px rgba(33,28,22,.3)", position: "relative", overflow: "hidden" } }, kids);
|
|
}
|
|
|
|
return { Logo: Logo, IconBadge: IconBadge, Card: Card, Btn: Btn, Input: Input,
|
|
Aviso: Aviso, Estado: Estado, StatusBadge: StatusBadge, HorasCard: HorasCard,
|
|
palette: C, fonts: fonts, icons: icons };
|
|
}
|
|
|
|
// ── Set cream de ESCRITORIO para el flavor 'panel' (rediseño visual) ──
|
|
// Reusa paleta/fuentes/íconos cream a densidad de escritorio y añade lo propio
|
|
// del panel: Nav, Table/Tr/Td, ProgressBar, Modal, EmptyState, Toggle, ErrorBar.
|
|
// Independiente de makeCream (móvil): checada y becario no se ven afectados.
|
|
function makePanel(React) {
|
|
var h = React.createElement;
|
|
var C = CREAM;
|
|
var fonts = { title: FONT_TITLE, body: FONT_BODY };
|
|
var icons = makeIcons(React);
|
|
// tonos semánticos del panel (los helpers estadoXTone siguen en panel.html).
|
|
var BADGE = {
|
|
success: [C.greenTint, C.green], warn: [C.amberTint, C.amber],
|
|
primary: [C.blueTint, C.primary], danger: [C.dangerTint, C.danger],
|
|
chip: [C.neutralTint, C.inkSoft], neutral: [C.neutralTint, C.inkSoft],
|
|
};
|
|
|
|
function Logo(props) {
|
|
return h("img", { src: "logo-taboada.png", alt: "Fundación Taboada",
|
|
style: Object.assign({ height: "40px", width: "auto", display: "block" }, (props && props.style) || {}) });
|
|
}
|
|
|
|
function Card(props) {
|
|
return h("div", { style: Object.assign({
|
|
background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "18px",
|
|
padding: "24px", boxShadow: "0 18px 40px -30px rgba(33,28,22,.3)",
|
|
}, props.style || {}) }, props.children);
|
|
}
|
|
|
|
function Btn(props) {
|
|
var v = props.variant || "primary";
|
|
var size = props.size === "sm" ? { pad: "7px 13px", font: "13px", radius: "10px" } : { pad: "11px 18px", font: "14px", radius: "13px" };
|
|
var disabled = props.disabled;
|
|
var VAR = {
|
|
primary: { bg: C.primary, fg: "#fff", bd: "none", sh: "0 10px 20px -12px rgba(46,119,184,.7)" },
|
|
success: { bg: C.green, fg: "#fff", bd: "none", sh: "0 10px 20px -12px rgba(47,138,99,.7)" },
|
|
danger: { bg: C.danger, fg: "#fff", bd: "none", sh: "none" },
|
|
subtle: { bg: C.softTint, fg: C.label, bd: "none", sh: "none" },
|
|
ghost: { bg: "transparent", fg: C.primary, bd: "none", sh: "none" },
|
|
link: { bg: "transparent", fg: C.inkSoft, bd: "none", sh: "none" },
|
|
outline: { bg: "transparent", fg: C.label, bd: "1px solid " + C.line, sh: "none" },
|
|
};
|
|
var s = VAR[v] || VAR.primary;
|
|
var solid = v === "primary" || v === "success" || v === "danger";
|
|
var style = {
|
|
display: props.block ? "flex" : "inline-flex", width: props.block ? "100%" : "auto", boxSizing: "border-box",
|
|
alignItems: "center", justifyContent: "center", gap: "8px",
|
|
padding: size.pad, borderRadius: size.radius, border: disabled ? "none" : s.bd,
|
|
background: disabled ? "#C6CFD8" : s.bg, color: disabled ? "#F4F8FC" : s.fg,
|
|
fontFamily: fonts.body, fontSize: size.font, fontWeight: 700,
|
|
cursor: disabled ? "not-allowed" : (props.loading ? "progress" : "pointer"),
|
|
boxShadow: disabled ? "none" : s.sh, whiteSpace: "nowrap",
|
|
};
|
|
var kids = [];
|
|
if (props.loading) kids.push(h("span", { key: "s", style: { display: "inline-flex" } },
|
|
icons.spinner({ size: 15, color: solid ? "#fff" : C.primary, track: C.line })));
|
|
kids.push(h("span", { key: "t", style: { display: "inline-flex", alignItems: "center", gap: "7px" } }, props.children));
|
|
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, kids);
|
|
}
|
|
|
|
function Input(props) {
|
|
var rest = Object.assign({}, props); delete rest.style;
|
|
var style = Object.assign({
|
|
width: "100%", boxSizing: "border-box", padding: "11px 14px",
|
|
border: "1.5px solid " + C.inputBorder, borderRadius: "13px", background: C.inputBg,
|
|
fontFamily: fonts.body, fontSize: "14px", color: C.ink, outline: "none",
|
|
}, props.style || {});
|
|
return h("input", Object.assign(rest, { style: style }));
|
|
}
|
|
|
|
function Field(props) {
|
|
return h("label", { style: { display: "block", marginBottom: "14px" } },
|
|
h("span", { style: { display: "block", fontFamily: fonts.body, fontSize: "12px", fontWeight: 600, color: C.label, marginBottom: "6px" } }, props.label),
|
|
props.children);
|
|
}
|
|
|
|
function Badge(props) {
|
|
var t = BADGE[props.tone] || BADGE.chip;
|
|
return h("span", { style: { display: "inline-block", padding: "4px 11px", borderRadius: "99px",
|
|
fontFamily: fonts.body, fontSize: "12px", fontWeight: 600, background: t[0], color: t[1], whiteSpace: "nowrap" } }, props.children);
|
|
}
|
|
|
|
function Aviso(props) {
|
|
var v = props.variant;
|
|
var box = v === "warn" ? { bg: C.warnBg, bd: C.warnBorder, text: C.warnText, ink: C.amber }
|
|
: v === "success" ? { bg: C.greenTint, bd: C.okBorder, text: C.okText, ink: C.green }
|
|
: { bg: C.errBg, bd: C.errBorder, text: C.errText, ink: C.danger };
|
|
var glyph = icons[props.icon] ? icons[props.icon]({ color: box.ink, size: 18, style: { flexShrink: 0 } }) : null;
|
|
return h("div", { style: { display: "flex", gap: "10px", alignItems: "flex-start",
|
|
background: box.bg, border: "1px solid " + box.bd, borderRadius: "13px", padding: "11px 13px", marginBottom: "14px" } },
|
|
[ glyph ? h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0, marginTop: "1px" } }, glyph) : null,
|
|
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "13px", fontWeight: 500, color: box.text, lineHeight: 1.45 } }, props.children) ]);
|
|
}
|
|
|
|
// Barra de error global, descartable (mapea err.message; el mapeo por code lo
|
|
// hace quien la invoca).
|
|
function ErrorBar(props) {
|
|
if (!props.error) return null;
|
|
return h("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px",
|
|
background: C.errBg, border: "1px solid " + C.errBorder, borderRadius: "14px", padding: "12px 16px", marginBottom: "16px" } },
|
|
[ h("span", { key: "l", style: { display: "flex", alignItems: "center", gap: "10px" } },
|
|
[ h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0 } }, icons.alertTriangle({ size: 18, color: C.danger })),
|
|
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "14px", fontWeight: 500, color: C.errText } }, props.error) ]),
|
|
h("span", { key: "x", onClick: props.onClose, style: { cursor: "pointer", display: "inline-flex", flexShrink: 0 } }, icons.x({ size: 16, color: C.errText, sw: 2.2 })) ]);
|
|
}
|
|
|
|
function Toggle(props) {
|
|
var on = !!props.checked;
|
|
return h("label", { style: { display: "flex", alignItems: "center", gap: "11px", cursor: "pointer" } },
|
|
[ h("span", { key: "sw", onClick: function () { props.onChange(!on); },
|
|
style: { width: "42px", height: "24px", borderRadius: "99px", background: on ? C.primary : "#D6CDBB", position: "relative", flexShrink: 0, transition: "background .15s" } },
|
|
h("span", { style: { position: "absolute", top: "3px", left: on ? "21px" : "3px", width: "18px", height: "18px", borderRadius: "50%", background: "#fff", transition: "left .15s" } })),
|
|
props.label ? h("span", { key: "l", style: { fontFamily: fonts.body, fontSize: "14px", color: C.ink } }, props.label) : null ]);
|
|
}
|
|
|
|
function ProgressBar(props) {
|
|
var pct = Math.max(0, Math.min(100, props.value || 0));
|
|
var done = (props.value || 0) >= 100;
|
|
return h("div", { style: { height: (props.height || 7) + "px", background: C.track, borderRadius: "99px", overflow: "hidden" } },
|
|
h("div", { style: { height: "100%", width: pct + "%", background: done ? C.green : C.primary, borderRadius: "99px" } }));
|
|
}
|
|
|
|
// Navegación superior (logo + marca + pestañas + usuario + salir).
|
|
function Nav(props) {
|
|
var tab = function (t) {
|
|
var active = props.active === t.key;
|
|
return h("button", { key: t.key, onClick: function () { props.onTab(t.key); },
|
|
style: { padding: "8px 15px", borderRadius: "11px", border: "none", cursor: "pointer",
|
|
fontFamily: fonts.body, fontSize: "14px", fontWeight: 600,
|
|
background: active ? C.blueTint : "transparent", color: active ? C.primaryDark : C.inkSoft } }, t.label);
|
|
};
|
|
return h("header", { style: { background: C.surface, borderBottom: "1px solid " + C.cardBorder,
|
|
padding: "12px 24px", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: "10px" } },
|
|
[ h("div", { key: "l", style: { display: "flex", alignItems: "center", gap: "22px" } },
|
|
[ h("div", { key: "b", style: { display: "flex", alignItems: "center", gap: "10px" } },
|
|
[ h(Logo, { key: "lo", style: { height: "34px" } }),
|
|
h("span", { key: "n", style: { fontFamily: fonts.title, fontWeight: 600, fontSize: "16px", color: C.brand } }, "Supervisión") ]),
|
|
h("nav", { key: "t", style: { display: "flex", gap: "4px", flexWrap: "wrap" } }, props.tabs.map(tab)) ]),
|
|
h("div", { key: "r", style: { display: "flex", alignItems: "center", gap: "14px" } },
|
|
[ h("span", { key: "u", style: { fontFamily: fonts.body, fontSize: "13px", color: C.inkSoft } }, props.user),
|
|
h(Btn, { key: "s", variant: "ghost", size: "sm", onClick: props.onLogout }, "Salir") ]) ]);
|
|
}
|
|
|
|
// Tabla de escritorio: contenedor + thead temático. Filas con Tr/Td.
|
|
function Table(props) {
|
|
return h("div", { style: { background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "18px",
|
|
overflow: "hidden", boxShadow: "0 18px 40px -30px rgba(33,28,22,.3)" } },
|
|
h("div", { style: { overflowX: "auto" } },
|
|
h("table", { style: { width: "100%", minWidth: (props.minWidth || 0) + "px", borderCollapse: "collapse", fontFamily: fonts.body, fontSize: "14px" } },
|
|
[ h("thead", { key: "h" }, h("tr", { style: { background: "#F6F1E9", textAlign: "left" } },
|
|
props.head.map(function (c, i) {
|
|
return h("th", { key: i, style: { padding: "13px 16px", fontFamily: fonts.body, fontSize: "12px", fontWeight: 600,
|
|
color: C.placeholder, textTransform: "uppercase", letterSpacing: ".06em", whiteSpace: "nowrap" } }, c);
|
|
}))),
|
|
h("tbody", { key: "b" }, props.children) ])));
|
|
}
|
|
function Tr(props) {
|
|
return h("tr", { onClick: props.onClick, style: Object.assign({ borderTop: "1px solid " + C.cardBorder }, props.onClick ? { cursor: "pointer" } : {}) }, props.children);
|
|
}
|
|
function Td(props) {
|
|
var style = {
|
|
padding: "13px 16px", verticalAlign: "middle",
|
|
fontFamily: props.mono ? "ui-monospace,SFMono-Regular,Menlo,monospace" : fonts.body,
|
|
color: props.soft ? C.inkSoft : C.ink,
|
|
};
|
|
if (props.nowrap) style.whiteSpace = "nowrap";
|
|
if (props.ellipsis) { style.maxWidth = "220px"; style.overflow = "hidden"; style.textOverflow = "ellipsis"; style.whiteSpace = "nowrap"; }
|
|
Object.assign(style, props.style || {});
|
|
return h("td", { style: style, title: props.title }, props.children);
|
|
}
|
|
|
|
// Modal genérico (overlay + tarjeta). Mismo patrón para editar jornada,
|
|
// alta/edición de becario y confirmaciones (autorizar/rechazar/baja/cerrar).
|
|
function Modal(props) {
|
|
return h("div", { style: { position: "fixed", inset: 0, background: "rgba(33,28,22,.4)",
|
|
display: "flex", alignItems: "center", justifyContent: "center", padding: "20px", zIndex: 50 } },
|
|
h("div", { style: { width: "100%", maxWidth: (props.width || 400) + "px", background: C.surface, borderRadius: "22px",
|
|
padding: "26px", boxShadow: "0 30px 60px -20px rgba(33,28,22,.5)", maxHeight: "90vh", overflowY: "auto" } },
|
|
[ h("h3", { key: "t", style: { margin: "0 0 " + (props.sub ? "6px" : "18px"), fontFamily: fonts.title, fontWeight: 600, fontSize: "18px", color: C.brand } }, props.title),
|
|
props.sub ? h("p", { key: "s", style: { margin: "0 0 18px", fontFamily: fonts.body, fontSize: "12px", color: C.inkSoft, lineHeight: 1.5 } }, props.sub) : null,
|
|
h("div", { key: "c" }, props.children) ]));
|
|
}
|
|
|
|
// Estado vacío: círculo con ícono + título + texto + acción opcional.
|
|
function EmptyState(props) {
|
|
var TONE = { blue: [C.blueTint, C.primary], green: [C.greenTint, C.green], neutral: [C.softTint, C.inkSoft] };
|
|
var t = TONE[props.tone] || TONE.neutral;
|
|
var glyph = icons[props.icon] ? icons[props.icon]({ color: t[1], size: 27, sw: 1.6 }) : null;
|
|
var kids = [
|
|
h("div", { key: "i", style: { width: "60px", height: "60px", borderRadius: "50%", background: t[0], display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 16px" } }, glyph),
|
|
h("h3", { key: "t", style: { margin: "0 0 6px", fontFamily: fonts.title, fontWeight: 600, fontSize: "17px", color: C.brand } }, props.title),
|
|
];
|
|
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, fontFamily: fonts.body, fontSize: "13px", color: C.inkSoft, lineHeight: 1.5 } }, props.sub));
|
|
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "18px" } }, props.action));
|
|
return h("div", { style: { background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "20px",
|
|
padding: "36px 26px", textAlign: "center", boxShadow: "0 20px 44px -32px rgba(33,28,22,.35)" } }, kids);
|
|
}
|
|
|
|
return { palette: C, fonts: fonts, icons: icons, Logo: Logo, Card: Card, Btn: Btn, Input: Input, Field: Field,
|
|
Badge: Badge, Aviso: Aviso, ErrorBar: ErrorBar, Toggle: Toggle, ProgressBar: ProgressBar,
|
|
Nav: Nav, Table: Table, Tr: Tr, Td: Td, Modal: Modal, EmptyState: EmptyState };
|
|
}
|
|
|
|
function makeUI(flavor) {
|
|
var React = window.React;
|
|
var h = React.createElement;
|
|
if (flavor === "panel") return makePanel(React); // rediseño escritorio: set cream denso
|
|
if (flavor === "checada" || flavor === "becario") return makeCream(React); // rediseño móvil: set cream
|
|
var F = FLAVORS[flavor];
|
|
if (!F) throw new Error("Theme.makeUI: flavor desconocido '" + flavor + "'");
|
|
|
|
function Card(props) {
|
|
var base = {
|
|
background: COLORS.surface, border: "1px solid " + COLORS.border,
|
|
borderRadius: F.card.radius, padding: F.card.pad,
|
|
boxShadow: F.card.shadow, marginBottom: F.card.mb,
|
|
};
|
|
return h("div", { style: Object.assign(base, props.style || {}) }, props.children);
|
|
}
|
|
|
|
function Btn(props) {
|
|
var v = btnVariant(props.variant);
|
|
var size = F.btn.sizes[props.size || F.btn.defaultSize] || F.btn.sizes[F.btn.defaultSize];
|
|
var disabled = props.disabled;
|
|
var style = {
|
|
padding: size.pad, borderRadius: F.btn.radius,
|
|
background: disabled ? COLORS.border : v.bg,
|
|
color: disabled && F.btn.disabledInk ? COLORS.inkSoft : v.color,
|
|
border: v.border,
|
|
fontFamily: FONT, fontSize: size.font, fontWeight: F.btn.weight,
|
|
cursor: disabled ? "not-allowed" : "pointer",
|
|
transition: F.btn.transition,
|
|
};
|
|
if (F.btn.block) style.width = "100%";
|
|
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, props.children);
|
|
}
|
|
|
|
function Input(props) {
|
|
var rest = Object.assign({}, props);
|
|
delete rest.style;
|
|
var style = Object.assign({
|
|
width: "100%", padding: F.input.pad, borderRadius: F.input.radius,
|
|
border: "1px solid " + COLORS.border, fontSize: F.input.font,
|
|
fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none",
|
|
}, props.style || {});
|
|
return h("input", Object.assign(rest, { style: style }));
|
|
}
|
|
|
|
function Badge(props) {
|
|
var t = TONES[props.tone] || TONES.chip;
|
|
var style = {
|
|
background: t.bg, color: t.color, padding: F.badge.pad,
|
|
borderRadius: RADIUS.pill, fontSize: "12px", fontWeight: 700,
|
|
};
|
|
if (F.badge.nowrap) style.whiteSpace = "nowrap";
|
|
return h("span", { style: style }, props.children);
|
|
}
|
|
|
|
function Field(props) {
|
|
return h("label", { style: { display: "block", marginBottom: "12px" } },
|
|
h("span", { style: { display: "block", fontSize: "13px", fontWeight: 600, color: COLORS.inkSoft, marginBottom: "5px" } }, props.label),
|
|
props.children
|
|
);
|
|
}
|
|
|
|
// Patrón ícono + título + mensaje (+ botón opcional) de las pantallas de estado.
|
|
// `tone` es un COLOR (no un tono de badge): tiñe el título.
|
|
function Estado(props) {
|
|
var kids = [
|
|
h("div", { key: "e", style: { fontSize: "44px", marginBottom: "8px" } }, props.emoji),
|
|
h("h2", { key: "t", style: { margin: "0 0 6px", color: props.tone || COLORS.ink, fontSize: "20px" } }, props.title),
|
|
];
|
|
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, color: COLORS.inkSoft, fontSize: "14px", lineHeight: 1.5 } }, props.sub));
|
|
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "16px" } }, props.action));
|
|
return Card({ style: { textAlign: "center" }, children: kids });
|
|
}
|
|
|
|
return { Btn: Btn, Card: Card, Input: Input, Badge: Badge, Field: Field, Estado: Estado };
|
|
}
|
|
|
|
// ── Cliente HTTP compartido por checada/becario/panel ─────────────────────
|
|
// Vive UNA sola vez aquí (antes estaba duplicado en las tres páginas). Mismo
|
|
// origen detrás de nginx; credentials:'include' manda la cookie de sesión. El
|
|
// Content-Type JSON se declara SOLO cuando de verdad hay body: anunciarlo en
|
|
// un POST sin cuerpo hacía que Fastify respondiera 400. El error lleva
|
|
// code/status/data para que cada página mapee por `code` igual que antes.
|
|
async function apiFetch(path, options) {
|
|
options = options || {};
|
|
var headers = Object.assign({}, options.headers || {});
|
|
if (options.body != null) headers["Content-Type"] = "application/json";
|
|
var res = await window.fetch(
|
|
window.location.origin + "/api" + path,
|
|
Object.assign({ credentials: "include" }, options, { headers: headers })
|
|
);
|
|
var data = await res.json().catch(function () { return {}; });
|
|
if (!res.ok) {
|
|
var err = new Error(data.error || "HTTP " + res.status);
|
|
err.code = data.code;
|
|
err.status = res.status;
|
|
err.data = data;
|
|
throw err;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
return { COLORS: COLORS, FONT: FONT, SPACE: SPACE, RADIUS: RADIUS, makeUI: makeUI, apiFetch: apiFetch };
|
|
})();
|