Commit 6d9fc97b authored by Jelle Besseling's avatar Jelle Besseling
Browse files

Merge branch 'fix/events-js' into 'master'

Fix events js

See merge request !1044
parents a5f77de5 f1cc12ee
......@@ -47,145 +47,121 @@
{% block js_body %}
{{ block.super }}
{% compress js %}
<script type="text/javascript">
$(function () {
var calendarElement = $('#calendar');
var sources = {
events: "/api/v1/events/calendarjs",
birthdays: "/api/v1/members/birthdays",
partners: "/api/v1/partners/calendarjs",
unpublishedEvents: "/api/v1/events/unpublished"
};
<script type="text/javascript">
$(function () {
var calendarElement = $('#calendar');
var sources = {
events: "/api/v1/events/calendarjs",
birthdays: "/api/v1/members/birthdays",
partners: "/api/v1/partners/calendarjs",
unpublishedEvents: "/api/v1/events/unpublished"
};
var eventSources = [sources.events, sources.partners];
{% if perms.events.change_event %}
eventSources.push(sources.unpublishedEvents);
{% endif %}
if (Cookies.get('showbirthdays')) {
eventSources.push(sources.birthdays);
}
var tmpView = ($(window).width() < 979) ? 'list' : 'agendaWeek';
if (Cookies.get('agendaview') !== undefined) {
tmpView = Cookies.get('agendaview');
}
var eventSources = [sources.events, sources.partners];
{% if perms.events.change_event %}
eventSources.push(sources.unpublishedEvents);
{% endif %}
if (Cookies.get('showbirthdays')) {
eventSources.push(sources.birthdays);
}
var tmpView = ($(window).width() < 979) ? 'list' : 'agendaWeek';
if (Cookies.get('agendaview') !== undefined) {
tmpView = Cookies.get('agendaview');
}
// History idea and code parts from
// https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-132535804
// and https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-245544401
{% if upcoming_activity %}
var startDate = new Date('{{ upcoming_activity.start|date:'Y-m-d' }}');
{% else %}
var startDate = new Date();
{% endif %}
var tmpYear = startDate.getFullYear();
var tmpMonth = startDate.getMonth();
var tmpDay = startDate.getDate();
var vars = window.location.hash.split("&");
for (var i = 0; i < vars.length; i++) {
if (vars[i].match("^#year")) tmpYear = vars[i].substring(6);
if (vars[i].match("^month")) tmpMonth = vars[i].substring(6) - 1;
if (vars[i].match("^day")) tmpDay = vars[i].substring(4);
if (vars[i].match("^view")) tmpView = vars[i].substring(5);
}
// History idea and code parts from
// https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-132535804
// and https://github.com/fullcalendar/fullcalendar/issues/659#issuecomment-245544401
{% if upcoming_activity %}
var startDate = new Date('{{ upcoming_activity.start|date:'Y-m-d' }}');
{% else %}
var startDate = new Date();
{% endif %}
var tmpYear = startDate.getFullYear();
var tmpMonth = startDate.getMonth();
var tmpDay = startDate.getDate();
var vars = window.location.hash.split("&");
for (var i = 0; i < vars.length; i++) {
if (vars[i].match("^#year")) tmpYear = vars[i].substring(6);
if (vars[i].match("^month")) tmpMonth = vars[i].substring(6) - 1;
if (vars[i].match("^day")) tmpDay = vars[i].substring(4);
if (vars[i].match("^view")) tmpView = vars[i].substring(5);
}
calendarElement.fullCalendar({
aspectRatio: 1.8,
theme: 'bootstrap4',
eventSources: eventSources,
defaultView: tmpView,
firstDay: 1,
scrollTime: '14:00:00',
timeFormat: 'HH:mm',
eventLimit: true,
locale: '{{ LANGUAGE_CODE }}',
views: {
list: {
buttonText: '{% trans "list" %}',
duration: {weeks: 1}
}
},
defaultDate:
{% spaceless %}
{% if upcoming_activity %}
"{{ upcoming_activity.start|date:'Y-m-d' }}"
{% else %}
"{% now 'Y-m-d' %}"
{% endif %}
{% endspaceless %},
customButtons: {
{% if request.user.is_authenticated %}
showBirthdays: {
text: Cookies.get('showbirthdays') ? '{% trans "hide birthdays" %}' : '{% trans "show birthdays" %}',
click: function (e) {
if (e.target.innerHTML == '{% trans "hide birthdays" %}') {
e.target.innerHTML = '{% trans 'show birthdays' %}';
Cookies.remove('showbirthdays');
calendarElement.fullCalendar('removeEventSource', sources.birthdays);
}
else {
e.target.innerHTML = '{% trans "hide birthdays" %}';
Cookies.set('showbirthdays', 1);
calendarElement.fullCalendar('addEventSource', sources.birthdays);
}
}
}
calendarElement.fullCalendar({
aspectRatio: 1.8,
theme: 'bootstrap4',
eventSources: eventSources,
defaultView: tmpView,
firstDay: 1,
scrollTime: '14:00:00',
timeFormat: 'HH:mm',
eventLimit: true,
locale: '{{ LANGUAGE_CODE }}',
views: {
list: {
buttonText: '{% trans "list" %}',
duration: {weeks: 1}
}
},
defaultDate:
{% spaceless %}
{% if upcoming_activity %}
"{{ upcoming_activity.start|date:'Y-m-d' }}"
{% else %}
"{% now 'Y-m-d' %}"
{% endif %}
},
header: {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
},
eventClick: function (event) {
if (event.url && event.blank) {
window.open(event.url, '_blank');
return false;
} else if (event.url) {
window.replace(event.url);
return false;
}
},
eventRender: function (event, element) {
element.attr('title', event.description);
},
viewRender: function (view) {
var prevView = Cookies.get('agendaview');
var moment = calendarElement.fullCalendar('getDate');
if (moment && moment.isValid()) {
window.location.hash = 'year=' + moment.format('YYYY') + '&month=' + (moment.format('M')) + '&day=' + moment.format('DD') + '&view=' + view.name;
}
if (view.name !== prevView) {
var windowWidth = $(window).width();
Cookies.set('agendaview', view.name);
if (windowWidth <= 768) {
calendarElement.fullCalendar('option', 'header', {
right: 'prev,next today'
});
} else {
if (view.name === 'list') {
calendarElement.fullCalendar('option', 'header', {
right: 'list,agendaWeek,month prev,next today'
});
} else {
calendarElement.fullCalendar('option', 'header', {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
});
{% endspaceless %},
customButtons: {
{% if request.user.is_authenticated %}
showBirthdays: {
text: Cookies.get('showbirthdays') ? '{% trans "hide birthdays" %}' : '{% trans "show birthdays" %}',
click: function (e) {
if (e.target.innerHTML == '{% trans "hide birthdays" %}') {
e.target.innerHTML = '{% trans 'show birthdays' %}';
Cookies.remove('showbirthdays');
calendarElement.fullCalendar('removeEventSource', sources.birthdays);
}
else {
e.target.innerHTML = '{% trans "hide birthdays" %}';
Cookies.set('showbirthdays', 1);
calendarElement.fullCalendar('addEventSource', sources.birthdays);
}
}
}
},
windowResize: function () {
{% endif %}
},
header: {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
},
eventClick: function (event) {
if (event.url && event.blank) {
window.open(event.url, '_blank');
return false;
} else if (event.url) {
window.replace(event.url);
return false;
}
},
eventRender: function (event, element) {
element.attr('title', event.description);
},
viewRender: function (view) {
var prevView = Cookies.get('agendaview');
var moment = calendarElement.fullCalendar('getDate');
if (moment && moment.isValid()) {
window.location.hash = 'year=' + moment.format('YYYY') + '&month=' + (moment.format('M')) + '&day=' + moment.format('DD') + '&view=' + view.name;
}
if (view.name !== prevView) {
var windowWidth = $(window).width();
var view = (windowWidth <= 768) ? 'list' : Cookies.get('agendaview');
var currentView = $('#calendar').fullCalendar('getView');
if (view !== currentView.name) {
calendarElement.fullCalendar('changeView', view);
} else if (windowWidth <= 768) {
Cookies.set('agendaview', view.name);
if (windowWidth <= 768) {
calendarElement.fullCalendar('option', 'header', {
right: 'prev,next today'
});
} else {
if (currentView.name === 'list') {
if (view.name === 'list') {
calendarElement.fullCalendar('option', 'header', {
right: 'list,agendaWeek,month prev,next today'
});
......@@ -196,40 +172,64 @@
}
}
}
});
var date = new Date(tmpYear, tmpMonth, tmpDay, 0, 0, 0);
var moment = calendarElement.fullCalendar('getDate');
var view = calendarElement.fullCalendar('getView');
if (date.getFullYear() !== moment.format('YYYY') ||
date.getMonth() !== moment.format('M') ||
date.getDate() !== moment.format('DD')) {
calendarElement.fullCalendar('gotoDate', date);
},
windowResize: function () {
var windowWidth = $(window).width();
var view = (windowWidth <= 768) ? 'list' : Cookies.get('agendaview');
var currentView = $('#calendar').fullCalendar('getView');
if (view !== currentView.name) {
calendarElement.fullCalendar('changeView', view);
} else if (windowWidth <= 768) {
calendarElement.fullCalendar('option', 'header', {
right: 'prev,next today'
});
} else {
if (currentView.name === 'list') {
calendarElement.fullCalendar('option', 'header', {
right: 'list,agendaWeek,month prev,next today'
});
} else {
calendarElement.fullCalendar('option', 'header', {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
});
}
}
}
});
if (view.name !== tmpView) {
calendarElement.fullCalendar('changeView', tmpView);
}
var date = new Date(tmpYear, tmpMonth, tmpDay, 0, 0, 0);
var moment = calendarElement.fullCalendar('getDate');
var view = calendarElement.fullCalendar('getView');
if (date.getFullYear() !== moment.format('YYYY') ||
date.getMonth() !== moment.format('M') ||
date.getDate() !== moment.format('DD')) {
calendarElement.fullCalendar('gotoDate', date);
}
if (view.name !== tmpView) {
calendarElement.fullCalendar('changeView', tmpView);
}
var windowWidth = $(window).width();
if (windowWidth <= 768) {
var windowWidth = $(window).width();
if (windowWidth <= 768) {
calendarElement.fullCalendar('option', 'header', {
right: 'prev,next today'
});
} else {
if (view.name === 'list') {
calendarElement.fullCalendar('option', 'header', {
right: 'prev,next today'
right: 'list,agendaWeek,month prev,next today'
});
} else {
if (view.name === 'list') {
calendarElement.fullCalendar('option', 'header', {
right: 'list,agendaWeek,month prev,next today'
});
} else {
calendarElement.fullCalendar('option', 'header', {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
});
}
calendarElement.fullCalendar('option', 'header', {
right: 'showBirthdays, list,agendaWeek,month prev,next today'
});
}
});
</script>
}
});
</script>
{% compress js %}
<script type="text/javascript" src="{% static "events/js/moment.js" %}"></script>
<script type="text/javascript" src="{% static "events/js/fullcalendar.min.js" %}"></script>
<script type="text/javascript" src="{% static "events/js/fullcalendar-nl.js" %}"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment