Änderungen von Dokument Calendar Macro

Zuletzt geändert von xwikiadmin am 2025/12/11 06:30

Von Version 7.1
bearbeitet von xwikiadmin
am 2025/05/21 09:32
Änderungskommentar: Install extension [com.xwiki.mocca-calendar:application-mocca-calendar-ui/2.15.2]
Auf Version 8.1
bearbeitet von xwikiadmin
am 2025/12/03 10:04
Änderungskommentar: Install extension [com.xwiki.mocca-calendar:application-mocca-calendar-ui/2.18.0]

Zusammenfassung

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -16,8 +16,6 @@
16 16   XWiki.MoccaCalendar = {};
17 17   }
18 18  
19 -#template('colorThemeInit.vm')
20 -
21 21   XWiki.MoccaCalendar.Helper = Class.create({
22 22   initialize: function(calendar, dateFormat, jsonServiceUrl, createEventBaseUrl, updateEventUrl, newPageNameUrl, dateCheckUrl, deleteEventInstanceUrl, newPageParams, formToken) {
23 23   this.calendar = calendar;
... ... @@ -158,7 +158,6 @@
158 158   },
159 159   {
160 160   verticalPosition: "top",
161 - backgroundColor: "$theme.pageHeaderBackgroundColor",
162 162   title : this.interactionParameters.editMode ? "$escapetool.javascript($services.localization.render('MoccaCalendar.calendarevent.create'))" : "$escapetool.javascript($services.localization.render('MoccaCalendar.calendarevent.view'))",
163 163   removeOnClose : true,
164 164   onClose : function() {
... ... @@ -301,6 +301,24 @@
301 301   }
302 302   this.content.title.value = purify.sanitize(this.content.title.value)
303 303   this.content.writeAttribute('action', saveUrl + '&xpage=plain&ajax=true');
301 + let formData = new FormData(this.content);
302 + if (formData.get('MoccaCalendar.MoccaCalendarEventClass_0_allDay') == 1) {
303 + this.content.querySelectorAll('input.datetime').forEach(dateInput => {
304 + // Convert the date fields from the displayed format to the one accepted by the backend.
305 + const dateObj = moment(dateInput.value, moment().toMomentFormatString(dateInput.getAttribute('data-format')));
306 + if (dateInput.id == "MoccaCalendar.MoccaCalendarEventClass_0_endDate") {
307 + // For the end date, set the hour to 23:59 instead of 00:00.
308 + dateObj.hours(23);
309 + dateObj.minutes(59);
310 + }
311 + const calendarEventObjectDateFormat = moment().toMomentFormatString(this.helper.dateFormat);
312 + // Add a hidden element to the DOM to avoid flickering.
313 + const tempElement = dateInput.clone();
314 + tempElement.addClassName('hidden');
315 + tempElement.value = dateObj.isValid() ? dateObj.format(calendarEventObjectDateFormat) : "";
316 + dateInput.parentElement.insertBefore(tempElement, dateInput);
317 + });
318 + }
304 304   this.content.request({
305 305   onSuccess: function() {
306 306   this.saving = false;
... ... @@ -797,16 +797,7 @@
797 797   new XWiki.MoccaCalendar.MoccaCalendarPopup(calendarPopup.interactionParameters, calendarPopup.helper);
798 798   });
799 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) {
815 + $(document).on('click', '.add-calendar-object-container a', function(event) {
810 810   event.preventDefault();
811 811   const addObjectButton = $('#add-calendar-object');
812 812   const target = addObjectButton.data('target');
... ... @@ -832,24 +832,38 @@
832 832   });
833 833   });
834 834  
841 + // Trigger the upload manually when the button is clicked.
842 + $(document).on('click', '.import-calendar-file-button', function(event) {
843 + event.preventDefault();
844 + var calId = $(event.target).data('calid');
845 + var form = $(`#import-calendar-file-${calId} form`).get(0);
846 + startUploading(form, calId);
847 + });
848 +
835 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) {
850 + var startUploading = function (form, calId) {
851 + var input = form.down(`#import-ical-file-input-${calId}`);
852 + var inputFile = input.files[0];
853 + if (inputFile && inputFile.size < input.dataset.maxFileSize) {
854 + var select = form.down(`#import-calendar-parent-${calId}`);
841 841   var params = {};
842 842   params[select.name] = select.value;
843 - formData.action = form.action + "?" + $.param(params);
857 + let action = form.action + "?" + $.param(params);
844 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);
859 + var request = new XMLHttpRequest();
860 + request.open('POST', action);
861 + request.onload = function () {
862 + if (request.status === 202 || request.status === 302) {
863 + checkImportJob(select.value);
864 + } else {
865 + new XWiki.widgets.Notification(l10n.get('import.error'),'error');
866 + }
867 + };
868 + request.send(inputFile);
849 849   } else {
850 850   var notification = new XWiki.widgets.Notification(l10n.get('import.filetoolarge'), 'error');
851 851   }
852 - }
872 + };
853 853  
854 854   const checkImportJob = function(selectedCalendar) {
855 855   let documentReference = XWiki.Model.resolve('MoccaCalendar.Code.ImportJobResource', XWiki.EntityType.DOCUMENT);
... ... @@ -865,7 +865,7 @@
865 865   {name: 'form_token', value: xwikiMeta.form_token}
866 866   );
867 867   var notification = new XWiki.widgets.Notification(l10n.get('import.inprogress'), 'inprogress');
868 - $('#import-calendar-file-button').prop('disabled', true);
888 + $('.import-calendar-file-button').prop('disabled', true);
869 869   return Promise.resolve(new JobRunner({
870 870   createStatusRequest: function(jobId) {
871 871   return {
... ... @@ -889,7 +889,7 @@
889 889   notification.replace(new XWiki.widgets.Notification(l10n.get('import.error'),'error'));
890 890   return Promise.reject(reason);
891 891   }).finally(() => {
892 - $('#import-calendar-file-button').prop('disabled', false);
912 + $('.import-calendar-file-button').prop('disabled', false);
893 893   });
894 894   };
895 895  });
XWiki.StyleSheetExtension[0]
Code
... ... @@ -26,7 +26,12 @@
26 26   margin-top: 0.6em;
27 27  }
28 28  .xdialog-box-moccacal-modal-popup {
29 + background-color: @modal-content-bg;
30 + border-color: @modal-content-border-color;
29 29   width: 600px;
32 + top: 3vh !important;
33 + bottom: 3vh !important;
34 + max-height: 94vh;
30 30  }
31 31  
32 32  /* Make sure the date time picker is shown on top of the event modal. */
... ... @@ -90,13 +90,45 @@
90 90  }
91 91  
92 92  .import-form select,
93 -.import-form #import-ical-file-input {
98 +.import-form input {
94 94   width: 100%;
95 95   margin-bottom: 1.6em;
96 96   border-radius: 0.4em;
97 97  }
98 98  
99 -.import-form #import-ical-file-input {
104 +.import-form input {
100 100   padding: 0.6em 1em;
101 101   border: 1px solid #ccc;
102 102  }
108 +
109 +#recurrentDays dd {
110 + display: flex;
111 + gap: 0.3rem;
112 + margin-top: 1rem;
113 + justify-content: space-between;
114 +}
115 +
116 +#recurrentDays .xwiki-form-listclass {
117 + display: inline-flex;
118 + align-items: center;
119 + justify-content: center;
120 + padding: 0.8rem 1.1rem;
121 + background-color: @btn-default-bg;
122 + color: @btn-default-color;
123 + border-radius: 6px;
124 + cursor: pointer;
125 + user-select: none;
126 + transition: all 0.2s ease;
127 + position: relative;
128 +}
129 +
130 +#recurrentDays .xwiki-form-listclass input[type="checkbox"] {
131 + position: absolute;
132 + opacity: 0;
133 + pointer-events: none;
134 +}
135 +
136 +#recurrentDays .xwiki-form-listclass:has(input[type="checkbox"]:checked) {
137 + background-color: @btn-primary-bg;
138 + color: @btn-primary-color;
139 +}
Content Type
... ... @@ -1,1 +1,1 @@
1 -CSS
1 +LESS
Inhalt parsen
... ... @@ -1,0 +1,1 @@
1 +Nein
XWiki.WikiMacroClass[0]
Makro-Code
... ... @@ -1,4 +1,11 @@
1 1  {{velocity output="false"}}
2 +#set ($parameterMap = {})
3 +#if ($themeDoc)
4 + ## If a theme doc is found, we add the theme to the ssx requests to make sure that the cache is properly updated.
5 + ## This code can be removed when the following platform issue is fixed:
6 + ## XWIKI-18668: The changes on the color theme are not taken into account for various ss*x resources
7 + #set ($discard = $parameterMap.put('colorTheme', $themeDocFullName))
8 +#end
2 2  $xwiki.jsx.use("Calendar.FullCalendar", {'defer': false, 'minify': false})
3 3  $xwiki.jsx.use("MoccaCalendar.Code.Macro", {'defer': false, 'v' : '2.7'})
4 4  $xwiki.jsx.use("MoccaCalendar.Code.DatePickerExtension", {'defer': false})
... ... @@ -5,8 +5,8 @@
5 5  $xwiki.jsx.use("MoccaCalendar.MoccaCalendarEventSheet")
6 6  $xwiki.jsx.use("MoccaCalendar.Code.MoccaCalendarEventModificationClass")
7 7  #dateTimePicker_import()
8 -$xwiki.ssx.use("Calendar.FullCalendar")
9 -$xwiki.ssx.use("MoccaCalendar.Code.Macro")
15 +$xwiki.ssx.use("Calendar.FullCalendar", $parameterMap)
16 +$xwiki.ssx.use("MoccaCalendar.Code.Macro", $parameterMap)
10 10  #set($calcounter = $request.getAttribute('MoccaCalendar.Code.Macro:counter'))
11 11  #if(!$calcounter) #set($calcounter = 0) #else #set($calcounter = $calcounter + 1) #end
12 12  #set($discard = $request.setAttribute('MoccaCalendar.Code.Macro:counter', $calcounter))
... ... @@ -153,7 +153,7 @@
153 153  #end
154 154  
155 155  #macro(importCalendarFileModal)
156 - <div class="modal fade" id="import-calendar-file" tabindex="-1" role="dialog">
163 + <div class="modal fade" id="import-calendar-file-$calcounter" tabindex="-1" role="dialog">
157 157   <div class="modal-dialog">
158 158   <div class="modal-content">
159 159   <div class="modal-header">
... ... @@ -168,13 +168,19 @@
168 168   #set ($actionURL = "$request.getContextPath()/rest/moccacalendar/import")
169 169   #set ($xwikiCalendarDoc = $xwiki.getDocument($calendarDoc))
170 170   #set ($calendarObject = $xwikiCalendarDoc.getObject('MoccaCalendar.MoccaCalendarClass'))
171 - <form class="xform" action="$actionURL" method="post">
178 + <form class="xform" action="${actionURL}" method="post">
172 172   <div class="import-form">
173 - #if ($calendarObject || $xwikiCalendarDoc.getFullName() == 'MoccaCalendar.Events')
174 - <label for="import-calendar-parent">
180 + #set ($calendarReferences = [])
181 + #if ($filter == 'wiki')
182 + #set ($calendarReferences = $services.moccacalendar.getAllCalendars())
183 + #elseif ($filter == 'space')
184 + #set ($calendarReferences = $services.moccacalendar.getAllCalendarsInDocumentSpace($services.model.resolveDocument($calendarDoc)))
185 + #end
186 + #if ($calendarReferences.size() > 0)
187 + <label for="import-calendar-parent-${calcounter}">
175 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
189 + <select id="import-calendar-parent-${calcounter}" name="parentCalendar">
190 + #foreach ($item in $calendarReferences)
178 178   #set ($itemdoc = $xwiki.getDocument($item))
179 179   #if ($!{itemdoc} && ${itemdoc.hasAccessLevel("edit")})
180 180   #set ($selected="")
... ... @@ -181,24 +181,25 @@
181 181   #if ($itemdoc.getId() == $doc.getId())
182 182   #set ($selected=" selected='selected'")
183 183   #end
184 - <option value="$escapetool.html($itemdoc.getFullName())"$selected>
197 + <option value="$escapetool.xml($services.model.serialize($itemdoc.getDocumentReference(),'default'))"$selected>
185 185   $itemdoc.getDisplayTitle()</option>
186 186   #end
187 187   #end
188 188   </select>
202 + #else
203 + <select id="import-calendar-parent-${calcounter}" name="parentCalendar" hidden>
204 + <option value="$escapetool.xml($services.model.serialize($services.model.resolveDocument($calendarDoc),'default'))" selected></option>
205 + </select>
189 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(
207 + <label for="import-ical-file-input-${calcounter}">$escapetool.xml($services.localization.render(
194 194   'MoccaCalendar.import.modal.file.label'))</label>
195 - <input type="file" id="import-ical-file-input" accept=".ics" name="importedfile"
209 + <input type="file" id="import-ical-file-input-${calcounter}" accept=".ics" name="importedfile"
196 196   data-max-file-size="$!escapetool.xml($xwiki.getSpacePreference('upload_maxsize'))">
197 197   </div>
198 198   </form>
199 199   </div>
200 200   <div class="modal-footer">
201 - <input type="button" class="btn btn-primary" id="import-calendar-file-button"
215 + <input type="button" class="btn btn-primary import-calendar-file-button" data-calid="${calcounter}"
202 202   value="$escapetool.xml($services.localization.render('MoccaCalendar.import.modal.button.start'))">
203 203   <input type="button" class="btn btn-default"
204 204   value="$escapetool.xml($services.localization.render('cancel'))" data-dismiss="modal">
... ... @@ -211,7 +211,7 @@
211 211   {{html clean=false wiki=true}}
212 212   <input type="hidden" id="add-calendar-object" data-target="$docRef">
213 213  
214 - {{info}}
228 + {{info cssClass="add-calendar-object-container"}}
215 215   $escapetool.xml($services.localization.render('rendering.macro.moccacalendar.addObject.description'))
216 216   [[**$escapetool.xml($services.localization.render('rendering.macro.moccacalendar.addObject.button'))**>>$docRef]]
217 217   {{/info}}
... ... @@ -290,7 +290,7 @@
290 290  ## create event link
291 291  <div class="calendar-buttons">
292 292  <span class="buttonwrapper">
293 -<button data-toggle="modal" data-target="#import-calendar-file"
307 +<button data-toggle="modal" data-target="#import-calendar-file-$calcounter"
294 294   title="$escapetool.xml($services.localization.render('MoccaCalendar.calendarevent.import.title'))">
295 295   $escapetool.html($services.localization.render('MoccaCalendar.calendarevent.import'))</button>
296 296  <button class="btn btn-success" id="calendar${calcounter}-btn"><span class="glyphicon glyphicon-plus"></span> $escapetool.html($services.localization.render('MoccaCalendar.calendarevent.create'))</button>
... ... @@ -471,7 +471,7 @@
471 471   });
472 472   jQuery('#calendar${calcounter}-btn').click( function(e) { calendarHelper.showCreateEvent(); e.preventDefault(); });
473 473   // helper to be used in callback above
474 -#set($newPageParams = "template=MoccaCalendar.MoccaCalendarEventTemplate&parentFROM=${escapetool.url($calendarDoc)}&form_token=${services.csrf.getToken()}&ocalcaction=create&disabled=$disableCreationEvent")
488 +#set($newPageParams = "template=MoccaCalendar.MoccaCalendarEventTemplate&parentFROM=${escapetool.url($calendarDoc)}&calendarParentFilter=${escapetool.url($filter)}&form_token=${services.csrf.getToken()}&ocalcaction=create&disabled=$disableCreationEvent")
475 475  #set($randomDocUrl = $xwiki.getURL("randomPage${util.generateRandomString(10)}",'edit',$newPageParams))
476 476  #set($updateUrlParams="?xpage=plain&outputSyntax=plain&calendarDoc=${escapetool.url(${calendarDoc})}&")
477 477   var calendarHelper = new XWiki.MoccaCalendar.Helper(calendar,
... ... @@ -488,9 +488,9 @@
488 488   });
489 489  });
490 490  </script>
505 +#importCalendarFileModal
491 491  #if($calcounter == 0)
492 492   #showDeleteEventsModal
493 - #importCalendarFileModal
494 494  #end
495 495  {{/html}}
496 496  #else ## of #if($xcontext.action=='view')