Änderungen von Dokument Calendar Macro

Zuletzt geändert von xwikiadmin am 2025/12/03 10:04

Von Version 5.1
bearbeitet von xwikiadmin
am 2025/01/07 11:32
Änderungskommentar: Install extension [com.xwiki.mocca-calendar:application-mocca-calendar-ui/2.15]
Auf 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]

Zusammenfassung

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -746,13 +746,14 @@
746 746  
747 747  });
748 748  
749 -define('mocca-calendar-import-notification', {
750 - prefix: 'MoccaCalendar.import.notification.',
749 +define('mocca-calendar-notification', {
750 + prefix: 'MoccaCalendar.notification.',
751 751   keys: [
752 - 'inprogress',
753 - 'done',
754 - 'error',
755 - 'filetoolarge'
752 + 'import.inprogress',
753 + 'import.done',
754 + 'import.error',
755 + 'import.filetoolarge',
756 + 'addObject.error'
756 756   ]
757 757  });
758 758  
... ... @@ -759,7 +759,7 @@
759 759  /**
760 760   * Delete event and calendar import actions.
761 761   */
762 -require(['jquery', 'xwiki-meta', 'xwiki-job-runner', 'xwiki-l10n!mocca-calendar-import-notification'],
763 +require(['jquery', 'xwiki-meta', 'xwiki-job-runner', 'xwiki-l10n!mocca-calendar-notification'],
763 763   function($, xwikiMeta, JobRunner, l10n) {
764 764   /**
765 765   * Events triggered before deleteEvents modal is shown: save the button that triggers
... ... @@ -805,6 +805,32 @@
805 805   startUploading(form);
806 806   });
807 807  
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 +
808 808   // Start uploading this file by creating a new XHR object with the file data.
809 809   var startUploading = function (form) {
810 810   var formData = new FormData(form);
... ... @@ -820,7 +820,7 @@
820 820   request.send(formData);
821 821   checkImportJob(select.value);
822 822   } else {
823 - var notification = new XWiki.widgets.Notification(l10n.get('filetoolarge'), 'error');
850 + var notification = new XWiki.widgets.Notification(l10n.get('import.filetoolarge'), 'error');
824 824   }
825 825   }
826 826  
... ... @@ -837,7 +837,7 @@
837 837   {name: 'data', value: 'jobStatus'},
838 838   {name: 'form_token', value: xwikiMeta.form_token}
839 839   );
840 - var notification = new XWiki.widgets.Notification(l10n.get('inprogress'), 'inprogress');
867 + var notification = new XWiki.widgets.Notification(l10n.get('import.inprogress'), 'inprogress');
841 841   $('#import-calendar-file-button').prop('disabled', true);
842 842   return Promise.resolve(new JobRunner({
843 843   createStatusRequest: function(jobId) {
... ... @@ -856,10 +856,10 @@
856 856   throw new Error(response.error.message);
857 857   } else {
858 858   document.dispatchEvent(new Event('calendarImportCompleted'));
859 - notification.replace(new XWiki.widgets.Notification(l10n.get('done'),'done'));
886 + notification.replace(new XWiki.widgets.Notification(l10n.get('import.done'),'done'));
860 860   }
861 861   }).catch((reason) => {
862 - notification.replace(new XWiki.widgets.Notification(l10n.get('error'),'error'));
889 + notification.replace(new XWiki.widgets.Notification(l10n.get('import.error'),'error'));
863 863   return Promise.reject(reason);
864 864   }).finally(() => {
865 865   $('#import-calendar-file-button').prop('disabled', false);
XWiki.WikiMacroClass[0]
Makro-Code
... ... @@ -166,22 +166,29 @@
166 166   #set ($escapedCalendarSpace = $escapetool.xml($doc.getSpace()))
167 167   #set ($escapedCalendarName = $escapetool.xml($doc.getDocumentReference().getName()))
168 168   #set ($actionURL = "$request.getContextPath()/rest/moccacalendar/import")
169 + #set ($xwikiCalendarDoc = $xwiki.getDocument($calendarDoc))
170 + #set ($calendarObject = $xwikiCalendarDoc.getObject('MoccaCalendar.MoccaCalendarClass'))
169 169   <form class="xform" action="$actionURL" method="post">
170 170   <div class="import-form">
171 - <label for="import-calendar-parent">
172 - $escapetool.xml($services.localization.render('MoccaCalendar.calendar'))</label>
173 - <select id="import-calendar-parent" name="parentCalendar">
174 - #foreach ($item in $services.moccacalendar.getAllCalendars()) ## TODO: add filter here, see MOCCACAL-76
175 - #set ($itemdoc = $xwiki.getDocument($item))
176 - #if ($!{itemdoc} && ${itemdoc.hasAccessLevel("edit")})
177 - #set ($selected="")
178 - #if ($itemdoc.getId() == $doc.getId())
179 - #set ($selected=" selected='selected'")
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>
180 180   #end
181 - <option value="$escapetool.html($itemdoc.getFullName())"$selected>
182 - $itemdoc.getDisplayTitle()</option>
183 183   #end
184 - #end
188 + </select>
189 + #end
190 + <select id="import-calendar-parent" name="parentCalendar" hidden>
191 + <option value="$calendarDoc" selected>$calendarDoc.getDisplayTitle()</option>
185 185   </select>
186 186   <label for="import-ical-file-input">$escapetool.xml($services.localization.render(
187 187   'MoccaCalendar.import.modal.file.label'))</label>
... ... @@ -200,6 +200,16 @@
200 200   </div>
201 201   </div>
202 202  #end
210 +#macro (addCalendarObject $docRef)
211 + {{html clean=false wiki=true}}
212 + <input type="hidden" id="add-calendar-object" data-target="$docRef">
213 +
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
203 203  {{/velocity}}
204 204  
205 205  {{velocity}}
... ... @@ -262,7 +262,13 @@
262 262  #if (!$services.licensing.licensor.hasLicensureForEntity($mainReference))
263 263   {{missingLicenseMessage extensionName="moccacalendar.extension.name"/}}
264 264  #else
265 -#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"}}
266 266  #if($canCreateEvents)
267 267  ## create event link
268 268  <div class="calendar-buttons">