<#macro commonsAppJS > <#macro headerTitle form=form > <#if form.title?has_content> document.addEventListener('DOMContentLoaded', function() { /* Add Form title */ const pageTitle = document.querySelector('#feature-title + .page-title'); if (pageTitle) { pageTitle.textContent = pageTitle.textContent.trim( ) + ' : ' + '${form.title!?js_string}'; } }); <#-- -- Check if the checkbox must be checked or not -- @param code the checkbox code -- @param referecenlist the default values list -- @return the String 'checked="checked" if the checkbox must be checked, an empty String otherwise --> <#function getChecked code reference_list> <#if reference_list?has_content><#list reference_list as reference_item><#if reference_item.code = code><#if reference_item.checked><#return "checked='checked'"><#else><#return ""><#return ""> <#-- -- Get the value of the parameter -- @param code the code of the parameter -- @param referecenlist the default values list -- @return the value of the parameter --> <#function getName code reference_list> <#if reference_list?has_content><#list reference_list as reference_item><#if reference_item.code = code><#return reference_item.name><#return ""> <#-- -- Get the field from a given title -- @param entry the entry -- @param fieldTitle the title -- @return the field --> <#function getField entry fieldTitle> <#if entry.fields?? && entry.fields?has_content><#list entry.fields as field><#if field?? && field.title?? && field.title == fieldTitle><#return field> <#-- -- Get the field value from a given entry and a given title -- @param entry the entry -- @param fieldTitle the title -- @return the field --> <#function getFieldValue entry fieldTitle> <#if getField( entry, fieldTitle )??><#assign field = getField( entry, fieldTitle )><#return field.value><#return ""> <#-- -- Get the max files value of an entry -- @param entry the entry -- @return the number of max authorized uploaded files --> <#function getMaxFiles entry> <#assign fieldMaxFiles = getFieldValueByCode( entry, "max_files" )><#if fieldMaxFiles?? && fieldMaxFiles != ""><#return fieldMaxFiles><#return "1"> <#-- -- Get the max size an uploaded file is authorized to have -- @param entry the entry -- @return the max size --> <#function getFileMaxSize entry> <#assign fieldFileMaxSize = getFieldValueByCode( entry, "file_max_size" )> <#if fieldFileMaxSize?? && fieldFileMaxSize != ""><#return fieldFileMaxSize><#else><#if getField( entry, "option" )??><#assign fieldFileMaxSize = getFieldValueByCode( entry, "option" )><#return fieldFileMaxSize.width><#return "5242880"> <#-- -- Check if the given entry must export the binary -- @param entry the entry -- @return true if it must export the binaries, false otherwise --> <#function exportBinary entry> <#assign field = getFieldValue( entry, "export_binary" ) /><#if field?? && field = "true"><#return true /><#return false /> <#-- -- Get the field value from a given entry and a given title -- @param entry the entry -- @param fieldTitle the title -- @return the field --> <#function getFieldValueByCode entry fieldCode> <#if getFieldByCode( entry, fieldCode )??><#assign field = getFieldByCode( entry, fieldCode )><#return field.value><#return ""> <#-- -- Get the field from a given code -- @param entry the entry -- @param fieldCode the code -- @return the field --> <#function getFieldByCode entry fieldCode> <#if entry.fields?? && entry.fields?has_content><#list entry.fields as field><#if field?? && field.code?? && field.code == fieldCode><#return field> <#function getResponseContainingTheFieldWithCode responses fieldCode> <#if responses??> <#list responses as response> <#if response.field?? && response.field.code?? && response.field.code == fieldCode > <#return response /> <#macro getCommentModal modalId modalTitle idComment idStartingDate idEndingDate idStartingTime idEndingTime action idForm mailingList locale=locale from="" additionalParameters="" inline=false current={}> <#switch modalId> <#case 'modify-comment'> <#assign startDateLabel='#i18n{appointment.modify_comment.labelStartingValidityDate}'> <#assign startTimeLabel='#i18n{appointment.modify_comment.labelStartingValidityTime}'> <#assign endDateLabel='#i18n{appointment.modify_comment.labelEndingValidityDate}'> <#assign endDateHelp='#i18n{appointment.modify_comment.labelEndingValidityDate}'> <#assign endTimeLabel='#i18n{appointment.modify_comment.labelEndingValidityTime}'> <#break> <#default> <#assign startDateLabel='#i18n{appointment.create_comment.labelStartingValidityDate}'> <#assign startTimeLabel='#i18n{appointment.create_comment.labelStartingValidityTime}'> <#assign endDateLabel='#i18n{appointment.create_comment.labelEndingValidityDate}'> <#assign endDateHelp='#i18n{appointment.create_comment.labelEndingValidityDate}'> <#assign endTimeLabel='#i18n{appointment.create_comment.labelEndingValidityTime}'> <#local commentFields> <@input type='hidden' name='id_form' value='${idForm!}' /> <@input type='hidden' name='id_comment' id='id_comment' value='${(current.id)!}' /> <@input type='hidden' name='from' value='${from!}' /> <@input type='hidden' name='additional_parameters' value='${additionalParameters!}' /> <@formGroup labelFor='comment' labelKey='#i18n{appointment.comment.name}' helpKey='#i18n{appointment.comment.name}' mandatory=true rows=2> <@input type='textarea' name='comment' id=idComment richtext=true mandatory=true>${((current.comment)!)?html} <@span id=idComment+'_errorEmpty' class='text-danger labelErrorComment'>#i18n{appointment.message.comment.error.commentEmpty} <@formGroup labelFor='startingValidityDate' labelKey=startDateLabel mandatory=true rows=2> <@input type='date' name='startingValidityDate' id=idStartingDate value=((current.startingValidityDate?string)?date.xs)!'' /> <@formGroup labelFor='startingValidityTime' labelKey=startTimeLabel rows=2> <@input type='time' name='startingValidityTime' id=idStartingTime value='${(current.startingValidityTime)!}' /> <@formGroup labelFor=idEndingDate labelKey=endDateLabel mandatory=true rows=2> <@input type='date' name='endingValidityDate' id=idEndingDate value=((current.endingValidityDate?string)?date.xs)!'' /> <@span id=idEndingDate+'_errorEndDateBeforeStartDate' class='text-danger labelErrorComment'> #i18n{appointment.message.comment.error.endDateBeforeStartDate} <@formGroup labelFor='endingValidityTime' labelKey=endTimeLabel rows=2> <@input type='time' name='endingValidityTime' id=idEndingTime value='${(current.endingValidityTime)!}' /> <@span id=idEndingTime+'_errorEndTimeEqualStartTime' class='text-danger labelErrorComment'> #i18n{appointment.message.comment.error.endTimeEqualStartTime} <@span id=idEndingTime+'_errorEndTimeBeforeStartTime' class='text-danger labelErrorComment'> #i18n{appointment.message.comment.error.endTimeBeforeStartTime} <@formGroup labelFor='idMailingList' labelKey='#i18n{appointment.create_comment.labelMailingList}' helpKey='#i18n{appointment.create_comment.labelMailingList.help}' mandatory=false rows=2> <#assign default='-1'> <@select name='idMailingList'> <@option value='-1' label='#i18n{appointment.create_comment.labelNoNotification}' /> <#list mailing_list as item> <#assign isSelected><#if default=item.code>true<#else>false <#assign label><#if !item.name?has_content>label="${i18n("portal.util.labelEmpty")}"<#else>${item.name} <@option value=item.code label=label selected=isSelected?boolean /> <#local commentActions> <#if action == 'doModifyComment'><@button type='submit' id='commentDelete' name='action_confirmRemoveComment' buttonIcon='trash' title='#i18n{portal.util.labelDelete}' color='danger' params='formnovalidate' /> <@button type='submit' id='action_${action}' name='action_${action}' buttonIcon='check' title='#i18n{portal.util.labelValidate}' params='formnovalidate' /> <#if inline> <@box> <@tform action='jsp/admin/plugins/appointment/Comments.jsp' id='${modalId}-form'> <@boxBody> ${commentFields} <@boxFooter> <@aButton href='jsp/admin/plugins/appointment/Comments.jsp?view=manageComment' title='#i18n{portal.util.labelCancel}' buttonIcon='times' color='light' /> ${commentActions} <#else> <@modal id=modalId size='lg'> <@tform action='jsp/admin/plugins/appointment/Comments.jsp' id='${modalId}-form'> <@modalHeader modalTitle=modalTitle /> <@modalBody> ${commentFields} <@modalFooter> <@button type='button' params='data-bs-dismiss="modal"' title='#i18n{portal.util.labelCancel}' buttonIcon='times' color='light' /> ${commentActions} <#macro btnComment > <#if permission_add_comment?boolean><@button id='toggle-add-comment' buttonIcon='message-plus' title='#i18n{appointment.create_comment.pageTitle}' hideTitle=['xs','sm'] size='sm' color='action' params='data-bs-toggle="modal" data-bs-target="#commentModal"' /> <#macro tabsComment tab> <@tabList id='${tab}-tab'> <#if tab='comment'><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/Comments.jsp?view=manageComment' title='#i18n{appointment.manage_comments.title}' active=active /> <#if tab='notif'><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/NotificationCommentConfig.jsp?view=notificationConfig' title='#i18n{appointment.task_notify_appointment_comment_config.title}' active=active /> <#macro appointmentTabList tab form tabcontext> <#if tabcontext='slot'> <#if tab="typicalWeek"><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointmentSlots.jsp?view=manageTypicalWeek&id_form=${form.idForm}&context=slot' title='#i18n{appointment.typicalWeek.pageTitle}' active=active /> <#if tab="specificWeek"><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageSpecificWeek.jsp?view=manageSpecificWeek&id_form=${form.idForm}&context=slot' title='#i18n{appointment.specificWeek.pageTitle}' active=active /> <#if tab="year"><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageAnnualCalendar.jsp?view=manageAnnualCalendar&id_form=${form.idForm}&context=slot' title='#i18n{appointment.annual.calendar.pageTitle}' active=active /> <#if tab="day"><#assign active = true /><#else><#assign active = false /> <#if isDeskInstalled?? && isDeskInstalled><@tabLink href='jsp/admin/plugins/appointment/modules/desk/ManageAppointmentDesks.jsp?plugin_name=appointment-desk&id_form=${form.idForm}&context=slot' title='#i18n{appointment.specificDay.pageTitle}' active=active /> <#elseif tabcontext='app'> <#if tab="calendar"><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointments.jsp?view=viewCalendarManageAppointment&id_form=${form.idForm}&context=app' title='#i18n{appointment.manageAppointmentCalendar.pageTitle}' active=active /> <#if tab="filter"><#assign active = true /><#else><#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointments.jsp?view=manageAppointments&id_form=${form.idForm}&context=app' title='#i18n{appointment.manageAppointments.pageTitle}' active=active /> <#if tab='day'><#assign active = true /><#else><#assign active = false /> <#if isDeskInstalled?? && isDeskInstalled><@tabLink href='jsp/admin/plugins/appointment/modules/desk/ManageAppointmentDesks.jsp?plugin_name=appointment-desk&id_form=${form.idForm}&context=app' title='#i18n{appointment.specificDay.pageTitle}' active=active /> <#else> <#assign tabparams='data-menu="slot"'> <#if isDeskInstalled?? && isDeskInstalled><@tabLink href='jsp/admin/plugins/appointment/modules/desk/ManageAppointmentDesks.jsp?plugin_name=appointment-desk&id_form=${form.idForm}&context=slot' title='#i18n{appointment.specificDay.pageTitle}' active=true params=tabparams /> <#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageSpecificWeek.jsp?view=manageSpecificWeek&id_form=${form.idForm}&context=slot' title='#i18n{appointment.specificWeek.pageTitle}' active=active params=tabparams/> <@tabLink href='jsp/admin/plugins/appointment/ManageAnnualCalendar.jsp?view=manageAnnualCalendar&id_form=${form.idForm}&context=slot' title='#i18n{appointment.annual.calendar.pageTitle}' active=active params=tabparams/> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointmentSlots.jsp?view=manageTypicalWeek&id_form=${form.idForm}&context=slot' title='#i18n{appointment.typicalWeek.pageTitle}' active=active params=tabparams/> <#assign tabparams='data-menu="app"'> <#assign active = false /> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointments.jsp?view=viewCalendarManageAppointment&id_form=${form.idForm}&context=app' title='#i18n{appointment.manageAppointmentCalendar.pageTitle}' active=active params=tabparams/> <@tabLink href='jsp/admin/plugins/appointment/ManageAppointments.jsp?view=manageAppointments&id_form=${form.idForm}&context=app' title='#i18n{appointment.manageAppointments.pageTitle}' active=active params=tabparams/> <#if isDeskInstalled?? && isDeskInstalled><@tabLink href='jsp/admin/plugins/appointment/modules/desk/ManageAppointmentDesks.jsp?plugin_name=appointment-desk&id_form=${form.idForm}&context=app' title='#i18n{appointment.specificDay.pageTitle}' active=true params=tabparams/> <#macro appointmentTabs tab form context tabBtn=''> <@commonsAppJS /> <@row id='${tab}-tab' class='appointment-tab'> <@columns> <@tabs class='mt-3'> <@tabList> <@appointmentTabList tab form context /> <#if tab !='typicalWeek' && tab !='year' && tab !='day' && tab !='filter'> <@li class='nav-item ms-auto'> <#if !tab?contains("filter") && !tab?contains("typicalWeek")><@btnComment /> <@button id='btn-toggle-mini-cal' type='button' title='#i18n{appointment.appointmentCalendar.labelHideMiniCalendar}' size='sm' color='action'> <@icon style='calendar-off' /> <#if tabBtn !=''> <@li class='nav-item ms-auto'> ${tabBtn} <@tabContent id='${tab}-content'> <#if formCalendarErrors??> <@messages errors=errors infos=infos/> <#else> <#if tab !='typicalWeek' && tab !='year' && tab !='day' && tab !='filter'> <@row> <@columns xs=12 md=12 lg=10 id='fc-calendar-col'> <@div id='calendar'> <@div id='loader' class='d-flex justify-content-center align-items-center vh-100 h-75'> <@span class='fw-bold'>#i18n{appointment.labelLoading}... <@div class='spinner-border' params='role="status" aria-hidden="true"' /> <@columns xs=12 md=12 lg=2 class='d-none d-lg-block' id='fc-sidebar-col'> <@div id='mini-calendar' class='stickycommentModal-top' params='style="top:80px"' /> <#nested> <#macro commentModal update=false > let commentModal = bootstrap.Modal.getOrCreateInstance('#modify-comment'); var modifyModalEl = document.getElementById('modify-comment'); modifyModalEl.addEventListener('show.bs.modal', function() { <#if update> var formValues = JSON.parse( info.el.getAttribute( 'data-json' ) ); var csDate = new Date(formValues.comment_start); localStorage.setItem( 'commentContext', fcFormatDate(csDate, 'YYYY-MM-DD') ); tinymce.get( modifyModalEl.querySelector( 'textarea[name="comment"]' ).id ).setContent( formValues.comment_text ); document.querySelector( '#modify-comment input[name="id_comment"]' ).value = formValues.id_comment.slice(1); document.querySelectorAll('.labelErrorComment').forEach(function(el) { el.style.display = 'none'; }); // Set dates/times via Flatpickr API var modStartDate = document.getElementById('modifyStartingValidityDate'); var modEndDate = document.getElementById('modifyEndingValidityDate'); var modStartTime = document.getElementById('idModifyStartingTime'); var modEndTime = document.getElementById('idModifyEndingTime'); if (modStartDate && modStartDate._flatpickr) { modStartDate._flatpickr.setDate(formValues.comment_start, true); } else if (modStartDate) { modStartDate.value = formValues.comment_start; } if (modEndDate && modEndDate._flatpickr) { modEndDate._flatpickr.setDate(formValues.comment_end, true); } else if (modEndDate) { modEndDate.value = formValues.comment_end; } if (modStartTime && modStartTime._flatpickr) { modStartTime._flatpickr.setDate(formValues.comment_start_time, true); } else if (modStartTime) { modStartTime.value = formValues.comment_start_time; } if (modEndTime && modEndTime._flatpickr) { modEndTime._flatpickr.setDate(formValues.comment_end_time, true); } else if (modEndTime) { modEndTime.value = formValues.comment_end_time; } }, { once: true }); commentModal.show(); <#macro getComments comments_list> <#list comments_list as comment_event> <#compress> <#assign comment_title>${comment_event.comment?replace('\n', '')?replace('\r', '')?replace('\rn', '')?replace('\'', ''')?replace('\\', '\')} { "title" : "${comment_title?json_string}", "start" : "${comment_event.startingValidityDate}T${comment_event.startingValidityTime!}", "end" : "${comment_event.calendarAllDaySlotEnd}T${comment_event.endingValidityTime!}", "validity_end" : "${comment_event.endingValidityDate}", "start_time" : "${comment_event.startingValidityTime!}", "end_time" : "${comment_event.endingValidityTime!}", "id" : "C${comment_event.id}", "creator_name" : "${comment_event.userLastName!''} ${comment_event.userFirstName!''}", "creator_user" : "${comment_event.creatorUserName!''}", "creation_date" : "${comment_event.creationDate?date.xs!''}", "type" : "comment", "allDay" : true, }, <#assign aDateTime = .now> <#if comment_event.startingValidityTime?? && comment_event.endingValidityTime??> <#if ( comment_event.startingValidityTime != '00:00' || comment_event.endingValidityTime != '00:00' )> { "start" : "${comment_event.startingValidityDate}T${comment_event.startingValidityTime!}", "end" : "${comment_event.endingValidityDate}T${comment_event.endingValidityTime!}", "type" : "hour_comment", // "backgroundColor" : 'rgba(233, 250, 0, 0.4)', "className" : ["comment-${comment_event.id!}"], "display" : "background", "allDay" : false, }, <#macro fullCalendarScript selectable=true isSpecific=false isTypical=false height='auto' showComments=true locale=locale> function fcFormatTime(date) { if (!date) return ''; return String(date.getHours()).padStart(2, '0') + ':' + String(date.getMinutes()).padStart(2, '0'); } function fcFormatDate(date, style) { if (!date) return ''; var d = (date instanceof Date) ? date : new Date(date); if (isNaN(d.getTime())) return ''; date = d; if (style === 'ddd DD/MM') return FullCalendar.formatDate(date, { weekday: 'short', day: '2-digit', month: '2-digit', locale: '${locale}' }); if (style === 'DD/MM/YYYY') return FullCalendar.formatDate(date, { day: '2-digit', month: '2-digit', year: 'numeric', locale: '${locale}' }); if (style === 'YYYY-MM-DD') return date.getFullYear() + '-' + String(date.getMonth() + 1).padStart(2, '0') + '-' + String(date.getDate()).padStart(2, '0'); return FullCalendar.formatDate(date, { locale: '${locale}' }); } function initMiniCalendar(fcInstance) { var container = document.getElementById('mini-calendar'); if (!container) return null; var minDate = typeof startingDateOfDisplay !== 'undefined' ? startingDateOfDisplay : null; var maxDate = typeof endingDateOfDisplay !== 'undefined' ? endingDateOfDisplay : null; // Local date key (avoids UTC shift from toISOString) function toLocalDateKey(d) { return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); } // Build available appointment counts per day from main calendar events // A slot is available when: not filled, not overbooked, not closed (bgClosedColor) function buildAppointmentCounts() { var closedColor = (typeof bgClosedColor !== 'undefined') ? bgClosedColor.replace(';', '') : '#bebebe'; var counts = {}; fcInstance.getEvents().forEach(function(event) { var type = event.extendedProps.type || ''; if (type !== 'comment' && type !== 'hour_comment' && event.start) { var customClass = event.extendedProps.customClass || ''; var isFilled = customClass.indexOf('filled') !== -1; var isOverbooked = customClass.indexOf('overbooked') !== -1; var isClosed = event.backgroundColor === closedColor; if (!isFilled && !isOverbooked && !isClosed) { var dateKey = toLocalDateKey(event.start); counts[dateKey] = (counts[dateKey] || 0) + 1; } } }); return counts; } function updateDots() { var appointmentCounts = buildAppointmentCounts(); container.querySelectorAll('.mini-cal-dot').forEach(function(dot) { dot.remove(); }); container.querySelectorAll('.fc-daygrid-day').forEach(function(cell) { var dateAttr = cell.getAttribute('data-date'); if (!dateAttr) return; var count = appointmentCounts[dateAttr]; if (count) { var dot = document.createElement('span'); dot.className = 'mini-cal-dot'; dot.setAttribute('data-bs-toggle', 'tooltip'); dot.setAttribute('data-bs-placement', 'top'); dot.setAttribute('title', count + ' #i18n{appointment.appointmentCalendar.labelAvailableSlots}'); var frame = cell.querySelector('.fc-daygrid-day-frame'); if (frame) frame.appendChild(dot); new bootstrap.Tooltip(dot); } }); } // Highlight the week currently visible in the main calendar function highlightCurrentWeek() { var view = fcInstance.view; if (!view) return; container.querySelectorAll('.fc-daygrid-day').forEach(function(cell) { var dateAttr = cell.getAttribute('data-date'); if (!dateAttr) return; var cellDate = new Date(dateAttr + 'T00:00:00'); if (cellDate >= view.activeStart && cellDate < view.activeEnd) { cell.classList.add('mini-cal-active-week'); } else { cell.classList.remove('mini-cal-active-week'); } }); } var miniCal = new FullCalendar.Calendar(container, { initialView: 'dayGridMonth', initialDate: fcInstance.getDate(), headerToolbar: { left: 'prev', center: 'title', right: 'next' }, footerToolbar: { center: 'today' }, height: '${height!}', contentHeight: 'auto', fixedWeekCount: false, locale: fcInstance.getOption('locale'), validRange: { start: minDate, end: maxDate }, dateClick: function(info) { fcInstance.gotoDate(info.date); requestAnimationFrame(highlightCurrentWeek); }, datesSet: function() { requestAnimationFrame(function() { highlightCurrentWeek(); updateDots(); }); } }); miniCal.render(); // Force re-render after layout is fully computed requestAnimationFrame(function() { miniCal.updateSize(); highlightCurrentWeek(); updateDots(); }); // Expose methods for external update miniCal.highlightCurrentWeek = highlightCurrentWeek; miniCal.updateDots = updateDots; return miniCal; } function initAppointmentCalendar() { var calendarEl = document.getElementById('calendar'); if ( !calendarEl ) { return; } var miniCalInstance = null; var isDragging = false, selectedEls = []; window.appointmentCalendar = null; var calendarInst = new FullCalendar.Calendar(calendarEl, { <#if !showComments>allDaySlot: false, displayEventTime: false, allDayText: '#i18n{appointment.appointmentCalendar.labelAllDay}', buttonText : { prev : '#i18n{appointment.appointmentApp.previousWeek}', next : '#i18n{appointment.appointmentApp.nextWeek}', today : "#i18n{appointment.appointmentCalendar.labelToday}", }, height: 'auto', navLinks: true, navLinkDayClick: function( date, jsEvent ) { var dateStr = date.toISOString().slice(0,10); location.href = eventUrl + 'manageAppointments&id_form=' + idForm + '&starting_date_time=' + dateStr + 'T00:00&ending_date_time=' + dateStr + 'T23:59'; }, initialDate: defaultDate, nowIndicator: true, initialView: 'timeGridWeek', locale: '${locale}', editable: false, headerToolbar: <#if isTypical>false<#else>{ left: 'prev', center: 'title', right: 'next today' }, <#if isTypical>dayHeaderFormat: { weekday: 'long' },<#else>dayHeaderContent: function(arg) { var d = arg.date; return { html: d.toLocaleDateString('${locale}', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) }; }, slotLabelFormat: { hour: 'numeric', minute: '2-digit', hour12: false }, slotLabelInterval: slotDuration, slotDuration: slotDuration, <#if selectable> selectable: true, selectMirror: true, select: function( info ) { isDragging = false; var startDate = info.start; var endDate = info.end; var selIdx=0, selData=''; calendarInst.getEvents().forEach(function(ev) { var type = ev.extendedProps.type || ''; if (type === 'comment' || type === 'hour_comment') return; if (ev.start >= startDate && ev.end <= endDate) { var evObj = { <#if isSpecific>idSlot: parseInt(ev.id) || 0, <#if isTypical>idTimeSlot: parseInt(ev.id) || 0, startingDateTime: fcFormatDate(ev.start, 'YYYY-MM-DD') + 'T' + fcFormatTime(ev.start), startingTime: fcFormatTime(ev.start), endingDateTime: fcFormatDate(ev.end, 'YYYY-MM-DD') + 'T' + fcFormatTime(ev.end), endingTime: fcFormatTime(ev.end), isOpen: ev.extendedProps.isOpen === 'true' || ev.extendedProps.isOpen === true, <#if isSpecific>isSpecific: ev.extendedProps.isSpecific === 'true' || ev.extendedProps.isSpecific === true, idForm: parseInt(ev.extendedProps.idForm) || 0, <#if isSpecific>date: ev.extendedProps.date || '', maxCapacity: parseInt(ev.extendedProps.maxCapacity) || 0 }; selData += JSON.stringify(evObj) + ','; selIdx++; } }); if ( selIdx === 0 ) { return; } if ( selIdx > 1 ){ var evtData='['+ selData.slice(0, -1) + ']'; var evt = JSON.parse(evtData); document.getElementById(<#if isTypical>'timeSlotData'<#else>'slotsData').value = evtData; document.getElementById('date_of_display_multi').value = fcFormatDate(new Date(evt[0].startingDateTime), 'YYYY-MM-DD'); setTimeout(function() { bootstrap.Modal.getOrCreateInstance('#updatePlanningMultiSlot').show(); }, 50); } else { var evtData = selData.slice(0, -1); var evt = JSON.parse(evtData); document.getElementById(<#if isTypical>'timeSlotData'<#else>'slotData').value = '['+evtData+']'; var isOpen = evt.isOpen === true || evt.isOpen === 'true'; document.getElementById(<#if isTypical>'timeIsOpen'<#else>'is_open').checked = isOpen; document.getElementById('maxCapacity').value = evt.maxCapacity; <#if isSpecific> document.querySelector('#dtSlot').textContent = fcFormatDate(new Date(evt.startingDateTime), 'DD/MM/YYYY'); document.getElementById('date_of_display_slot').value = fcFormatDate(new Date(evt.startingDateTime), 'YYYY-MM-DD'); <#if isTypical> document.getElementById('idTimeSlot').value = evt.idTimeSlot; document.getElementById('idWorkingDay').value = evt.idWorkingDay || ''; document.getElementById('timeStart').textContent = evt.startingTime; document.getElementById('timeEnd').value = evt.endingTime; setTimeout(function() { bootstrap.Modal.getOrCreateInstance('#updatePlanningSlot').show(); }, 50); } }, eventDidMount: function( info ) { var tooltip = new Tooltip(info.el, { title: info.event.extendedProps.description, placement: 'top', trigger: 'hover', container: 'body' }); }, loading: function(isLoading) { var loader = document.getElementById('loader'); if (loader) { loader.style.display = isLoading ? '' : 'none'; } }, <#if !isTypical> validRange: { start: startingDateOfDisplay, end: endingDateOfDisplay }, slotMinTime: minTime, slotMaxTime: maxTime, businessHours: { startTime: minTime, endTime: maxTime, daysOfWeek: dow }, eventClick: function( info ){ var calEvent = info.event; var jsEvent = info.jsEvent; var type = calEvent.extendedProps.type || ''; /* Intercept click on .open-AddBookDialog link inside event */ var addBookLink = jsEvent.target.closest('.open-AddBookDialog'); if (addBookLink) { jsEvent.preventDefault(); jsEvent.stopPropagation(); document.getElementById('starting_date_time').value = addBookLink.dataset.starting_date_time; var dtDate = new Date(addBookLink.dataset.starting_date_time); document.getElementById('starting_date_time_span').value = fcFormatDate(dtDate, 'DD/MM/YYYY') + ' ' + fcFormatTime(dtDate); bootstrap.Modal.getOrCreateInstance('#addBookModalDialog').show(); return; } /* A link written inside the event (count of the slot, add an appointment) opens its own page */ var innerLink = jsEvent.target.closest('a[href]'); if (innerLink && innerLink !== info.el && info.el.contains(innerLink)) { return; } <#if showComments> // Comments var isCommentModerator=${permission_moderate_comment}; if( type == "comment" && ( calEvent.extendedProps.creator_user === '${permission_access_code}' || isCommentModerator ) ){ <@commentModal update=true /> } else if( type == "appointment" ) { jsEvent.preventDefault(); // An empty target is intentional : the slot is not actionable, do not reload the page var strTarget = calEvent.extendedProps.manageUrl || calEvent.url; if( strTarget ){ location.href = strTarget; } } <#if selectable> if ( type !== 'comment' && type !== 'hour_comment' && type !== 'appointment' ) { jsEvent.preventDefault(); var ev = calEvent; var evObj = { <#if isSpecific>idSlot: parseInt(ev.id) || 0, <#if isTypical>idTimeSlot: parseInt(ev.id) || 0, startingDateTime: fcFormatDate(ev.start, 'YYYY-MM-DD') + 'T' + fcFormatTime(ev.start), startingTime: fcFormatTime(ev.start), endingDateTime: fcFormatDate(ev.end, 'YYYY-MM-DD') + 'T' + fcFormatTime(ev.end), endingTime: fcFormatTime(ev.end), isOpen: ev.extendedProps.isOpen === 'true' || ev.extendedProps.isOpen === true, <#if isSpecific>isSpecific: ev.extendedProps.isSpecific === 'true' || ev.extendedProps.isSpecific === true, idForm: parseInt(ev.extendedProps.idForm) || 0, <#if isSpecific>date: ev.extendedProps.date || '', maxCapacity: parseInt(ev.extendedProps.maxCapacity) || 0 }; var evtData = JSON.stringify(evObj); document.getElementById(<#if isTypical>'timeSlotData'<#else>'slotData').value = '[' + evtData + ']'; document.getElementById(<#if isTypical>'timeIsOpen'<#else>'is_open').checked = evObj.isOpen; document.getElementById('maxCapacity').value = evObj.maxCapacity; <#if isSpecific> document.querySelector('#dtSlot').textContent = fcFormatDate(ev.start, 'DD/MM/YYYY'); document.getElementById('date_of_display_slot').value = fcFormatDate(ev.start, 'YYYY-MM-DD'); <#if isTypical> document.getElementById('idTimeSlot').value = evObj.idTimeSlot; document.getElementById('idWorkingDay').value = ev.extendedProps.idWorkingDay || ''; document.getElementById('timeStart').textContent = evObj.startingTime; document.getElementById('timeEnd').value = evObj.endingTime; setTimeout(function() { bootstrap.Modal.getOrCreateInstance('#updatePlanningSlot').show(); }, 50); } }, events: events, <#if !isTypical> datesSet: function(info) { var d = info.start; sessionStorage.setItem( 'appCurrentDate', d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0') ); if (miniCalInstance) { miniCalInstance.gotoDate(info.start); requestAnimationFrame(function() { miniCalInstance.highlightCurrentWeek(); }); } }, <#if showComments> eventMouseEnter: function(info) { const bgHoverColor = 'rgba(233, 250, 0, .1)'; if (info.event.extendedProps.type === 'hour_comment') { info.el.dataset.prevBgColor = info.el.style.backgroundColor; var commentId = info.event.classNames[0]; var cEl = commentId ? document.getElementById(commentId.replace('comment-', 'comment-C')) : null; if (cEl) { cEl.dataset.prevBgColor = cEl.style.backgroundColor; cEl.style.color = '#fff'; } } else if (info.event.extendedProps.type !== 'comment') { /* Highlight allDay comments whose hour_comment overlaps this slot */ var slotStart = info.event.start, slotEnd = info.event.end; if (slotStart && slotEnd) { calendarInst.getEvents().forEach(function(evt) { if (evt.extendedProps.type === 'hour_comment' && evt.start < slotEnd && evt.end > slotStart) { var commentId = evt.classNames[0]; var cEl = commentId ? document.getElementById(commentId.replace('comment-', 'comment-C')) : null; if (cEl && !cEl.dataset.slotHover) { cEl.dataset.slotHover = 'true'; cEl.style.backgroundColor = bgHoverColor; cEl.style.color = '#fff'; } } }); } } }, eventMouseLeave: function(info) { if (info.event.extendedProps.type === 'hour_comment') { info.el.style.backgroundColor = info.el.dataset.prevBgColor || ''; var commentId = info.event.classNames[0]; var cEl = commentId ? document.getElementById(commentId.replace('comment-', 'comment-C')) : null; if (cEl) { cEl.style.backgroundColor = cEl.dataset.prevBgColor || ''; cEl.style.color = '#000'; } } else if (info.event.extendedProps.type !== 'comment') { /* Remove highlight from allDay comments */ document.querySelectorAll('[data-slot-hover="true"]').forEach(function(cEl) { cEl.style.backgroundColor = cEl.dataset.prevBgColor2 || ''; cEl.style.color = '#000'; delete cEl.dataset.slotHover; delete cEl.dataset.prevBgColor2; }); } }, eventsSet: function( events ) { <#if isSpecific || isTypical > /* Event selection via native drag selection */ (function() { var timegridBody = document.querySelector('.fc-timegrid-body'); if (!timegridBody) return; <#if isSpecific>if (timegridBody.querySelector('.comments')) return; if (timegridBody.querySelector('.btn-comments')) return; var eventEls = timegridBody.querySelectorAll('.fc-timegrid-event.fc-v-event'); timegridBody.addEventListener('mousedown', function(e) { if (e.button !== 0) return; var target = e.target.closest('.fc-timegrid-event.fc-v-event'); if (!target || target.classList.contains('comments') || !target.dataset.event) return; isDragging = true; selectedEls = [target]; target.classList.add('ui-selected'); e.preventDefault(); }); timegridBody.addEventListener('mouseover', function(e) { if (!isDragging) return; var target = e.target.closest('.fc-timegrid-event.fc-v-event'); if (target && selectedEls.indexOf(target) === -1 && !target.classList.contains('comments') && target.dataset.event) { selectedEls.push(target); target.classList.add('ui-selected'); } }); document.addEventListener('mouseup', function() { if (!isDragging) return; isDragging = false; if (selectedEls.length <= 1) { /* Single slot: let FC select callback handle it */ selectedEls.forEach(function(el) { el.classList.remove('ui-selected'); }); selectedEls = []; return; } var eventIdx = selectedEls.length; var eventData = '', evtData = ''; selectedEls.forEach(function(el, index) { <#if isSpecific> eventData += '{' + (el.dataset.event || '') + '},'; evtData = '[' + eventData.slice(0, -1) + ']'; var evt = JSON.parse(evtData); document.getElementById('slotsData').value = evtData; document.getElementById('date_of_display_multi').value = fcFormatDate(new Date(evt[0].startingDateTime), 'YYYY-MM-DD'); if (index === eventIdx - 1) { setTimeout(function() { bootstrap.Modal.getOrCreateInstance('#updatePlanningMultiSlot').show(); }, 50); } <#if isTypical> eventData += '{' + (el.dataset.event || '') + '},'; evtData = '[' + eventData.slice(0, -1) + ']'; document.getElementById('timeSlotData').value = evtData; if (index === eventIdx - 1) { setTimeout(function() { bootstrap.Modal.getOrCreateInstance('#updatePlanningMultiSlot').show(); }, 50); } }); var clearSel = function() { selectedEls.forEach(function(el) { el.classList.remove('ui-selected'); }); selectedEls = []; }; ['#updatePlanningSlot', '#updatePlanningMultiSlot'].forEach(function(mid) { var m = document.querySelector(mid); if (m) { m.addEventListener('hidden.bs.modal', clearSel, { once: true }); } }); }); })(); /* Update mini-calendar dots after events are loaded */ if (miniCalInstance && typeof miniCalInstance.updateDots === 'function') { miniCalInstance.updateDots(); } }, eventDidMount: function( info ) { var event = info.event; var el = info.el; if (event.extendedProps.type === 'hour_comment') { el.classList.add('hour-comment'); } var titleEl = el.querySelector( '.fc-event-title' ), createSlot='', labelEventDate=''; var customClass = (event.extendedProps.customClass || '').trim(); if (customClass) { customClass.split(/\s+/).forEach(function(c) { el.classList.add(c); }); } if ( event.extendedProps.customStyle && event.extendedProps.customStyle !== '' ){ el.style.background = event.extendedProps.customStyle; } if (titleEl) { titleEl.innerHTML = titleEl.textContent; } if( event.extendedProps.type !== 'comment' ){ <#if isSpecific> el.setAttribute( 'data-event', '"idSlot":"' + event.id +'","startingDateTime":"' + fcFormatDate(event.start, 'YYYY-MM-DD') + 'T' + fcFormatTime(event.start) + '","startingTime":"' + fcFormatTime(event.start) + '","endingDateTime":"' + fcFormatDate(event.end, 'YYYY-MM-DD') + 'T' + fcFormatTime(event.end) + '","endingTime":"' + fcFormatTime(event.end)+ '","isOpen":"' + event.extendedProps.isOpen + '","idForm":"' + event.extendedProps.idForm +'","date":"' + event.extendedProps.date + '","isSpecific":"' + event.extendedProps.isSpecific + '","maxCapacity":"' + event.extendedProps.maxCapacity + '"' ); <#if isTypical> el.setAttribute( 'data-event', '"idTimeSlot":"' + event.id +'","startingDateTime":"' + fcFormatDate(event.start, 'YYYY-MM-DD') + 'T' + fcFormatTime(event.start) + '","startingTime":"' + fcFormatTime(event.start) + '","endingDateTime":"' + fcFormatDate(event.end, 'YYYY-MM-DD') + 'T' + fcFormatTime(event.end) + '","endingTime":"' + fcFormatTime(event.end)+ '","isOpen":"' + event.extendedProps.isOpen + '","idForm":"' + event.extendedProps.idForm +'","maxCapacity":"' + event.extendedProps.maxCapacity + '"' ); } var json = { "container": "body", "placement" : "bottom", "html" : true, "trigger" : "hover" }; <#if showComments> if( event.extendedProps.type == 'comment' ){ el.classList.add('comments'); el.setAttribute( 'id', 'comment-' + event.id ); el.setAttribute( 'data-json', '{"id_comment":"' + event.id + '", "comment_text":"' + event.title.replace(/"/g,'\\"') + '", "comment_start":"' + fcFormatDate(event.start, 'YYYY-MM-DD') + '", "comment_start_time":"' + event.extendedProps.start_time + '", "comment_end":"' + event.extendedProps.validity_end + '", "comment_end_time\":"' + event.extendedProps.end_time + '"}' ); /* Add comment render — build flat object expected by setLabelComment */ var commentData = { start: event.start, validity_end: event.extendedProps.validity_end, start_time: event.extendedProps.start_time, end_time: event.extendedProps.end_time }; labelEventDate = (typeof setLabelComment === 'function') ? setLabelComment( commentData, '${locale}' ) : ''; var creator = (event.extendedProps.creator_name || '').trim() !== '' ? event.extendedProps.creator_name : event.extendedProps.creator_user; <#noparse>json.content = `

${labelEventDate}

Créé par ${creator} le ${event.extendedProps.creation_date}


${event.title.replace(/"/g,'\\"')}

`; var dateDebut='', dateFin=''; if ( ! ( event.extendedProps.start_time == null || event.extendedProps.start_time == undefined || event.extendedProps.start_time == '00:00' ) ){ var startDDMM = (event.start.getDate().toString().padStart(2,'0')) + (event.start.getMonth()+1).toString().padStart(2,'0'); var endValDate = new Date(event.extendedProps.validity_end); var endDDMM = (endValDate.getDate().toString().padStart(2,'0')) + (endValDate.getMonth()+1).toString().padStart(2,'0'); if( startDDMM != endDDMM ){ dateDebut=fcFormatDate(event.start, 'ddd DD/MM') + ' à '; dateFin=fcFormatDate(endValDate, 'ddd DD/MM') + ' à '; } var fcTitle = el.querySelector('.fc-event-title p'); if (fcTitle) { fcTitle.insertAdjacentHTML('afterbegin', dateDebut + event.extendedProps.start_time + '/' + dateFin + event.extendedProps.end_time + ' ' ); } } else { el.classList.add('allday'); } } else { if( event.id != undefined ){ <#noparse>json.content = `

${fcFormatTime(event.start)} - ${fcFormatTime(event.end)}

`; } } <#else> if( event.id != undefined ){ <#noparse>json.content = `

${fcFormatTime(event.start)} - ${fcFormatTime(event.end)}

`; } const popover = new bootstrap.Popover( el, json ) } }); calendarInst.render(); window.appointmentCalendar = calendarInst; // Force re-render after layout is computed to ensure events display requestAnimationFrame(function() { calendarInst.updateSize(); }); /* Mini-calendar toggle — apply visibility BEFORE rendering mini-cal */ (function() { var toggleBtn = document.getElementById('btn-toggle-mini-cal'); var miniCalEl = document.getElementById('mini-calendar'); var sidebarCol = document.getElementById('fc-sidebar-col'); var calendarCol = document.getElementById('fc-calendar-col'); if (!toggleBtn || !miniCalEl) return; function applyState(visible) { if (visible) { miniCalEl.style.display = ''; if (sidebarCol) sidebarCol.style.display = ''; if (calendarCol) { calendarCol.classList.remove('col-lg-12'); calendarCol.classList.add('col-lg-10'); } toggleBtn.title = '#i18n{appointment.appointmentCalendar.labelHideMiniCalendar}'; toggleBtn.querySelector('i').className = 'ti ti-calendar-off'; } else { miniCalEl.style.display = 'none'; if (sidebarCol) sidebarCol.style.display = 'none'; if (calendarCol) { calendarCol.classList.remove('col-lg-10'); calendarCol.classList.add('col-lg-12'); } toggleBtn.title = '#i18n{appointment.appointmentCalendar.labelShowMiniCalendar}'; toggleBtn.querySelector('i').className = 'ti ti-calendar'; } calendarInst.updateSize(); if (miniCalInstance) { miniCalInstance.updateSize(); } } var stored = localStorage.getItem('appointmentMiniCalVisible'); var visible = stored === null ? true : stored === 'true'; applyState(visible); toggleBtn.addEventListener('click', function() { visible = !visible; localStorage.setItem('appointmentMiniCalVisible', String(visible)); applyState(visible); }); })(); /* Init mini-calendar AFTER layout is stable */ miniCalInstance = initMiniCalendar(calendarInst); /* Update dots now that both mini-cal and main calendar events are ready */ if (miniCalInstance && typeof miniCalInstance.updateDots === 'function') { miniCalInstance.updateDots(); } /* If comment creation set currentDate from "commentContext" localstorage */ const dtCurrent=localStorage.getItem('commentContext'); if( dtCurrent !='' && dtCurrent != null ){ localStorage.removeItem( 'commentContext' ); calendarInst.gotoDate(new Date(dtCurrent)); } <#nested> } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initAppointmentCalendar); } else { initAppointmentCalendar(); }