PageSourceSearch

https://velez-santander.gov.co/SiteAssets/v1/assets/components/hom…/js/slider/manage/modal/events.js

js velez-santander.gov.co collected 2026-10-01 23:51:49 UTC 3,056 bytes, 112 lines download raw bytes

1import { state } from "../state.js";
2import { isOpen } from "./core.js";
3import { renderPage } from "./render.js";
4import { resolveIdFromButton } from "./utils.js";
5import { doSaveForId } from "./save.js";
6import { handleMenuToggle } from "./menus.js";
7import { closeAllMenus } from "../ui.js";
8
9export function installModalListeners(modalRoot) {
10  if (!state.listenersBound) state.listenersBound = {};
11  if (!state.listenersBound.pagination) {
12    modalRoot.addEventListener("click", onPaginationClick);
13    state.listenersBound.pagination = true;
14  }
15  if (!state.listenersBound.rowActions) {
16    modalRoot.addEventListener("click", onRowAction);
17    state.listenersBound.rowActions = true;
18  }
19}
20
21export function installGlobalKeyListener() {
22  if (!state.listenersBound) state.listenersBound = {};
23  if (state.listenersBound.keyboard) return;
24  state.listenersBound.keyboard = true;
25
26  document.addEventListener("keydown", (ev) => {
27    if (!isOpen()) return;
28    if (ev.key === "Escape") {
29      const anyOpen = state.modalRoot?.querySelector(
30        "[data-menu-panel]:not(.hidden)"
31      );
32      if (anyOpen) {
33        closeAllMenus();
34        return;
35      }
36      // Cerrar modal
37      const btn = state.modalRoot?.querySelector("#btn-close");
38      btn?.click();
39    }
40  });
41}
42
43export function onPaginationClick(ev) {
44  if (!isOpen()) return;
45  const btn = ev.target.closest("button[data-goto]");
46  if (!btn) return;
47  const next = Number(btn.dataset.goto);
48  if (Number.isNaN(next) || next === state.CURRENT_PAGE) return;
49  state.CURRENT_PAGE = next;
50  renderPage();
51}
52
53export async function onRowAction(ev) {
54  if (!isOpen()) return;
55  const btn = ev.target.closest("button[data-action]");
56  if (!btn) return;
57
58  const action = btn.dataset.action;
59
60  if (action === "menu-toggle") {
61    handleMenuToggle(btn);
62    return;
63  }
64
65  const id = resolveIdFromButton(btn);
66  if (!Number.isFinite(id) || id <= 0) {
67    alert("Este elemento no tiene ID válido y no puede editarse.");
68    return;
69  }
70
71  if (action === "edit") {
72    closeAllMenus();
73    const exists =
74      state.ITEMS.some(
75        (x) => resolveIdFromButton({ dataset: { id: x.Id ?? x.ID } }) === id
76      ) || state.ITEMS.some((x) => (x.Id ?? x.ID) == id);
77    if (!exists) {
78      alert("No se encontró el elemento a editar.");
79      return;
80    }
81    state.editingRowId = id;
82    renderPage();
83    return;
84  }
85
86  if (action === "cancel") {
87    closeAllMenus();
88    state.editingRowId = null;
89    renderPage();
90    return;
91  }
92
93  if (action === "save") {
94    closeAllMenus();
95    await doSaveForId(id);
96    return;
97  }
98
99  if (action === "delete") {
100    // Eliminar lo maneja tu handler global (ya lo separaste en ui/delete-handler.js)
101    closeAllMenus();
102    return;
103  }
104}
105
106export function onHeaderCancel() {
107  const id = Number(state.editingRowId);
108  if (!Number.isFinite(id) || id <= 0) return;
109  closeAllMenus();
110  state.editingRowId = null;
111  renderPage();
112}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.