Commit 4abd0880 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

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

Fix events javascript to be compressed again

See merge request !1058
parents 851ee4f4 211b08aa
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-08 13:43+0100\n"
"POT-Creation-Date: 2018-11-13 20:58+0100\n"
"PO-Revision-Date: 2018-11-08 13:45+0100\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n"
......@@ -700,8 +700,8 @@ msgid ""
"Searching for another event? <a href=\"%(events_index)s\">Take a look at the "
"entire agenda.</a>"
msgstr ""
"Op zoek naar een andere evenement? <a href=\"%(events_index)s\">Bekijk de hele "
"agenda.</a>"
"Op zoek naar een andere evenement? <a href=\"%(events_index)s\">Bekijk de "
"hele agenda.</a>"
#: templates/events/index.html
msgid "iCal feed (all events)"
......@@ -711,18 +711,6 @@ msgstr "iCal feed (alle evenementen)"
msgid "iCal feed (personal)"
msgstr "iCal feed (persoonlijk)"
#: templates/events/index.html
msgid "list"
msgstr "lijst"
#: templates/events/index.html
msgid "hide birthdays"
msgstr "verberg verjaardagen"
#: templates/events/index.html
msgid "show birthdays"
msgstr "toon verjaardagen"
#: templates/events/member_email.txt
#, python-format
msgid ""
......
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-18 14:35+0200\n"
"PO-Revision-Date: 2018-10-18 14:36+0200\n"
"POT-Creation-Date: 2018-11-13 20:59+0100\n"
"PO-Revision-Date: 2018-11-13 20:59+0100\n"
"Last-Translator: Sébastiaan Versteeg <se_bastiaan@outlook.com>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -25,3 +25,15 @@ msgstr "Er zijn geen evenementen gepland in de geselecteerde periode."
#: static/events/js/calendarlistview.js
msgid "Go to event"
msgstr "Naar de evenementpagina"
#: static/events/js/main.js
msgid "list"
msgstr "lijst"
#: static/events/js/main.js
msgid "hide birthdays"
msgstr "verberg verjaardagen"
#: static/events/js/main.js
msgid "show birthdays"
msgstr "toon verjaardagen"
function checkResponsiveState(calendarElement, windowWidth, view) {
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'
});
}
}
}
$(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 showUnpublished = calendarElement.data('show-unpublished');
var defaultDate = calendarElement.data('default-date');
var isAuthenticated = calendarElement.data('authenticated');
var language = calendarElement.data('language');
var eventSources = [sources.events, sources.partners];
if (showUnpublished) {
eventSources.push(sources.unpublishedEvents);
}
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
var startDate = new Date(defaultDate);
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,
views: {
list: {
buttonText: gettext('list'),
duration: {weeks: 1}
}
},
defaultDate: defaultDate,
customButtons:
isAuthenticated ? {
showBirthdays: {
text: Cookies.get('showbirthdays') ? gettext('hide birthdays') : gettext('show birthdays'),
click: function (e) {
if (e.target.innerHTML == gettext('hide birthdays')) {
e.target.innerHTML = gettext('show birthdays');
Cookies.remove('showbirthdays');
calendarElement.fullCalendar('removeEventSource', sources.birthdays);
} else {
e.target.innerHTML = gettext('hide birthdays');
Cookies.set('showbirthdays', 1);
calendarElement.fullCalendar('addEventSource', sources.birthdays);
}
}
}
} : {}
,
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);
checkResponsiveState(calendarElement, windowWidth, view.name);
}
}
,
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 {
checkResponsiveState(calendarElement, windowWidth, currentView.name);
}
}
})
;
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);
} else {
var windowWidth = $(window).width();
checkResponsiveState(calendarElement, windowWidth, view);
}
});
......@@ -2,13 +2,16 @@
{% load i18n static compress personal_feed %}}
{% get_current_language as LANGUAGE_CODE %}
{% block title %}{% trans "Calendar"|capfirst %} — {{ block.super }}{% endblock %}
{% block opengraph_title %}{% trans "Calendar"|capfirst %} — {{ block.super }}{% endblock %}
{% block title %}{% trans "Calendar"|capfirst %} —
{{ block.super }}{% endblock %}
{% block opengraph_title %}{% trans "Calendar"|capfirst %} —
{{ block.super }}{% endblock %}
{% block css_head %}
{{ block.super }}
{% compress css %}
<link href="{% static "events/css/fullcalendar.css" %}" rel="stylesheet" type="text/css">
<link href="{% static "events/css/fullcalendar.css" %}"
rel="stylesheet" type="text/css">
{% endcompress %}
{% endblock %}
......@@ -40,199 +43,33 @@
{% endif %}
</h1>
<div id="calendar"></div>
<div id="calendar" data-default-date="{% spaceless %}
{% if upcoming_activity %}
{{ upcoming_activity.start|date:'Y-m-d' }}
{% else %}
{% now 'Y-m-d' %}
{% endif %}
{% endspaceless %}"
data-authenticated="{{ request.user.is_authenticated|yesno:'true,false' }}"
data-show-unpublished="{{ perms.events.change_event|yesno:'true,false' }}"
data-language="{{ LANGUAGE_CODE }}"
></div>
</div>
</section>
{% endblock body %}
{% block js_body %}
{{ block.super }}
<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');
}
// 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);
}
}
}
{% 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'
});
}
}
}
},
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'
});
}
}
}
});
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) {
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'
});
}
}
});
</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>
<script type="text/javascript" src="{% static "events/js/calendarlistview.js" %}"></script>
<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>
<script type="text/javascript"
src="{% static "events/js/calendarlistview.js" %}"></script>
<script type="text/javascript"
src="{% static "events/js/main.js" %}"></script>
{% endcompress %}
{% endblock js_body %}
Supports Markdown
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