{% extends 'base.html.twig' %}
{% block title %}Calendrier{% endblock %}
{% block body %}
<div id="form_event" class="parent" style="display: none;">
<div id="container_close"><i id="close" class="fa fa-2x fa-times"></i></div>
<div id="form_event_detail"></div>
</div>
<div id="calendrier"></div>
{% endblock %}
{% block javascripts %}
<script>
var calendar;
var calendarElt;
{% if app.user %}
function addEvent(e) {
self.location.href = '/admin/calendrier/newcalendrier/';
}
function showEvent(e) {
self.location.href = '/admin/calendrier/edit/' + e.id;
}
{% else %}
function showEvent(e) {
if (e.id == -1) {
return;
}
let url = '/api/' + e.id + '/getevent';
let xhr = new XMLHttpRequest;
xhr.responseType = 'json';
xhr.open("GET", url, true);
xhr.onload = (e) => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let e = xhr.response;
let ds = new Date(e.start);
var html = '<div class="event-title text-center"><h2>' + e.title + '</h2></div>';
html += '<div class="event-title">Début : ' + ds.toLocaleString("fr") + '</div>';
if (e.end !== null) {
let de = new Date(e.end);
html += '<div class="event-title">Fin : ' + de.toLocaleString("fr") + '</div>';
}
html += '<div class="event-title">Description : ' + e.description + '</div>';
html += '<div class="event-title">Lieu : ' + e.lieu + '</div>';
document.querySelector("#form_event_detail").style.padding = "6px";
document.querySelector("#form_event_detail").style.backgroundColor = e.backgroundColor;
document.querySelector("#form_event_detail").style.color = e.textColor;
document.querySelector("#form_event_detail").style.border = "solid " + e.borderColor;
document.querySelector("#form_event_detail").innerHTML = html;
document.querySelector("#form_event").style.display = 'block';
} else {
console.error(xhr.statusText);
}
}
};
xhr.send(null);
}
{% endif %}
function initializeCalendrier() {
calendar = new FullCalendar.Calendar(calendarElt, {
initialView: 'dayGridMonth',
locale: 'fr',
timeZone: 'Europe/Paris',
handleWindowResize: true,
height: 800,
allDayText: 'Journée',
firstDay: 1,
weekNumbers: true,
weekText: "S",
buttonText: {
today: 'Aujourd\'hui',
month: 'Mois',
week: 'Semaine',
day: 'Journée'
},
buttonIcons: {
'loggedButton': 'fa-logged',
{% if app.user %}
'loginButton': 'fa-sign-logout',
{% else %}
'loginButton': 'fa-sign-login'
{% endif %}
},
headerToolbar: {
start: '{{ app.user ? 'loggedButton backendButton '}}loginButton prevYear,nextYear prev,next today',
center: 'title',
end: 'dayGridMonth timeGridWeek timeGridDay'
},
footerToolbar: {
center: 'showCarteButton'
},
customButtons: {
{% if app.user %}
backendButton: {
text: 'Espace admin',
click: function (e) {
e.stopPropagation();
self.location.href = '{{asset(path('admin'))}}';
}
},
{% endif %}
showCarteButton: {
text: 'Voir sur la carte',
click: function (e) {
self.location.href = '{{asset(path('carte'))}}';
}
},
loggedButton: {
text: '{{ app.user ? 'Vous êtes identifié-e comme ' ~ app.user.username}}'
},
loginButton: {
text: '{{ app.user ? 'Déconnection' : 'Identifiez-vous' }}',
click: function (e) {
{% if app.user %}
self.location.href = '{{asset(path('app_logout'))}}';
{% else %}
self.location.href = '{{asset(path('app_login'))}}';
{% endif %}
}
}
},
eventSources: ['api/getallevents'],
editable:{{app.user ? 'true' : 'false'}} ,
eventResizableFromStart: true
});
calendar.on('eventClick', (e) => {
showEvent(e.event);
});
{% if app.user %}
calendar.on('dateClick', (e) => {
addEvent(e);
});
calendar.on('eventChange', (e) => {
let donnees = {
"id": e.event.id,
"title": e.event.title,
"description": e.event.extendedProps.description,
"start": e.event.start,
"end": e.event.end,
"backgroundColor": e.event.backgroundColor,
"borderColor": e.event.borderColor,
"textColor": e.event.textColor,
"allDay": e.event.allDay,
"lieu": e.event.lieu,
"latitude": e.event.latitude,
"longitude": e.event.longitude
};
setEvent(donnees);
});
{% endif %}
calendar.render();
}
function setEvent(donnees) {
let url = '/api/' + donnees.id + '/edit';
let xhr = new XMLHttpRequest;
xhr.open("PUT", url);
xhr.send(JSON.stringify(donnees));
xhr.onload = (e) => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
document.querySelector("#form_event").style.display = 'none';
calendar.refetchEvents();
}
}
};
}
window.onload = () => {
calendarElt = document.querySelector("#calendrier");
let closeBtn = document.querySelector("#close");
closeBtn.addEventListener('click', function () {
document.querySelector("#form_event").style.display = 'none';
});
calendarElt.addEventListener('click', function () {
document.querySelector("#form_event").style.display = 'none';
});
initializeCalendrier();
};
</script>
<script src="{{ asset('js/tarteaucitron/tarteaucitron.js')}}"></script>
<script>
{#
tarteaucitron.init({
"privacyUrl": "", /* Privacy policy url */
"bodyPosition": "top", /* or top to bring it as first element for accessibility */
"hashtag": "#tarteaucitron", /* Open the panel with this hashtag */
"cookieName": "tarteaucitron", /* Cookie name */
"orientation": "middle", /* Banner position (top - bottom - middle - popup) */
"groupServices": false, /* Group services by category */
"serviceDefaultState": "wait", /* Default state (true - wait - false) */
"showAlertSmall": false, /* Show the small banner on bottom right */
"cookieslist": false, /* Show the cookie list */
"showIcon": true, /* Show cookie icon to manage cookies */
// "iconSrc": "", /* Optionnal: URL or base64 encoded image */
"iconPosition": "BottomRight", /* Position of the icon between BottomRight, BottomLeft, TopRight and TopLeft */
"adblocker": false, /* Show a Warning if an adblocker is detected */
"DenyAllCta": true, /* Show the deny all button */
"AcceptAllCta": true, /* Show the accept all button when highPrivacy on */
"highPrivacy": true, /* HIGHLY RECOMMANDED Disable auto consent */
"handleBrowserDNTRequest": false, /* If Do Not Track == 1, disallow all */
"removeCredit": true, /* Remove credit link */
"moreInfoLink": true, /* Show more info link */
"useExternalCss": false, /* If false, the tarteaucitron.css file will be loaded */
"useExternalJs": false, /* If false, the tarteaucitron.services.js file will be loaded */
//"cookieDomain": ".my-multisite-domaine.fr", /* Shared cookie for subdomain website */
"readmoreLink": "", /* Change the default readmore link pointing to tarteaucitron.io */
"mandatory": true, /* Show a message about mandatory cookies */
"mandatoryCta": true /* Show the disabled accept button when mandatory on */
});
#}
</script>
<script src="{{ asset('fullcalendar_5_11_3/lib/main.min.js') }}"></script>
{% endblock %}