2 * @file view/theme/frio/js/mod_events.js
3 * @brief 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>',
92 var args=location.href.replace(baseurl,"").split("/");
95 $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
99 $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
104 var view = $('#events-calendar').fullCalendar('getView');
105 $('#fc-title').text(view.title);
108 var hash = location.hash.split("-")
109 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
113 // loads the event into a modal
114 function showEvent(eventid) {
115 addToModal(baseurl + moduleUrl + '/?id=' + eventid);
118 function changeView(action, viewName) {
119 $('#events-calendar').fullCalendar(action, viewName);
120 var view = $('#events-calendar').fullCalendar('getView');
121 $('#fc-title').text(view.title);
124 // The template for the bootstrap popover for displaying the event title and
125 // author (it's the nearly the same template we use in frio for the contact
126 // hover cards. So be careful when changing the css)
127 function eventHoverBodyTemplate() {
129 <div class="event-card-basic-content media">\
130 <div class="event-card-details">\
131 <div class="event-card-header">\
132 <div class="event-card-left-date">\
133 <span class="event-date-wrapper medium">\
134 <span class="event-card-short-month">{5}</span>\
135 <span class="event-card-short-date">{6}</span>\
138 <div class="event-card-content media-body">\
139 <div class="event-card-title">{2}</div>\
140 <div class="event-property"><span class="event-card-date">{4}</span>{3}\
144 <div class="clearfix"></div>\
151 // The template for presenting the event location in the event hover-card
152 function eventHoverLocationTemplate() {
153 var template = '<span role="presentation" aria-hidden="true"> ยท </span>\
154 <span class="event-card-location"> {0}</span></div>';
158 function eventHoverProfileNameTemplate() {
160 <div class="event-card-profile-name profile-entry-name">\
161 <a href="{0}" class="userinfo">{1}</a>\
165 // transform the event data to html so we can use it in the event hover-card
166 function eventHoverHtmlContent(event) {
167 var eventLocation = '';
168 var eventProfileName = '';
169 // Get the Browser language
170 var locale = window.navigator.userLanguage || window.navigator.language;
173 // Use the browser language for date formatting
174 moment.locale(locale);
176 // format dates to different styles
177 var startDate = moment(event.item.start).format('dd HH:mm');
178 var endDate = moment(event.item.finsih).format('dd HH:mm');
179 var monthShort = moment(event.item.start).format('MMM');
180 var dayNumberStart = moment(event.item.start).format('DD');
181 var dayNumberEnd = moment(event.item.finish).format('DD');
182 var startTime = moment(event.item.start).format('HH:mm');
183 var endTime = moment(event.item.finish).format('HH:mm');
186 var formattedDate = startDate;
188 // We only need the to format the end date if the event does have
190 if (event.item.nofinish == 0) {
191 formattedDate = startDate + ' - ' + endTime;
193 // use a different Format (15. Feb - 18. Feb) if the events end date
194 // is not the start date
195 if ( dayNumberStart != dayNumberEnd) {
196 formattedDate = moment(event.item.start).format('Do MMM') +
198 moment(event.item.finish).format('Do MMM');
202 // Get the html template
203 data = eventHoverBodyTemplate();
205 // Get only template data if there exists location data
206 if (event.item.location) {
207 var eventLocationText = htmlToText(event.item.location);
208 // Get the the html template for formatting the location
209 var eventLocationTemplate = eventHoverLocationTemplate();
210 // Format the event location data according to the the event location
212 eventLocation = eventLocationTemplate.format(
217 // Get only template data if there exists a profile name
218 if (event.item['author-name']) {
220 var eventProfileNameTemplate = eventHoverProfileNameTemplate();
221 // Insert the data into the template
222 eventProfileName = eventProfileNameTemplate.format(
223 event.item['author-link'],
224 event.item['author-name']
228 // Format the event data according to the event hover template
229 var formatted = data.format(
230 event.item['author-avatar'], // this isn't used at the present time
235 monthShort.replace('.', ''), // Get rid of possible dots in the string
242 // transform the the list view event element into formatted html
243 function formatListViewEvent(event) {
244 // The basic template for list view
245 var template = '<td class="fc-list-item-title fc-widget-content">\
246 <hr class="seperator"></hr>\
247 <div class="event-card">\
248 <div class="popover-content hovercard-content">{0}</div>\
251 // Use the formation of the event hover and insert it in the base list view template
252 var formatted = template.format(eventHoverHtmlContent(event));