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 formatEventLocationText(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 formatEventLocationText(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="hover-card-details">\
131 <div class="hover-card-header left-align">\
132 <div class="event-hover-left-date left-align">\
133 <span class="event-date-wrapper medium">\
134 <span class="event-hover-short-month">{6}</span>\
135 <span class="event-hover-short-date">{7}</span>\
138 <div class="event-card-content media-body">\
139 <div class="event-hover-title">{3}</div>\
140 <div class="event-property"><span class="event-hover-date">{5}</span>{4}\
141 <div class="event-hover-profile-name profile-entry-name">\
142 <span class="left-align1"><a href="{1}" class="userinfo">{2}</a></span>\
146 <div class="clearfix"></div>\
153 // The template for presenting the event location in the event hover-card
154 function eventHoverLocationTemplate() {
155 var template = '<span class="event-hover-location"> {0}</span></div>';
159 // transform the event data to html so we can use it in the event hover-card
160 function eventHoverHtmlContent(event) {
161 var eventLocation = '';
162 // Get the Browser language
163 var locale = window.navigator.userLanguage || window.navigator.language;
166 // Use the browser language for date formatting
167 moment.locale(locale);
169 // format dates to different styles
170 var startDate = moment(event.item.start).format('dd HH:mm');
171 var endDate = moment(event.item.finsih).format('dd HH:mm');
172 var monthShort = moment(event.item.start).format('MMM');
173 var dayNumberStart = moment(event.item.start).format('DD');
174 var dayNumberEnd = moment(event.item.finish).format('DD');
175 var startTime = moment(event.item.start).format('HH:mm');
176 var endTime = moment(event.item.finish).format('HH:mm');
179 var formattedDate = startDate
181 // We only need the to format the end date if the event does have
183 if (event.item.nofinish == 0) {
184 formattedDate = startDate + ' - ' + endTime;
186 // use a different Format (15. Feb - 18. Feb) if the events end date
187 // is not the start date
188 if ( dayNumberStart != dayNumberEnd) {
189 formattedDate = moment(event.item.start).format('Do MMM') +
191 moment(event.item.finish).format('Do MMM');
195 // Get the html template
196 data = eventHoverBodyTemplate();
198 // Get only template data if there exist location data
199 if (event.item.location != '') {
200 var eventLocationText = formatEventLocationText(event.item.location);
201 // Get the the html template for formatting the location
202 var eventLocationTemplate = eventHoverLocationTemplate();
203 // Format the event location data according to the the event location
205 eventLocation = eventLocationTemplate.format(
210 // Format the event data according to the event hover template
211 var formatted = data.format(
212 event.item['author-avatar'], // this isn't used at the present time
213 event.item['author-link'],
214 event.item['author-name'],
218 monthShort.replace('.', ''), // Get rid of possible dots in the string
225 // transform the the list view event element into formatted html
226 function formatListViewEvent(event) {
227 // The basic template for list view
228 var template = '<td class="fc-list-item-title fc-widget-content">\
229 <hr class="seperator"></hr>\
230 <div class="event-card">\
231 <div class="popover-content hovercard-content">{0}</div>\
234 // Use the formation of the event hover and insert it in the base list view template
235 var formatted = template.format(eventHoverHtmlContent(event));
240 // Format event location in pure text
241 function formatEventLocationText(location) {
242 // Friendica can store the event location as text or as html
243 // We need to check if the location is html. In this case we need
244 // to transform it into clean text
245 if (location.startsWith("<div")) {
246 var locationHtml = $.parseHTML( location );
247 var eventLocationText = locationHtml[0]['innerText'];
249 var eventLocationText = location.replace("<br>", " ");
252 return eventLocationText;