Änderungen von Dokument Calendar Macro
Zuletzt geändert von xwikiadmin am 2025/12/03 10:04
Von Version 2.1
bearbeitet von xwikiadmin
am 2023/04/25 10:51
am 2023/04/25 10:51
Änderungskommentar:
Install extension [com.xwiki.mocca-calendar:application-mocca-calendar-ui/2.12]
Auf Version 7.1
bearbeitet von xwikiadmin
am 2025/05/21 09:32
am 2025/05/21 09:32
Änderungskommentar:
Install extension [com.xwiki.mocca-calendar:application-mocca-calendar-ui/2.15.2]
Zusammenfassung
-
Objekte (3 geändert, 3 hinzugefügt, 0 gelöscht)
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,5 +1,11 @@ 1 -define('moccaCalendar', ['jquery', 'fullcalendar', 'moment'], function(jQuery, fullCalendar, moment) { 1 +require.config({ 2 + paths: { 3 + purify: "$services.webjars.url('org.webjars.npm:dompurify', 'dist/purify.js')" 4 + }, 5 +}); 2 2 7 +define('moccaCalendar', ['jquery', 'fullcalendar', 'moment', 'purify'], function(jQuery, fullCalendar, moment, purify) { 8 + 3 3 // Make sure the XWiki 'namespace' and the ModalPopup class exist. 4 4 if (typeof(XWiki) == "undefined" || typeof(XWiki.widgets) == "undefined" || typeof(XWiki.widgets.ModalPopup) == "undefined") { 5 5 if (typeof console != "undefined" && typeof console.warn == "function") { ... ... @@ -34,6 +34,9 @@ 34 34 this.timeFormat = ''; 35 35 this.dayFormat = dateFormat; 36 36 } 43 + document.addEventListener('calendarImportCompleted', () => { 44 + calendar.fullCalendar('refetchEvents'); 45 + }); 37 37 }, 38 38 displayError: function(errorMessage) { 39 39 if (!errorMessage) { ... ... @@ -121,6 +121,12 @@ 121 121 document.cookie = cookieName + value + "; path=/"; 122 122 }; 123 123 133 + function removeColorPickers() { 134 + jQuery('#mocca-event-edit-form .color-picker').each(function(index) { 135 + jQuery('#' + jQuery(this).data('colpickId')).remove(); 136 + }); 137 + } 138 + 124 124 // 125 125 // the dialog to show / edit events 126 126 // ... ... @@ -136,7 +136,7 @@ 136 136 // call constructor from ModalPopup with params content, shortcuts, options 137 137 $super( 138 138 // this element will end up as 'this.content' 139 - new Element('form', {'class' : 'xform'}), 154 + new Element('form', {'class' : 'xform', 'id' : 'mocca-event-edit-form'}), 140 140 { 141 141 "show": {method: this.showDialog, keys: []}, 142 142 "close": {method: this.closeDialog, keys: ['Esc']} ... ... @@ -147,6 +147,7 @@ 147 147 title : this.interactionParameters.editMode ? "$escapetool.javascript($services.localization.render('MoccaCalendar.calendarevent.create'))" : "$escapetool.javascript($services.localization.render('MoccaCalendar.calendarevent.view'))", 148 148 removeOnClose : true, 149 149 onClose : function() { 165 + removeColorPickers(); 150 150 document.stopObserving('xwiki:moccacalendar:editmode'); 151 151 document.stopObserving('xwiki:moccacalendar:instancesaved'); 152 152 } ... ... @@ -187,6 +187,7 @@ 187 187 // and we only listen for the results to close the dialog 188 188 document.observe('xwiki:moccacalendar:instancesaved', function(event) { 189 189 this.savedBox.show(); 206 + removeColorPickers(); 190 190 this.closeDialog(); 191 191 this.helper.calendar.fullCalendar('refetchEvents'); 192 192 }.bind(this)); ... ... @@ -282,6 +282,7 @@ 282 282 } else { 283 283 saveUrl = this.interactionParameters.event.saveUrl; 284 284 } 302 + this.content.title.value = purify.sanitize(this.content.title.value) 285 285 this.content.writeAttribute('action', saveUrl + '&xpage=plain&ajax=true'); 286 286 this.content.request({ 287 287 onSuccess: function() { ... ... @@ -288,6 +288,7 @@ 288 288 this.saving = false; 289 289 this.savingBox.hide(); 290 290 this.savedBox.show(); 309 + removeColorPickers(); 291 291 this.closeDialog(); 292 292 this.helper.calendar.fullCalendar('refetchEvents'); 293 293 }.bind(this), ... ... @@ -384,18 +384,20 @@ 384 384 var buttons = new Element('div', {'class':'buttons'}); 385 385 var oldSkin = ! $('body').hasClassName('skin-flamingo'); // FIXME: bad b/w compat hack 386 386 formcontent.insert(buttons); 406 + // When you are in a read only calendar you only need the close button for the modal and you MUST Not fire 407 + // the xwiki:moccacalendar:editloaded event because you will get a bunch of errors. 387 387 if (this.interactionParameters.editMode) { 388 388 var that = this; 389 - buttons.insert(this.createButton("submit","$escapetool.javascript($services.localization.render('save'))","","save-moccacalendar-event","btn")); 390 - buttons.down('#save-moccacalendar-event').observe('click', this.submitForm.bind(this)); 410 + if(this.helper.createEventBaseUrl.indexOf('disabled=disabled') === -1) { 411 + buttons.insert(this.createButton("submit","$escapetool.javascript($services.localization.render('save'))","","save-moccacalendar-event","btn")); 412 + buttons.down('#save-moccacalendar-event').observe('click', this.submitForm.bind(this)); 413 + // MOCCACAL-128: the event template has a space in the title to avoid showing the page name, but we want to remove this on load 414 + var titleField = formcontent.down('input[name="title"]') 415 + if (titleField && titleField.getAttribute('value').trim() == '') { titleField.setAttribute('value','') } 416 + document.fire('xwiki:moccacalendar:editloaded'); 417 + } 391 391 buttons.insert('<span class="buttonwrapper"><a href="#" id="cancel-moccacalendar-event" class="secondary button">' + "$escapetool.javascript($services.localization.render('cancel'))" + '</a></span>'); 392 392 buttons.down('#cancel-moccacalendar-event').observe('click', this.closeDialog.bind(this)); 393 - 394 - // MOCCACAL-128: the event template has a space in the title to avoid showing the page name, but we want to remove this on load 395 - var titleField = formcontent.down('input[name="title"]') 396 - if (titleField && titleField.getAttribute('value').trim() == '') { titleField.setAttribute('value','') } 397 - 398 - document.fire('xwiki:moccacalendar:editloaded'); 399 399 $("MoccaCalendarEvent.MoccaCalendarEventClass_0_title").focus(); 400 400 } else { 401 401 var leftGroup = new Element('div', {'class':'btn-group btn-group-left'}); ... ... @@ -410,13 +410,19 @@ 410 410 } 411 411 // FIXME: this should be a plain link, but then it has no styles 412 412 if (oldSkin) { 413 - leftGroup.insert(this.createButton("button","$escapetool.javascript($services.localization.render('view'))","","view-moccacalendar-event","btn")); 434 + if (this.interactionParameters.event.readOnly != true) { 435 + leftGroup.insert(this.createButton("button","$escapetool.javascript($services.localization.render('view'))","","view-moccacalendar-event","btn")); 436 + } 414 414 leftGroup.insert('<span class="buttonwrapper"><a href="#" id="cancel-moccacalendar-event" class="secondary button">' + "$escapetool.javascript($services.localization.render('cancel'))" + '</a></span>'); 415 415 } else { 416 - leftGroup.insert(' <button class="button btn btn-default" id="view-moccacalendar-event"><span class="glyphicon glyphicon-file"></span> '+"$escapetool.javascript($services.localization.render('view'))"+'</button>'); 439 + if (this.interactionParameters.event.readOnly != true) { 440 + leftGroup.insert(' <button class="button btn btn-default" id="view-moccacalendar-event"><span class="glyphicon glyphicon-file"></span> '+"$escapetool.javascript($services.localization.render('view'))"+'</button>'); 441 + } 417 417 leftGroup.insert('<button class="button btn btn-default" id="cancel-moccacalendar-event"><span class="glyphicon glyphicon-remove"></span> '+"$escapetool.javascript($services.localization.render('cancel'))"+'</button>'); 418 418 } 419 - leftGroup.down("#view-moccacalendar-event").observe('click', function(e) { e.stop(); window.location.href = this.interactionParameters.event.viewUrl; }.bind(this)); 444 + if (this.interactionParameters.event.readOnly != true) { 445 + leftGroup.down("#view-moccacalendar-event").observe('click', function(e) { e.stop(); window.location.href = this.interactionParameters.event.viewUrl; }.bind(this)); 446 + } 420 420 leftGroup.down('#cancel-moccacalendar-event').observe('click', this.closeDialog.bind(this)); 421 421 if (this.interactionParameters.event.canDelete) { 422 422 var rightGroup = new Element('div', {'class':'btn-group btn-group-right'}); ... ... @@ -456,6 +456,9 @@ 456 456 script.remove(); 457 457 }); 458 458 content.insert('<div id="formcontent"><div id="forminnercontent">' + container.innerHTML + '</div></div>'); 486 + 487 + var parentModalPopup = jQuery('.xdialog-box-moccacal-modal-popup').toArray(); 488 + document.fire('xwiki:dom:updated', {elements: parentModalPopup}); 459 459 }, 460 460 handleDatetimeFieldChange : function(event, element) { 461 461 if (this.saving) { return; } ... ... @@ -716,10 +716,22 @@ 716 716 717 717 }); 718 718 749 +define('mocca-calendar-notification', { 750 + prefix: 'MoccaCalendar.notification.', 751 + keys: [ 752 + 'import.inprogress', 753 + 'import.done', 754 + 'import.error', 755 + 'import.filetoolarge', 756 + 'addObject.error' 757 + ] 758 +}); 759 + 719 719 /** 720 - * Delet ingan event761 + * Delete event and calendar import actions. 721 721 */ 722 -require(['jquery'], function($) { 763 +require(['jquery', 'xwiki-meta', 'xwiki-job-runner', 'xwiki-l10n!mocca-calendar-notification'], 764 + function($, xwikiMeta, JobRunner, l10n) { 723 723 /** 724 724 * Events triggered before deleteEvents modal is shown: save the button that triggers 725 725 * the modal, close MoccaCalendarPopup, update the name of event on displayed text. ... ... @@ -754,4 +754,100 @@ 754 754 var calendarPopup = relatedTarget.data('calendarPopup'); 755 755 new XWiki.MoccaCalendar.MoccaCalendarPopup(calendarPopup.interactionParameters, calendarPopup.helper); 756 756 }); 799 + 800 + // Trigger the upload manually when the button is clicked. 801 + $(document).on('click', '#import-calendar-file-button', function(event) { 802 + var form = $('#import-calendar-file form').get(0); 803 + if (event) { 804 + event.preventDefault(); 805 + } 806 + startUploading(form); 807 + }); 808 + 809 + $(document).on('click', '.box.infomessage > p > span > a', function(event) { 810 + event.preventDefault(); 811 + const addObjectButton = $('#add-calendar-object'); 812 + const target = addObjectButton.data('target'); 813 + // To be adapted to the standard XWiki rest endpoint for object creation after 814 + // XWIKI-20704: NullPointerException (NPE) when accessing objects with ComputedField properties from REST is fixed. 815 + var documentReference = XWiki.Model.resolve('MoccaCalendar.Code.MoccaCalendarObjectCreator', 816 + XWiki.EntityType.DOCUMENT); 817 + var targetUrl = new XWiki.Document(documentReference).getURL(); 818 + var params = { 819 + 'documentRef': target 820 + }; 821 + $.ajax({ 822 + url: targetUrl, 823 + type: 'POST', 824 + data: params, 825 + success: function (response) { 826 + window.location.reload(); 827 + }, 828 + error: function (xhr, status, error) { 829 + console.error('Failed to add the MoccaCalendarClass object', error); 830 + var notification = new XWiki.widgets.Notification(l10n.get('addObject.error'), 'error'); 831 + } 832 + }); 833 + }); 834 + 835 + // Start uploading this file by creating a new XHR object with the file data. 836 + var startUploading = function (form) { 837 + var formData = new FormData(form); 838 + var select = form.down('#import-calendar-parent'); 839 + var input = form.down('#import-ical-file-input'); 840 + if (input.files[0].size < input.dataset.maxFileSize) { 841 + var params = {}; 842 + params[select.name] = select.value; 843 + formData.action = form.action + "?" + $.param(params); 844 + // Create XMLHttpRequest object and POST the data 845 + var request = this.request = new XMLHttpRequest(); 846 + request.open('POST', formData.action); 847 + request.send(formData); 848 + checkImportJob(select.value); 849 + } else { 850 + var notification = new XWiki.widgets.Notification(l10n.get('import.filetoolarge'), 'error'); 851 + } 852 + } 853 + 854 + const checkImportJob = function(selectedCalendar) { 855 + let documentReference = XWiki.Model.resolve('MoccaCalendar.Code.ImportJobResource', XWiki.EntityType.DOCUMENT); 856 + var targetURL = new XWiki.Document(documentReference).getURL('get'); 857 + var targetJobId = ['moccacalendar', 'import', selectedCalendar]; 858 + var data = []; 859 + data.push( 860 + {name: 'outputSyntax', value: 'plain'}, 861 + {name: 'sheet', value: 'MoccaCalendar.Code.ImportJobResource'}, 862 + {name: 'action', value: 'jobStatus'}, 863 + {name: 'jobId', value: targetJobId.join('/')}, 864 + {name: 'data', value: 'jobStatus'}, 865 + {name: 'form_token', value: xwikiMeta.form_token} 866 + ); 867 + var notification = new XWiki.widgets.Notification(l10n.get('import.inprogress'), 'inprogress'); 868 + $('#import-calendar-file-button').prop('disabled', true); 869 + return Promise.resolve(new JobRunner({ 870 + createStatusRequest: function(jobId) { 871 + return { 872 + url: targetURL, 873 + data: { 874 + outputSyntax: 'plain', 875 + sheet: 'MoccaCalendar.Code.ImportJobResource', 876 + data: 'jobStatus', 877 + jobId: jobId.join('/') 878 + } 879 + }; 880 + } 881 + }).run(targetURL, data)).then((response) => { 882 + if (response.error !== null) { 883 + throw new Error(response.error.message); 884 + } else { 885 + document.dispatchEvent(new Event('calendarImportCompleted')); 886 + notification.replace(new XWiki.widgets.Notification(l10n.get('import.done'),'done')); 887 + } 888 + }).catch((reason) => { 889 + notification.replace(new XWiki.widgets.Notification(l10n.get('import.error'),'error')); 890 + return Promise.reject(reason); 891 + }).finally(() => { 892 + $('#import-calendar-file-button').prop('disabled', false); 893 + }); 894 + }; 757 757 });
- XWiki.StyleSheetExtension[0]
-
- Code
-
... ... @@ -79,3 +79,24 @@ 79 79 .skin-flamingo .gadget .fc h2 { 80 80 font-size: 140%; 81 81 } 82 + 83 +.import-form { 84 + padding: 2em; 85 +} 86 + 87 +.import-form label { 88 + margin-bottom: 0.8em; 89 + font-weight: bold; 90 +} 91 + 92 +.import-form select, 93 +.import-form #import-ical-file-input { 94 + width: 100%; 95 + margin-bottom: 1.6em; 96 + border-radius: 0.4em; 97 +} 98 + 99 +.import-form #import-ical-file-input { 100 + padding: 0.6em 1em; 101 + border: 1px solid #ccc; 102 +}
- XWiki.WikiMacroClass[0]
-
- Makro-Code
-
... ... @@ -67,6 +67,33 @@ 67 67 #if(!$date) 68 68 #set($date = "") 69 69 #end 70 +#set($gCal = "$!xcontext.macro.params.gCal") 71 +#set($gApiKey = $xcontext.macro.params.gApiKey) 72 +#if(!$gApiKey) 73 + #set($gApiKey = "") 74 +#end 75 +#set($iCal = $xcontext.macro.params.iCal) 76 +#if(!$iCal) 77 + #set ($iCal = "") 78 +#end 79 +## Prepare the fields if the subscribed class is present 80 +#set ($subscribed = $doc.getObject('MoccaCalendar.MoccaCalendarSubscribeClass')) 81 +#if ($subscribed) 82 + #set ($subscribediCal = $subscribed.getValue('iCal')) 83 + #set ($subscribedgCals = $subscribed.getValue('gCal')) 84 + #set ($gApiKeySubscribed = $subscribed.getValue('gApiKey')) 85 + #set ($subscribedColor = $subscribed.getValue('color')) 86 + #set ($subscribedTextColor = $subscribed.getValue('textColor')) 87 + #set ($disableCreationEvent = 'disabled') 88 +#else 89 + #set ($subscribediCals = '') 90 + #set ($subscribedgCals = '') 91 + #set ($gApiKeySubscribed = '') 92 + #set ($subscribedColor = 'blue') 93 + #set ($subscribedTextColor = 'white') 94 + #set ($disableCreationEvent = "") 95 +#end 96 + 70 70 ## If the date format is not set in MoccaCalendarEventClass, we are going to use the date format from the current wiki. 71 71 #set($dateFormat = $!xwiki.getClass("MoccaCalendar.MoccaCalendarEventClass").get("startDate").getProperty('dateFormat').value) 72 72 #if("$!dateFormat" == "") ... ... @@ -124,23 +124,148 @@ 124 124 </div> 125 125 </div> 126 126 #end 127 -{{/velocity}} 128 128 129 -{{include reference="Licenses.Code.VelocityMacros"/}} 155 +#macro(importCalendarFileModal) 156 + <div class="modal fade" id="import-calendar-file" tabindex="-1" role="dialog"> 157 + <div class="modal-dialog"> 158 + <div class="modal-content"> 159 + <div class="modal-header"> 160 + <button type="button" class="close" data-dismiss="modal">×</button> 161 + <h4 class="modal-title"> 162 + $escapetool.xml($services.localization.render('MoccaCalendar.import.modal.title')) 163 + </h4> 164 + </div> 165 + <div class="modal-body"> 166 + #set ($escapedCalendarSpace = $escapetool.xml($doc.getSpace())) 167 + #set ($escapedCalendarName = $escapetool.xml($doc.getDocumentReference().getName())) 168 + #set ($actionURL = "$request.getContextPath()/rest/moccacalendar/import") 169 + #set ($xwikiCalendarDoc = $xwiki.getDocument($calendarDoc)) 170 + #set ($calendarObject = $xwikiCalendarDoc.getObject('MoccaCalendar.MoccaCalendarClass')) 171 + <form class="xform" action="$actionURL" method="post"> 172 + <div class="import-form"> 173 + #if ($calendarObject || $xwikiCalendarDoc.getFullName() == 'MoccaCalendar.Events') 174 + <label for="import-calendar-parent"> 175 + $escapetool.xml($services.localization.render('MoccaCalendar.calendar'))</label> 176 + <select id="import-calendar-parent" name="parentCalendar"> 177 + #foreach ($item in $services.moccacalendar.getAllCalendars()) ## TODO: add filter here, see MOCCACAL-76 178 + #set ($itemdoc = $xwiki.getDocument($item)) 179 + #if ($!{itemdoc} && ${itemdoc.hasAccessLevel("edit")}) 180 + #set ($selected="") 181 + #if ($itemdoc.getId() == $doc.getId()) 182 + #set ($selected=" selected='selected'") 183 + #end 184 + <option value="$escapetool.html($itemdoc.getFullName())"$selected> 185 + $itemdoc.getDisplayTitle()</option> 186 + #end 187 + #end 188 + </select> 189 + #end 190 + <select id="import-calendar-parent" name="parentCalendar" hidden> 191 + <option value="$calendarDoc" selected>$calendarDoc.getDisplayTitle()</option> 192 + </select> 193 + <label for="import-ical-file-input">$escapetool.xml($services.localization.render( 194 + 'MoccaCalendar.import.modal.file.label'))</label> 195 + <input type="file" id="import-ical-file-input" accept=".ics" name="importedfile" 196 + data-max-file-size="$!escapetool.xml($xwiki.getSpacePreference('upload_maxsize'))"> 197 + </div> 198 + </form> 199 + </div> 200 + <div class="modal-footer"> 201 + <input type="button" class="btn btn-primary" id="import-calendar-file-button" 202 + value="$escapetool.xml($services.localization.render('MoccaCalendar.import.modal.button.start'))"> 203 + <input type="button" class="btn btn-default" 204 + value="$escapetool.xml($services.localization.render('cancel'))" data-dismiss="modal"> 205 + </div> 206 + </div> 207 + </div> 208 + </div> 209 +#end 210 +#macro (addCalendarObject $docRef) 211 + {{html clean=false wiki=true}} 212 + <input type="hidden" id="add-calendar-object" data-target="$docRef"> 130 130 214 + {{info}} 215 + $escapetool.xml($services.localization.render('rendering.macro.moccacalendar.addObject.description')) 216 + [[**$escapetool.xml($services.localization.render('rendering.macro.moccacalendar.addObject.button'))**>>$docRef]] 217 + {{/info}} 218 + {{/html}} 219 +#end 220 +{{/velocity}} 221 + 131 131 {{velocity}} 223 +#macro(getSubscribedCalendars) 224 + #set ($query = ", BaseObject as obj where doc.fullName = obj.name and obj.className = 'MoccaCalendar.MoccaCalendarSubscribeClass'") 225 + #set ($calendarDocumentsReferences = $services.query.hql($query).execute()) 226 + #set ($properties = []) 227 + #foreach($reference in $calendarDocumentsReferences) 228 + #set ($document = $xwiki.getDocument($reference)) 229 + #set ($class = $document.getObject('MoccaCalendar.MoccaCalendarSubscribeClass')) 230 + #if ($class.getValue('globalDisplay') == '1') 231 + #set ($discard = $properties.add({ 232 + 'iCal': $class.getValue('iCal'), 233 + 'gCal': $class.getValue('gCal'), 234 + 'gApiKey': $class.getValue('gApiKey'), 235 + 'color': $class.getValue('color'), 236 + 'textColor': $class.getValue('textColor') 237 + })) 238 + #end 239 + #end 240 +#end 241 + 242 +## Macro for handling iCal sources 243 +#macro(handleICalSources $iCalList $color $textColor) 244 + #set($iCals = $stringtool.split($iCalList, ',')) 245 + #foreach($iCal in $iCals) 246 + #set($json = $xwiki.getDocument('Calendar.ICalToJSON').getURL('get', "iCal=$escapetool.url($stringtool.strip($iCal))")) 247 + { 248 + url: "$json&outputSyntax=plain&startfield=datetime", 249 + backgroundColor: "$color", 250 + textColor: "$textColor" 251 + } 252 + #if($foreach.count < $iCals.size()) 253 + , 254 + #end 255 + #end 256 +#end 257 + 258 +## Macro for handling Google Calendar sources 259 +#macro(handleGoogleCalendarSources $gCalList $apiKey $color, $textColor) 260 + #set($googleCalendars = $stringtool.split($gCalList, ',')) 261 + #foreach($calendar in $googleCalendars) 262 + { 263 + googleCalendarId: "$stringtool.strip($calendar)", 264 + googleCalendarApiKey: "$apiKey", 265 + backgroundColor: "$color", 266 + textColor: "$textColor" 267 + } 268 + #if($foreach.count < $googleCalendars.size()) 269 + , 270 + #end 271 + #end 272 +#end 273 + 274 + 132 132 ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right 133 133 ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that 134 134 ## don't have view right on those pages. 135 135 #set ($mainReference = $services.model.createDocumentReference('', 'MoccaCalendar', 'MoccaCalendarClass')) 136 136 #if (!$services.licensing.licensor.hasLicensureForEntity($mainReference)) 137 - {{ error}}#getMissingLicenseMessage('moccacalendar.extension.name'){{/error}}280 + {{missingLicenseMessage extensionName="moccacalendar.extension.name"/}} 138 138 #else 139 -#if($xcontext.action=='view'){{html clean="false" wiki="false"}} 282 +#if($xcontext.action=='view') 283 +#set ($xwikiCalendarDoc = $xwiki.getDocument($calendarDoc)) 284 +#set ($calendarObject = $xwikiCalendarDoc.getObject('MoccaCalendar.MoccaCalendarClass')) 285 +#if ($filter == 'page' && !$calendarObject) 286 + #addCalendarObject($calendarDoc) 287 +#end 288 +{{html clean="false" wiki="false"}} 140 140 #if($canCreateEvents) 141 141 ## create event link 142 142 <div class="calendar-buttons"> 143 143 <span class="buttonwrapper"> 293 +<button data-toggle="modal" data-target="#import-calendar-file" 294 + title="$escapetool.xml($services.localization.render('MoccaCalendar.calendarevent.import.title'))"> 295 + $escapetool.html($services.localization.render('MoccaCalendar.calendarevent.import'))</button> 144 144 <button class="btn btn-success" id="calendar${calcounter}-btn"><span class="glyphicon glyphicon-plus"></span> $escapetool.html($services.localization.render('MoccaCalendar.calendarevent.create'))</button> 145 145 </span> 146 146 </div> ... ... @@ -148,7 +148,14 @@ 148 148 #end 149 149 <div id="calendar${calcounter}"></div> 150 150 <script type="text/javascript"> 151 -require(['xwiki-meta', 'jquery', 'moccaCalendar'], function(xwikiMeta, jQuery) { 303 +require.config({ 304 + paths: { 305 + purify: "$services.webjars.url('org.webjars.npm:dompurify', 'dist/purify.js')" 306 + }, 307 +}); 308 + 309 + 310 +require(['xwiki-meta', 'jquery', 'moment','purify', 'gcal', 'moccaCalendar'], function(xwikiMeta, jQuery, moment, purify) { 152 152 jQuery(document).ready(function() { 153 153 var defaultView = XWiki.MoccaCalendar.Helper.getCalendarView("$!escapetool.javascript($defaultView)"); 154 154 ... ... @@ -171,21 +171,79 @@ 171 171 172 172 // page is now ready, initialize the calendar... 173 173 var calendar = jQuery('#calendar${calcounter}').fullCalendar({ 174 - events: { 175 - url : "$!escapetool.javascript($jsonUrl)", 176 - type: 'GET', 177 - data : function() { 178 - // as we also get called before the calendar is fully initialized 179 - // we cannot get the current view reliably from the calendar itself 180 - // instead use our trusty helper 181 - return jQuery.extend(defaultEventData, {'outputView': XWiki.MoccaCalendar.Helper.getCalendarView(defaultView)} ); 182 - }, 183 - error: function() { 184 - calendarHelper.displayError(); 185 - }, 186 - traditional: true 187 - }, 333 + eventSources: [ 334 + ## Source where the xwiki events are stored. 335 + { 336 + url: "$!escapetool.javascript($jsonUrl)", 337 + type: 'GET', 338 + data: function() { 339 + // as we also get called before the calendar is fully initialized 340 + // we cannot get the current view reliably from the calendar itself 341 + // instead use our trusty helper 342 + return jQuery.extend(defaultEventData, {'outputView': XWiki.MoccaCalendar.Helper.getCalendarView(defaultView)} ); 343 + }, 344 + error: function() { 345 + calendarHelper.displayError(); 346 + }, 347 + traditional: true 348 + } 349 + ## Subscribed iCal sources 350 + #if($subscribediCal) 351 + , 352 + #handleICalSources($subscribediCal, $subscribedColor, $subscribedTextColor) 353 + #end 354 + ## Subscribed Google Calendar sources 355 + #if($!subscribedgCals != "") 356 + , 357 + #handleGoogleCalendarSources($subscribedgCals, $gApiKeySubscribed, $subscribedColor, $subscribedTextColor) 358 + #end 359 + ## Global events 360 + #if($doc.getFullName() == 'MoccaCalendar.WebHome') 361 + #getSubscribedCalendars() 362 + #foreach($property in $properties) 363 + , 364 + #handleICalSources($property['iCal'], $property['color'], $property['textColor']) 365 + , 366 + #handleGoogleCalendarSources($property['gCal'], $property['gApiKey'], $property['color'], $property['textColor']) 367 + #end 368 + #end 369 + ## In case the user uses the calendar macro directly and dosen't use the UI to create it. 370 + ## iCal sources 371 + #if($!iCal != "") 372 + , 373 + #handleICalSources($iCal 'black') 374 + #end 375 + ## Google Calendar public sources 376 + #if($!gCal != "") 377 + , 378 + #handleGoogleCalendarSources($gCal $gApiKey 'blue') 379 + #end 380 + ], 188 188 eventClick: function(calEvent, jsEvent, view) { 382 + // Prepare the read only events for the modal. 383 + if (!calEvent.viewUrl){ 384 + // The XWiki default format for date is yyyy/MM/dd, which translates into 2024/01/17. However, for some weird 385 + // reason, when using the date.format() from JavaScript, it translates into 2024/01/Mon. We need to use the 386 + // moment().toMomentFormatString(format) to get the right format. 387 + const dateFormat = moment().toMomentFormatString(calendarHelper.dateFormat); 388 + 389 + // Get the sheet URL. 390 + const sheetURL = new XWiki.Document('MoccaCalendarEventSheet', 'MoccaCalendar').getURL('get'); 391 + // Parameters for the modal content. 392 + const params = { 393 + title: purify.sanitize(calEvent.title), 394 + start: calEvent.start.format(dateFormat), 395 + end: calEvent.end ? calEvent.end.format(dateFormat) : null, 396 + allDay: calEvent.allDay ? "$escapetool.xml($services.localization.render('moccacalendar.subscribedevent.allday.yes'))" : 397 + "$escapetool.xml($services.localization.render('moccacalendar.subscribedevent.allday.no'))", 398 + description: purify.sanitize(calEvent.description), 399 + readOnly: 'true' 400 + }; 401 + const queryString = jQuery.param(params); 402 + const requestURL = `${sheetURL}?${queryString}`; 403 + calEvent.url = requestURL; 404 + calEvent.readOnly=true; 405 + } 189 189 new XWiki.MoccaCalendar.MoccaCalendarPopup({editMode: false, event: calEvent}, calendarHelper); 190 190 jsEvent.preventDefault(); 191 191 return false; ... ... @@ -254,7 +254,7 @@ 254 254 }); 255 255 jQuery('#calendar${calcounter}-btn').click( function(e) { calendarHelper.showCreateEvent(); e.preventDefault(); }); 256 256 // helper to be used in callback above 257 -#set($newPageParams = "template=MoccaCalendar.MoccaCalendarEventTemplate&parentFROM=${escapetool.url($calendarDoc)}&form_token=${services.csrf.getToken()}&ocalcaction=create") 474 +#set($newPageParams = "template=MoccaCalendar.MoccaCalendarEventTemplate&parentFROM=${escapetool.url($calendarDoc)}&form_token=${services.csrf.getToken()}&ocalcaction=create&disabled=$disableCreationEvent") 258 258 #set($randomDocUrl = $xwiki.getURL("randomPage${util.generateRandomString(10)}",'edit',$newPageParams)) 259 259 #set($updateUrlParams="?xpage=plain&outputSyntax=plain&calendarDoc=${escapetool.url(${calendarDoc})}&") 260 260 var calendarHelper = new XWiki.MoccaCalendar.Helper(calendar, ... ... @@ -273,6 +273,7 @@ 273 273 </script> 274 274 #if($calcounter == 0) 275 275 #showDeleteEventsModal 493 + #importCalendarFileModal 276 276 #end 277 277 {{/html}} 278 278 #else ## of #if($xcontext.action=='view') - Default categories
-
... ... @@ -1,0 +1,1 @@ 1 +Content - Standardkategorie
-
... ... @@ -1,1 +1,0 @@ 1 -Content
- XWiki.WikiMacroParameterClass[11]
-
- Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein - Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +gCal
- XWiki.WikiMacroParameterClass[12]
-
- Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein - Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +gApiKey
- XWiki.WikiMacroParameterClass[13]
-
- Parameter verpflichtend
-
... ... @@ -1,0 +1,1 @@ 1 +Nein - Parameter-Name
-
... ... @@ -1,0 +1,1 @@ 1 +iCal