PageSourceSearch

https://iftm.edu.br/sdsgov/visao/js/agenda.js?

js iftm.edu.br collected 2026-10-02 07:42:13 UTC 7,274 bytes, 209 lines download raw bytes

1(function () {
2  var agenda = (function () {
3    let agenda = {};
4    let carregando = false;
5    let tipo = "R";
6    let CACHE_TTL = 5 * 60 * 1000; // 5 minutos em ms
7
8    // --- Skeleton loading ---
9    agenda.mostrarSkeleton = function () {
10      let skeletons = '';
11      for (let i = 0; i < 3; i++) {
12        skeletons += '<div class="col-sm-12 col-md-4 col-lg-4 mb-4">' +
13          '<div class="if-br-card br-card p-2 skeleton-card">' +
14            '<div class="skeleton-line skeleton-title"></div>' +
15            '<div class="skeleton-line skeleton-text"></div>' +
16            '<div class="skeleton-line skeleton-text short"></div>' +
17          '</div>' +
18        '</div>';
19      }
20      $("#_container_eventos").html(skeletons);
21    };
22
23    // --- Cache sessionStorage ---
24    agenda.cacheKey = function (url, param) {
25      return "agenda_cache_" + url + "?" + param;
26    };
27
28    agenda.getCache = function (key) {
29      try {
30        let cached = sessionStorage.getItem(key);
31        if (!cached) return null;
32        let parsed = JSON.parse(cached);
33        if (Date.now() - parsed.timestamp > CACHE_TTL) {
34          sessionStorage.removeItem(key);
35          return null;
36        }
37        return parsed.data;
38      } catch (e) {
39        return null;
40      }
41    };
42
43    agenda.setCache = function (key, data) {
44      try {
45        sessionStorage.setItem(key, JSON.stringify({ data: data, timestamp: Date.now() }));
46      } catch (e) {
47        // sessionStorage cheio — ignora
48      }
49    };
50
51    // --- Lógica principal ---
52    agenda.setarTipo = function () {
53      $(".bt_tipo_agenda").removeClass("active bg-warning");
54      $(this).addClass("active bg-warning");
55      tipo = $(this).data("tipo");
56
57      let isReitor = tipo === "R";
58      $("#_titulo_autoridade").toggle(isReitor);
59      $("#_link_agenda_autoridade").toggle(isReitor);
60      $("#_titulo_evento").toggle(!isReitor);
61      $("#_link_agenda_eventos").toggle(!isReitor);
62
63      agenda.consultar($("#dtAgenda").val());
64    };
65
66    agenda.consultar = function (val, operacao) {
67      if (carregando) return;
68
69      if (tipo === "R") {
70        agenda.carregar("/sdsgov/controlador/eventosAgenda.php", val, operacao, "setor_id", "#_setor_id");
71      } else if (tipo === "E") {
72        agenda.carregar("/sdsgov/controlador/eventosIFTM.php", val, operacao, "campus_id", "#_cm_campus_id");
73      }
74    };
75
76    agenda.carregar = function (url, val, operacao, paramNome, seletorId) {
77      carregando = true;
78      let param = "data=" + encodeURIComponent(val) + "&operacao=" + encodeURIComponent(operacao || "");
79      param += "&" + paramNome + "=" + encodeURIComponent($(seletorId).val());
80
81      // Verifica cache
82      let key = agenda.cacheKey(url, param);
83      let cached = agenda.getCache(key);
84      if (cached) {
85        agenda.renderResultado(cached);
86        carregando = false;
87        return;
88      }
89
90      // Mostra skeleton enquanto carrega
91      agenda.mostrarSkeleton();
92
93      util.setShowLoadingPage(false);
94      util.getJSON(url, param)
95        .then(function (obj) {
96          agenda.setCache(key, obj);
97          agenda.renderResultado(obj);
98        })
99        .catch(function (error) {
100          console.error("Erro ao carregar agenda:", error);
101          $("#_container_eventos").html(
102            '<div class="col-12 text-center"><h5 class="text-warning">Erro ao carregar. Tente novamente.</h5></div>'
103          );
104        })
105        .finally(function () {
106          carregando = false;
107        });
108    };
109
110    // --- Day Picker ---
111    agenda.renderResultado = function (obj) {
112      $("#_day_picker").html(obj.dayPicker);
113      $("#_container_eventos").html(obj.eventos);
114      $("#dtAgenda").val(obj.data);
115      agenda.renderAtalhos();
116    };
117
118    agenda.renderAtalhos = function () {
119      let atalhos = $("#_agenda_atalhos");
120      atalhos.html("");
121      let qtd = $("._card_evento").length;
122      if (qtd > 0) {
123        for (let i = 1; i <= Math.ceil(qtd / 3); i++) {
124          let classe = i === 1 ? "dot active bt_navegar" : "dot bt_navegar";
125          atalhos.append(
126            '<button class="' + classe + '" aria-label="Página ' + i + '" data-index="' + i + '"><i class="fas fa-circle"></i></button>'
127          );
128        }
129      }
130    };
131
132    agenda.atualizar_atalhos = function () {
133      $("#_agenda_atalhos .bt_navegar").removeClass("active");
134      let index_atual = $("#_container_eventos .active").filter(":last").data("index");
135      index_atual = Math.ceil(index_atual / 3);
136      if (index_atual === 0) index_atual = 1;
137      $("#_agenda_atalhos").find('[data-index="' + index_atual + '"]').addClass("active");
138    };
139
140    agenda.anterior = function () {
141      let qtd = $("._card_evento").length;
142      if (qtd === 0) return;
143
144      let primeiro = $("#_container_eventos .active").filter(":first").data("index");
145      let ultimo = $("#_container_eventos .active").filter(":last").data("index");
146
147      if (primeiro <= 1) {
148        agenda.consultar($("#dtAgenda").val(), "A");
149      } else {
150        let aux = primeiro - 1;
151        $("#_container_eventos").find('[data-index="' + aux + '"]').addClass("active").show();
152        $("#_container_eventos").find('[data-index="' + ultimo + '"]').removeClass("active").hide();
153        agenda.atualizar_atalhos();
154      }
155    };
156
157    agenda.proximo = function () {
158      let qtd = $("._card_evento").length;
159      if (qtd === 0) return;
160
161      let primeiro = $("#_container_eventos .active").filter(":first").data("index");
162      let ultimo = $("#_container_eventos .active").filter(":last").data("index");
163
164      if (ultimo >= qtd) {
165        agenda.consultar($("#dtAgenda").val(), "P");
166      } else {
167        let aux = ultimo + 1;
168        $("#_container_eventos").find('[data-index="' + aux + '"]').addClass("active").show();
169        $("#_container_eventos").find('[data-index="' + primeiro + '"]').removeClass("active").hide();
170        agenda.atualizar_atalhos();
171      }
172    };
173
174    agenda.navegar = function () {
175      let index = $(this).data("index");
176      if (index === "+") {
177        agenda.proximo();
178      } else if (index === "-") {
179        agenda.anterior();
180      } else {
181        $("#_agenda_atalhos .bt_navegar").removeClass("active");
182        $("#_agenda_atalhos").find('[data-index="' + index + '"]').addClass("active");
183        $("._card_evento").each(function () {
184          let item_idx = $(this).data("index");
185          if (item_idx >= index * 3 - 2 && item_idx <= index * 3) {
186            $(this).show().addClass("active");
187          } else {
188            $(this).hide().removeClass("active");
189          }
190        });
191      }
192    };
193
194    $(document).ready(function () {
195      $("#dtAgenda").on("change", function () {
196        agenda.consultar($(this).val());
197      });
198
199      $("#_day_picker").on("click", ".li-sel-day", function () {
200        agenda.consultar($(this).data("value"));
201      });
202
203      $(document).on("click", ".bt_navegar", agenda.navegar);
204      $(".bt_tipo_agenda").on("click", agenda.setarTipo);
205
206      $("#dtAgenda").change();
207    });
208  })();
209})();

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.