Allow to only display events the user subscribed to.

This commit is contained in:
Daru13 2018-11-25 16:05:00 +01:00
parent 9e7937d7d9
commit 81eb6bebac

View file

@ -33,6 +33,10 @@ class Calendar {
this.events = []; this.events = [];
this.onlyDisplaySubscribedEvents = calendarParameters.onlyDisplaySubscribedEvents !== undefined
? calendarParameters.onlyDisplaySubscribedEvents
: false;
this.eventDetailURLFormat = calendarParameters.eventDetailURLFormat !== undefined this.eventDetailURLFormat = calendarParameters.eventDetailURLFormat !== undefined
? calendarParameters.eventDetailURLFormat ? calendarParameters.eventDetailURLFormat
: ""; : "";
@ -81,6 +85,7 @@ class Calendar {
this.updateHoursToDisplay(); this.updateHoursToDisplay();
this.updateEventContainerGridStyle(); this.updateEventContainerGridStyle();
this.updateTimeSlots(); this.updateTimeSlots();
this.updateEventVisibilities(); this.updateEventVisibilities();
this.updateCalendarNodeHeight(); this.updateCalendarNodeHeight();
@ -93,6 +98,7 @@ class Calendar {
this.updateHoursToDisplay(); this.updateHoursToDisplay();
this.updateEventContainerGridStyle(); this.updateEventContainerGridStyle();
this.updateTimeSlots(); this.updateTimeSlots();
this.updateEventVisibilities(); this.updateEventVisibilities();
this.updateCalendarNodeHeight(); this.updateCalendarNodeHeight();
@ -114,7 +120,9 @@ class Calendar {
let timeSlotHourRowHeight = $(".cal-time-slot-hour").outerHeight(); let timeSlotHourRowHeight = $(".cal-time-slot-hour").outerHeight();
// Event grid // Event grid
let eventContainerHeight = $(".cal-event-container") this.containerNode.css("height", "calc(100% )");
let eventContainerHeight = this.eventContainerNode
.css("grid-template-rows") .css("grid-template-rows")
.split("px ") .split("px ")
.reduce((heightAccumulator, currentRowHeight) => { .reduce((heightAccumulator, currentRowHeight) => {
@ -355,6 +363,32 @@ class Calendar {
background: "#000" background: "#000"
}); });
} }
// Event filtering
showEventsNotSubscribedByUser () {
this.onlyDisplaySubscribedEvents = false;
this.updateEventVisibilities();
this.updateCalendarNodeHeight();
}
hideEventsNotSubscribedByUser () {
this.onlyDisplaySubscribedEvents = true;
this.updateEventVisibilities();
this.updateCalendarNodeHeight();
}
toggleEventsNotSubscribedByUser () {
if (this.onlyDisplaySubscribedEvents) {
this.showEventsNotSubscribedByUser();
}
else {
this.hideEventsNotSubscribedByUser();
}
}
} }
@ -626,26 +660,41 @@ class Event {
// Visibility // Visibility
hide () {
this.stopDisplayingDetailsPopupOnClick();
this.node.hide();
this.displayed = false;
}
show () {
this.node.show();
this.updateNodeStyle();
this.updatePositionInGrid();
this.updateOverflowTooltipTriggering();
this.startDisplayingDetailsPopupOnClick();
this.displayed = true;
}
updateVisibility () { updateVisibility () {
// If required, hide events which are not subscribed by the current user
if (this.calendar.onlyDisplaySubscribedEvents
&& ! this.subscribedByUser) {
this.hide();
return;
}
// Hide events which cannot apear in the calendar time span // Hide events which cannot apear in the calendar time span
if (this.calendar.startDate.getTime() >= this.endDate.getTime() if (this.calendar.startDate.getTime() >= this.endDate.getTime()
|| this.calendar.endDate.getTime() <= this.startDate.getTime()) { || this.calendar.endDate.getTime() <= this.startDate.getTime()) {
this.stopDisplayingDetailsPopupOnClick(); this.hide();
return;
this.node.hide();
this.displayed = false;
} }
else {
this.node.show();
this.updateNodeStyle(); // Otherwise, show the current event
this.updatePositionInGrid(); this.show();
this.updateOverflowTooltipTriggering();
this.startDisplayingDetailsPopupOnClick();
this.displayed = true;
}
} }