1 | import { htmlentities } from "../../lib/js/htmlentities.js" |
2 | import { Sesion } from "../Sesion.js" |
3 | import { ROL_ID_ADMINISTRADOR } from "../ROL_ID_ADMINISTRADOR.js" |
4 | import { ROL_ID_CLIENTE } from "../ROL_ID_CLIENTE.js" |
5 | |
6 | export class MiNav extends HTMLElement { |
7 | |
8 | connectedCallback() { |
9 | |
10 | this.style.display = "block" |
11 | |
12 | this.innerHTML = |
13 | `<nav> |
14 | <ul style="display: flex; |
15 | flex-wrap: wrap; |
16 | padding:0; |
17 | gap: 0.5em; |
18 | list-style-type: none"> |
19 | <li><progress max="100">Cargando…</progress></li> |
20 | </ul> |
21 | </nav>` |
22 | |
23 | } |
24 | |
25 | |
26 | |
27 | |
28 | set sesion(sesion) { |
29 | const cue = sesion.cue |
30 | const rolIds = sesion.rolIds |
31 | let innerHTML = `<li><a href="index.html">Inicio</a></li>` |
32 | innerHTML += this.hipervinculosAdmin(rolIds) |
33 | innerHTML += this.hipervinculosCliente(rolIds) |
34 | const cueHtml = htmlentities(cue) |
35 | if (cue !== "") { |
36 | innerHTML += `<li>${cueHtml}</li>` |
37 | } |
38 | innerHTML += `<li><a href="perfil.html">Perfil</a></li>` |
39 | const ul = this.querySelector("ul") |
40 | if (ul !== null) { |
41 | ul.innerHTML = innerHTML |
42 | } |
43 | } |
44 | |
45 | |
46 | |
47 | |
48 | hipervinculosAdmin(rolIds) { |
49 | return rolIds.has(ROL_ID_ADMINISTRADOR) ? |
50 | `<li><a href="admin.html">Para administradores</a></li>` |
51 | : "" |
52 | } |
53 | |
54 | |
55 | |
56 | |
57 | hipervinculosCliente(rolIds) { |
58 | return rolIds.has(ROL_ID_CLIENTE) ? |
59 | `<li><a href="cliente.html">Para clientes</a></li>` |
60 | : "" |
61 | } |
62 | } |
63 | |
64 | customElements.define("mi-nav", MiNav) |