Changes for page Calendar Macro

Last modified by Benjamin Fischer on 2025/07/01 00:06

From version 1.1
edited by Benjamin Fischer
on 2024/07/26 12:42
Change comment: Install extension [org.xwiki.contrib:macro-fullcalendar/2.0.3]
To version 3.1
edited by Benjamin Fischer
on 2025/04/29 00:08
Change comment: Migrated property [executionIsolated] from class [XWiki.WikiMacroClass]

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,8 +1,4 @@
1 1  {{velocity}}
2 -#set($discard = $xwiki.jsx.use("Calendar.JQuery", {'defer': false, 'minify': false}))
3 -#set($discard = $xwiki.jsx.use("Calendar.JQueryUI", {'defer': false, 'minify': false}))
4 -#set($discard = $xwiki.jsx.use("Calendar.Moment", {'defer': false, 'minify': false}))
5 -#set($discard = $xwiki.jsx.use("Calendar.FullCalendar", {'defer': false, 'minify': false}))
6 6  #set($discard = $xwiki.ssx.use("Calendar.FullCalendar"))
7 7  ##
8 8  #if($calcounter)
... ... @@ -84,10 +84,16 @@
84 84  #if(!$editable)
85 85   #set($editable = "false")
86 86  #end
87 -#set($json = $xcontext.macro.params.json)
88 -#if(!$json)
89 - #set($json = $xwiki.getDocument("Calendar.JSONService").getURL("get"))
83 +#set($extraFields = $xcontext.macro.params.extraFields)
84 +#set($json = $xwiki.getDocument('Calendar.JSONService').getURL('get'))
85 +#if ($xcontext.macro.params.json)
86 + #set($json = $xcontext.macro.params.json)
90 90  #end
88 +#set($iCal = $xcontext.macro.params.iCal)
89 +#if ($iCal)
90 + ## The iCal format is serialized as JSON and should be used only when the JSON parameter is not specified.
91 + #set($json = $xwiki.getDocument('Calendar.ICalToJSON').getURL('get', "iCal=$escapetool.url($iCal)"))
92 +#end
91 91  #set($updateurl = $xcontext.macro.params.updateurl)
92 92  #if(!$updateurl)
93 93   #set($updateurl = $xwiki.getDocument("Calendar.UpdateService").getURL("get"))
... ... @@ -99,111 +99,167 @@
99 99  #set($gCal = $xcontext.macro.params.gCal)
100 100  {{html clean="false"}}
101 101  <script>
102 -require(['fullcalendar', 'gcal'], function ($) {
103 - function updateEvent(page, isResize, delta, allDay, revertFunc) {
104 - // Initialize notification boxes
105 - var savingBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.inprogress')", "inprogress", {inactive: true});
106 - var savedBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.done')", "done", {inactive: true});
107 - var failedBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.error')", "error", {inactive: true});
104 +/************************************
105 + * Configure RequireJS to use jQuery-UI
106 + ************************************/
107 +require.config({
108 + paths: {
109 + 'fullcalendar-setup': new XWiki.Document('FullCalendar', 'Calendar').getURL('jsx', 'minify=$!services.debug.minify')
110 + }
111 +});
112 +require(['fullcalendar-setup'], function() {
113 + require(['jquery', 'jquery-ui', 'fullcalendar', 'gcal'], function ($) {
114 + function updateEvent(page, isResize, delta, allDay, revertFunc) {
115 + // Initialize notification boxes
116 + var savingBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.inprogress')", "inprogress", {inactive: true});
117 + var savedBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.done')", "done", {inactive: true});
118 + var failedBox = new XWiki.widgets.Notification("$!services.localization.render('xwiki.calendar.notification.error')", "error", {inactive: true});
108 108  
109 - // Display loading notification
110 - savingBox.show();
111 - savedBox.hide();
112 - failedBox.hide();
120 + // Display loading notification
121 + savingBox.show();
122 + savedBox.hide();
123 + failedBox.hide();
113 113  
114 - // Compute days and minutes in order to keep backwards compatibility
115 - var dayDelta = delta._data.days;
116 - var minuteDelta = delta._data.hours * 60 + delta._data.minutes;
125 + // Compute days and minutes in order to keep backwards compatibility
126 + var dayDelta = delta._data.days;
127 + var minuteDelta = delta._data.hours * 60 + delta._data.minutes;
117 117  
118 - // Let's call the calendar update
119 - var url = '$updateurl';
120 - url = url + "#if($stringtool.contains($updateurl, "?"))&#{else}?#{end}xpage=plain&outputSyntax=plain&classname=$!{xcontext.macro.params.classname}&startfield=$!{xcontext.macro.params.startfield}&endfield=$!{xcontext.macro.params.endfield}&durationfield=$!{xcontext.macro.params.durationfield}&page=" + page + "&isResize=" + (isResize ? "1" : "0") + "&dayDelta=" + dayDelta + "&minuteDelta=" + minuteDelta + ((allDay) ? "&allDay=1" : "");
129 + // Let's call the calendar update
130 + var url = '$updateurl';
131 + url = url + "#if($stringtool.contains($updateurl, "?"))&#{else}?#{end}xpage=plain&outputSyntax=plain&classname=$!{xcontext.macro.params.classname}&startfield=$!{xcontext.macro.params.startfield}&endfield=$!{xcontext.macro.params.endfield}&durationfield=$!{xcontext.macro.params.durationfield}&page=" + page + "&isResize=" + (isResize ? "1" : "0") + "&dayDelta=" + dayDelta + "&minuteDelta=" + minuteDelta + ((allDay) ? "&allDay=1" : "");
121 121  
122 - jQuery.ajax({ url: url }).fail(function(data) {
123 - savingBox.hide();
124 - failedBox.show();
125 - revertFunc();
126 - }).success(function(data) {
127 - if (data.indexOf("OK") == 0) {
133 + $.ajax({ url: url }).fail(function(data) {
128 128   savingBox.hide();
129 - savedBox.show();
130 - } else {
131 - savingBox.hide();
132 132   failedBox.show();
133 133   revertFunc();
134 - }
135 - });
136 - }
137 + }).success(function(data) {
138 + if (data.indexOf("OK") == 0) {
139 + savingBox.hide();
140 + savedBox.show();
141 + } else {
142 + savingBox.hide();
143 + failedBox.show();
144 + revertFunc();
145 + }
146 + });
147 + }
137 137  
138 - var monthNames = $!services.localization.render('xwiki.calendar.monthNames')
139 - var monthNamesShort = $!services.localization.render('xwiki.calendar.monthNamesShort');
140 - var dayNames = $!services.localization.render('xwiki.calendar.dayNames');
141 - var dayNamesShort = $!services.localization.render('xwiki.calendar.dayNamesShort');
149 + var monthNames = $!services.localization.render('xwiki.calendar.monthNames')
150 + var monthNamesShort = $!services.localization.render('xwiki.calendar.monthNamesShort');
151 + var dayNames = $!services.localization.render('xwiki.calendar.dayNames');
152 + var dayNamesShort = $!services.localization.render('xwiki.calendar.dayNamesShort');
142 142  
143 - jQuery(document).ready(function() {
144 - // The page is now ready, initialize the calendar...
145 - jQuery('#calendar${calcounter}').fullCalendar({
146 - columnFormat: {
147 - month : "$!services.localization.render('xwiki.calendar.columnFormat.month')",
148 - week : "$!services.localization.render('xwiki.calendar.columnFormat.week')",
149 - day : "$!services.localization.render('xwiki.calendar.columnFormat.day')"
150 - },
151 - titleFormat: {
152 - month : "$!services.localization.render('xwiki.calendar.titleFormat.month')",
153 - week : "$!services.localization.render('xwiki.calendar.titleFormat.week')",
154 - day : "$!services.localization.render('xwiki.calendar.titleFormat.day')"
155 - },
156 - buttonText: {
157 - today : "$!services.localization.render('xwiki.calendar.button.today')",
158 - day : "$!services.localization.render('xwiki.calendar.button.day')",
159 - week : "$!services.localization.render('xwiki.calendar.button.week')",
160 - month : "$!services.localization.render('xwiki.calendar.button.month')"
161 - },
162 - timeFormat : "$!services.localization.render('xwiki.calendar.timeFormat')",
163 - axisFormat : "$!services.localization.render('xwiki.calendar.axisFormat')",
164 - allDayText : "$!services.localization.render('xwiki.calendar.allDayText')",
165 - monthNames : monthNames,
166 - monthNamesShort : monthNamesShort,
167 - dayNames : dayNames,
168 - dayNamesShort : dayNamesShort,
169 - googleCalendarApiKey : "$gApiKey",
170 - eventSources: [
171 - #if($json != $jsonService || $!{xcontext.macro.params.classname} != '')
172 - "${json}#if($stringtool.contains($json, "?"))&#{else}?#{end}xpage=plain&outputSyntax=plain&classname=$!{xcontext.macro.params.classname}&startfield=$!{xcontext.macro.params.startfield}&endfield=$!{xcontext.macro.params.endfield}&durationfield=$!{xcontext.macro.params.durationfield}"
173 - #end
174 - #if($!gCal != '')
175 - ,
176 - #set($calendars = $stringtool.split($gCal, ','))
177 - #foreach($calendar in $calendars)
178 - { googleCalendarId: "$stringtool.strip($calendar)" }
179 - #if($velocityCount < $calendars.size())
180 - ,
181 - #end
154 + function init() {
155 + // The page is now ready, initialize the calendar...
156 + var progressNotification;
157 + $('#calendar${calcounter}').fullCalendar({
158 + views: {
159 + month : {
160 + columnFormat: "$!services.localization.render('xwiki.calendar.columnFormat.month')",
161 + titleFormat: "$!services.localization.render('xwiki.calendar.titleFormat.month')",
162 + buttonText: "$!services.localization.render('xwiki.calendar.button.month')"
163 + },
164 + week : {
165 + columnFormat: "$!services.localization.render('xwiki.calendar.columnFormat.week')",
166 + titleFormat: "$!services.localization.render('xwiki.calendar.titleFormat.week')",
167 + buttonText: "$!services.localization.render('xwiki.calendar.button.week')"
168 + },
169 + day : {
170 + columnFormat: "$!services.localization.render('xwiki.calendar.columnFormat.day')",
171 + titleFormat: "$!services.localization.render('xwiki.calendar.titleFormat.day')",
172 + buttonText: "$!services.localization.render('xwiki.calendar.button.day')"
173 + },
174 + today: {
175 + buttonText: "$!services.localization.render('xwiki.calendar.button.today')"
176 + }
177 + },
178 + timeFormat : "$!services.localization.render('xwiki.calendar.timeFormat')",
179 + axisFormat : "$!services.localization.render('xwiki.calendar.axisFormat')",
180 + allDayText : "$!services.localization.render('xwiki.calendar.allDayText')",
181 + monthNames : monthNames,
182 + monthNamesShort : monthNamesShort,
183 + dayNames : dayNames,
184 + dayNamesShort : dayNamesShort,
185 + googleCalendarApiKey : "$gApiKey",
186 + eventSources: [
187 + #if($json != $jsonService || "$!xcontext.macro.params.classname" != '')
188 + "${json}#if($stringtool.contains($json, "?"))&#{else}?#{end}xpage=plain&outputSyntax=plain&classname=$!{xcontext.macro.params.classname}&startfield=$!{xcontext.macro.params.startfield}&endfield=$!{xcontext.macro.params.endfield}&durationfield=$!{xcontext.macro.params.durationfield}&extraFields=$!{extraFields}"
182 182   #end
183 - #end
184 - ],
185 - header: {
186 - left : '$left',
187 - center : '$center',
188 - right : '$right'
189 - }
190 - #if($timeFormat != ""), timeFormat : '$timeFormat' #end
191 - #if($defaultView != ""), defaultView : '$defaultView' #end
192 - #if($firstDay != ""), firstDay : '$firstDay' #end
193 - #if($firstHour != ""), firstHour : '$firstHour' #end
194 - #if($minTime != ""), minTime : '$minTime' #end
195 - #if($maxTime != ""), maxTime : '$maxTime' #end
196 - ,defaultDate : '${year}-${month}-${date}'
197 - ,editable : $editable
198 - ,eventDrop : function(event, delta, revertFunc) {
199 - updateEvent(event.id, false, delta, event._allDay, revertFunc);
200 - }
201 - ,eventResize : function(event, delta, revertFunc) {
202 - updateEvent(event.id, true, delta, false, revertFunc);
203 - }
204 - })
190 + #if($!gCal != '')
191 + ,
192 + #set($calendars = $stringtool.split($gCal, ','))
193 + #foreach($calendar in $calendars)
194 + { googleCalendarId: "$stringtool.strip($calendar)" }
195 + #if($foreach.count < $calendars.size())
196 + ,
197 + #end
198 + #end
199 + #end
200 + ],
201 + header: {
202 + left : '$left',
203 + center : '$center',
204 + right : '$right'
205 + }
206 + #if($timeFormat != ""), timeFormat : '$timeFormat' #end
207 + #if($defaultView != ""), defaultView : '$defaultView' #end
208 + #if($firstDay != ""), firstDay : '$firstDay' #end
209 + #if($firstHour != ""), firstHour : '$firstHour' #end
210 + #if($minTime != ""), minTime : '$minTime' #end
211 + #if($maxTime != ""), maxTime : '$maxTime' #end
212 + ,defaultDate : '${year}-${month}-${date}'
213 + ,editable : $editable
214 + ,eventDrop : function(event, delta, revertFunc) {
215 + updateEvent(event.id, false, delta, event._allDay, revertFunc);
216 + }
217 + ,eventResize : function(event, delta, revertFunc) {
218 + updateEvent(event.id, true, delta, false, revertFunc);
219 + },
220 + eventRender: function(event, element) {
221 + // Add tooltip on the calendar element.
222 + var tooltip = '';
223 + if (event.status) {
224 + tooltip = tooltip + "$services.localization.render('xwiki.calendar.event.status') " + event.status + '\n';
225 + }
226 + if (event.location) {
227 + tooltip = tooltip + "$services.localization.render('xwiki.calendar.event.location') " + event.location + '\n';
228 + }
229 + if (event.description) {
230 + tooltip = tooltip + "$services.localization.render('xwiki.calendar.event.description') " + event.description;
231 + }
232 + element.attr('title', tooltip);
233 + },
234 + loading: function( isLoading) {
235 + if (isLoading) {
236 + if (typeof progressNotification === 'undefined') {
237 + progressNotification = new XWiki.widgets.Notification(
238 + "$escapetool.javascript($services.localization.render('xwiki.calendar.notification.loading'))", 'inprogress');
239 + } else {
240 + var oldNotification = progressNotification;
241 + progressNotification = new XWiki.widgets.Notification(
242 + "$escapetool.javascript($services.localization.render('xwiki.calendar.notification.loading'))", 'inprogress');
243 + oldNotification.replace(progressNotification);
244 + }
245 + } else {
246 + var oldNotification = progressNotification;
247 + progressNotification = new XWiki.widgets.Notification(
248 + "$escapetool.javascript($services.localization.render('xwiki.calendar.notification.loaded'))", 'done');
249 + oldNotification.replace(progressNotification);
250 + }
251 + }
252 + });
253 + }
254 +
255 + // Load the calendar in edit mode.
256 + $(window).on('xwiki:dom:updated', function() {
257 + init();
258 + });
259 + // Load the calendar in view mode.
260 + $(document).ready(function() {
261 + init();
262 + });
205 205   });
206 206  });
207 207  </script>
208 208  {{/html}}
209 -{{velocity}}
267 +{{/velocity}}
XWiki.WikiMacroParameterClass[17]
Parameter description
... ... @@ -1,0 +1,1 @@
1 +The URL to access a calendar in iCal format (.ics file). If this parameter is used, the JSON one should be empty.
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +No
Parameter name
... ... @@ -1,0 +1,1 @@
1 +iCal
XWiki.WikiMacroParameterClass[18]
Parameter description
... ... @@ -1,0 +1,1 @@
1 +Provide extra fields to be displayed in the event tooltip. An empty list or a list of exactly 3 values that represent event description, event location and event status, in this order, is expected.
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +No
Parameter name
... ... @@ -1,0 +1,1 @@
1 +extraFields