| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /**
- * Calendario slot prenotazione (dashboard admin).
- */
- import { Calendar } from '@fullcalendar/core';
- import itLocale from '@fullcalendar/core/locales/it';
- import dayGridPlugin from '@fullcalendar/daygrid';
- import interactionPlugin from '@fullcalendar/interaction';
- import listPlugin from '@fullcalendar/list';
- import timeGridPlugin from '@fullcalendar/timegrid';
-
- function initSlotCalendar() {
- const calendarEl = document.getElementById('calendarioSlotPrenotazioni');
- if (!calendarEl) {
- return;
- }
-
- const dataEl = document.getElementById('calendarioSlotPrenotazioniData');
- let events = [];
- try {
- events = JSON.parse(dataEl ? dataEl.textContent : '[]');
- } catch (e) {
- events = [];
- }
- if (!Array.isArray(events)) {
- events = [];
- }
-
- const now = Date.now();
- const starts = events
- .map(function (event) {
- return event && event.start ? Date.parse(event.start) : NaN;
- })
- .filter(function (ts) {
- return !Number.isNaN(ts);
- })
- .sort(function (a, b) {
- return a - b;
- });
- const nextStart = starts.find(function (ts) {
- return ts >= now;
- });
- const initialDate = nextStart || starts[0];
-
- const calendar = new Calendar(calendarEl, {
- plugins: [dayGridPlugin, timeGridPlugin, listPlugin, interactionPlugin],
- locale: itLocale,
- firstDay: 1,
- initialView: window.innerWidth < 768 ? 'listWeek' : 'timeGridWeek',
- initialDate: initialDate ? new Date(initialDate) : undefined,
- headerToolbar: {
- left: 'prev,next today',
- center: 'title',
- right: 'dayGridMonth,timeGridWeek,listWeek'
- },
- height: 'auto',
- navLinks: true,
- nowIndicator: true,
- slotMinTime: '06:00:00',
- slotMaxTime: '22:00:00',
- events: events,
- eventClick: function (info) {
- if (info.event.url) {
- info.jsEvent.preventDefault();
- window.location.href = info.event.url;
- }
- }
- });
-
- calendar.render();
- }
-
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', initSlotCalendar);
- } else {
- initSlotCalendar();
- }
|