2 * @file view/theme/frio/js/mod_events.js
3 * Initialization of the fullCalendar and format the output.
6 $(document).ready(function() {
7 // start the fullCalendar
8 $('#events-calendar').fullCalendar({
9 firstDay: aStr.firstDay,
10 monthNames: aStr['monthNames'],
11 monthNamesShort: aStr['monthNamesShort'],
12 dayNames: aStr['dayNames'],
13 dayNamesShort: aStr['dayNamesShort'],
14 allDayText: aStr.allday,
15 noEventsMessage: aStr.noevent,
22 events: baseurl + moduleUrl + '/json/',
29 eventClick: function(calEvent, jsEvent, view) {
30 showEvent(calEvent.id);
32 loading: function(isLoading, view) {
34 $('td.fc-day').dblclick(function() { addToModal('/events/new?start='+$(this).data('date')); });
39 eventRender: function(event, element, view) {
40 //console.log(view.name);
43 element.find(".fc-title").html(
44 "<span class='item-desc'>{2}</span>".format(
45 event.item['author-avatar'],
46 event.item['author-name'],
53 if (event.item['author-name'] == null) return;
54 element.find(".fc-title").html(
55 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
56 event.item['author-avatar'],
57 event.item['author-name'],
59 htmlToText(event.item.location)
63 if (event.item['author-name'] == null) return;
64 element.find(".fc-title").html(
65 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
66 event.item['author-avatar'],
67 event.item['author-name'],
69 htmlToText(event.item.location)
73 element.find(".fc-list-item-title").html(formatListViewEvent(event));
77 eventAfterRender: function (event, element) {
79 content: eventHoverHtmlContent(event),
84 template: '<div class="popover hovercard event-card"><div class="arrow"></div><div class="popover-content hovercard-content"></div></div>',
85 sanitizeFn: function (content) {
86 return DOMPurify.sanitize(content)
95 var args=location.href.replace(baseurl,"").split("/");
98 $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
101 if (args.length>=4) {
102 $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
107 var view = $('#events-calendar').fullCalendar('getView');
108 $('#fc-title').text(view.title);
111 var hash = location.hash.split("-")
112 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
116 // loads the event into a modal
117 function showEvent(eventid) {
118 addToModal(baseurl + moduleUrl + '/?id=' + eventid);
121 function changeView(action, viewName) {
122 $('#events-calendar').fullCalendar(action, viewName);
123 var view = $('#events-calendar').fullCalendar('getView');
124 $('#fc-title').text(view.title);
127 // The template for the bootstrap popover for displaying the event title and
128 // author (it's the nearly the same template we use in frio for the contact
129 // hover cards. So be careful when changing the css)
130 function eventHoverBodyTemplate() {
132 <div class="event-card-basic-content media">\
133 <div class="event-card-details">\
134 <div class="event-card-header">\
135 <div class="event-card-left-date">\
136 <span class="event-date-wrapper medium">\
137 <span class="event-card-short-month">{5}</span>\
138 <span class="event-card-short-date">{6}</span>\
141 <div class="event-card-content media-body">\
142 <div class="event-card-title">{2}</div>\
143 <div class="event-property"><span class="event-card-date">{4}</span>{3}\
147 <div class="clearfix"></div>\
154 // The template for presenting the event location in the event hover-card
155 function eventHoverLocationTemplate() {
156 var template = '<span role="presentation" aria-hidden="true"> ยท </span>\
157 <span class="event-card-location"> {0}</span></div>';
161 function eventHoverProfileNameTemplate() {
163 <div class="event-card-profile-name profile-entry-name">\
164 <a href="{0}" class="userinfo">{1}</a>\
168 // transform the event data to html so we can use it in the event hover-card
169 function eventHoverHtmlContent(event) {
170 var eventLocation = '';
171 var eventProfileName = '';
172 // Get the Browser language
173 var locale = window.navigator.userLanguage || window.navigator.language;
176 // Use the browser language for date formatting
177 moment.locale(locale);
179 // format dates to different styles
180 var startDate = moment(event.item.start).format('dd HH:mm');
181 var endDate = moment(event.item.finsih).format('dd HH:mm');
182 var monthShort = moment(event.item.start).format('MMM');
183 var dayNumberStart = moment(event.item.start).format('DD');
184 var dayNumberEnd = moment(event.item.finish).format('DD');
185 var startTime = moment(event.item.start).format('HH:mm');
186 var endTime = moment(event.item.finish).format('HH:mm');
189 var formattedDate = startDate;
191 // We only need the to format the end date if the event does have
193 if (event.item.nofinish == 0) {
194 formattedDate = startDate + ' - ' + endTime;
196 // use a different Format (15. Feb - 18. Feb) if the events end date
197 // is not the start date
198 if ( dayNumberStart != dayNumberEnd) {
199 formattedDate = moment(event.item.start).format('Do MMM') +
201 moment(event.item.finish).format('Do MMM');
205 // Get the html template
206 data = eventHoverBodyTemplate();
208 // Get only template data if there exists location data
209 if (event.item.location) {
210 var eventLocationText = htmlToText(event.item.location);
211 // Get the the html template for formatting the location
212 var eventLocationTemplate = eventHoverLocationTemplate();
213 // Format the event location data according to the the event location
215 eventLocation = eventLocationTemplate.format(
220 // Get only template data if there exists a profile name
221 if (event.item['author-name']) {
223 var eventProfileNameTemplate = eventHoverProfileNameTemplate();
224 // Insert the data into the template
225 eventProfileName = eventProfileNameTemplate.format(
226 event.item['author-link'],
227 event.item['author-name']
231 // Format the event data according to the event hover template
232 var formatted = data.format(
233 event.item['author-avatar'], // this isn't used at the present time
238 monthShort.replace('.', ''), // Get rid of possible dots in the string
245 // transform the the list view event element into formatted html
246 function formatListViewEvent(event) {
247 // The basic template for list view
248 var template = '<td class="fc-list-item-title fc-widget-content">\
249 <hr class="seperator"></hr>\
250 <div class="event-card">\
251 <div class="popover-content hovercard-content">{0}</div>\
254 // Use the formation of the event hover and insert it in the base list view template
255 var formatted = template.format(eventHoverHtmlContent(event));