refactor(calendar.html): change API URLs and event to occurrence
This commit is contained in:
@@ -6,14 +6,14 @@
|
|||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.20/index.global.min.js" integrity="sha256-sQEgS6I+FEeOlX4oTVi7qW/HMRAh0O6vifpeZXIMRsg=" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.20/index.global.min.js" integrity="sha256-sQEgS6I+FEeOlX4oTVi7qW/HMRAh0O6vifpeZXIMRsg=" crossorigin="anonymous"></script>
|
||||||
<script>
|
<script>
|
||||||
function showModal(eventId) {
|
function showModal(occurrenceId) {
|
||||||
// get event's url
|
// get event's url
|
||||||
const eventApiUrl = `/api/calendar/events/${eventId}`;
|
const eventApiUrl = `/api/calendar/occurrences/${occurrenceId}`;
|
||||||
|
|
||||||
const eventApi = fetch(eventApiUrl)
|
const eventApi = fetch(eventApiUrl)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
eventUrl = data.url;
|
eventUrl = `/occurrence/${occurrenceId}/`;
|
||||||
|
|
||||||
const modal = document.createElement('div');
|
const modal = document.createElement('div');
|
||||||
modal.classList.add('fixed', 'inset-0', 'flex', 'items-center', 'justify-center', 'z-50', 'shadow-lg', 'overflow-auto');
|
modal.classList.add('fixed', 'inset-0', 'flex', 'items-center', 'justify-center', 'z-50', 'shadow-lg', 'overflow-auto');
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
if (e.target === modal) {
|
if (e.target === modal) {
|
||||||
document.body.removeChild(modal);
|
document.body.removeChild(modal);
|
||||||
|
|
||||||
// remove ?modal=eventId from the url
|
// remove ?modal=occurrenceId from the url
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
url.searchParams.delete('modal');
|
url.searchParams.delete('modal');
|
||||||
window.history.pushState({}, '', url);
|
window.history.pushState({}, '', url);
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
document.body.removeChild(modal);
|
document.body.removeChild(modal);
|
||||||
}
|
}
|
||||||
document.removeEventListener('keydown', escHandler);
|
document.removeEventListener('keydown', escHandler);
|
||||||
// remove ?modal=eventId from the url
|
// remove ?modal=occurrenceId from the url
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
url.searchParams.delete('modal');
|
url.searchParams.delete('modal');
|
||||||
window.history.pushState({}, '', url);
|
window.history.pushState({}, '', url);
|
||||||
@@ -69,16 +69,16 @@
|
|||||||
if (document.body.contains(modal)) {
|
if (document.body.contains(modal)) {
|
||||||
document.body.removeChild(modal);
|
document.body.removeChild(modal);
|
||||||
}
|
}
|
||||||
// remove ?modal=eventId from the url
|
// remove ?modal=occurrenceId from the url
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
url.searchParams.delete('modal');
|
url.searchParams.delete('modal');
|
||||||
window.history.pushState({}, '', url);
|
window.history.pushState({}, '', url);
|
||||||
});
|
});
|
||||||
modal.appendChild(closeButton);
|
modal.appendChild(closeButton);
|
||||||
|
|
||||||
// add ?modal=eventId to the url
|
// add ?modal=occurrenceId to the url
|
||||||
const url = new URL(window.location);
|
const url = new URL(window.location);
|
||||||
url.searchParams.set('modal', eventId);
|
url.searchParams.set('modal', occurrenceId);
|
||||||
window.history.pushState({}, '', url);
|
window.history.pushState({}, '', url);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
right: 'timeGridWeek,listMonth',
|
right: 'timeGridWeek,listMonth',
|
||||||
},
|
},
|
||||||
locale: "{% get_current_language as LANGUAGE_CODE %}{{ LANGUAGE_CODE }}",
|
locale: "{% get_current_language as LANGUAGE_CODE %}{{ LANGUAGE_CODE }}",
|
||||||
events: "/api/calendar/events/",
|
events: "/api/calendar/occurrences/",
|
||||||
eventClick: function(info) {
|
eventClick: function(info) {
|
||||||
// prevent default navigation
|
// prevent default navigation
|
||||||
info.jsEvent.preventDefault();
|
info.jsEvent.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user