Découvrez les nouveautés de cette version : Fonctionnalités, améliorations et évolutions vous attendent ! 👉 Cliquez ici pour en savoir plus

Modifications pour le document Confluence bridge for Attachments

Modifié par Admin le 21/07/2025 - 09:06

Depuis la version 8.1
modifié par Admin
sur 21/07/2025 - 09:06
Commentaire de modification : Install extension [com.xwiki.pro:xwiki-pro-macros-confluence-bridges-ui/1.27.1]
À la version 1.1
modifié par Admin
sur 25/06/2024 - 07:06
Commentaire de modification : Install extension [com.xwiki.pro:xwiki-pro-macros-confluence-bridges-ui/1.19.4]

Résumé

Détails

XWiki.JavaScriptExtension[0]
Code
... ... @@ -8,12 +8,6 @@
8 8  });
9 9  
10 10  require(['jquery', 'xwiki-l10n!xwiki-confluence-attachments-messages'], function($, l10n) {
11 -
12 - // Trigger Collabora integration.
13 - $(document).on('xwiki:livedata:entriesUpdated', function(){
14 - $(document).trigger('xwiki:collabora:addButtons');
15 - });
16 -
17 17   var enhanceUploadInputs = function(liveDataElems) {
18 18   $.each(liveDataElems.find('input[type=file]'), function() {
19 19   // Since the attachments liveData is refreshed on file upload, there is no need for a response container.
... ... @@ -38,8 +38,14 @@
38 38   if ($(e.target).prop('id').startsWith('confluenceAttachments')) {
39 39   // Select the livedata above the upload form.
40 40   const uploadForm = $(e.target).closest('form');
41 - let associatedLivedata = uploadForm.prevAll('.liveData').first();
42 - associatedLivedata.data('liveData').updateEntries();
35 + // The 'xwiki-livedata' CSS class is present only before XWiki version 14.4.
36 + let associatedLivedata = uploadForm.prevAll('.liveData, .xwiki-livedata').first();
37 + // We do not have access to a liveData object before XWiki 14.4.
38 + if (associatedLivedata.data('liveData') === undefined) {
39 + location.reload();
40 + } else {
41 + associatedLivedata.data('liveData').updateEntries();
42 + }
43 43   }
44 44   });
45 45  
... ... @@ -54,7 +54,8 @@
54 54   */
55 55   $(document).on('click', '.confluenceAttachmentsMacro .attachmentActions .actiondelete', function(e) {
56 56   e.preventDefault();
57 - let liveData = $(e.currentTarget).closest('.liveData');
57 + // The 'xwiki-livedata' CSS class is present only before XWiki version 14.4.
58 + let liveData = $(e.currentTarget).closest('.liveData, .xwiki-livedata');
58 58   var modal = liveData.nextAll('.deleteConfluenceAttachment');
59 59   modal.data('relatedTarget', e.currentTarget);
60 60   modal.modal('show');
... ... @@ -67,7 +67,8 @@
67 67   e.preventDefault();
68 68   var modal = $(e.currentTarget).closest('.deleteConfluenceAttachment');
69 69   var button = $(modal.data('relatedTarget'));
70 - let liveData = button.closest('.liveData');
71 + // The 'xwiki-livedata' CSS class is present only before XWiki version 14.4.
72 + let liveData = button.closest('.liveData, .xwiki-livedata');
71 71   var notification;
72 72  
73 73   $.ajax({
... ... @@ -76,8 +76,13 @@
76 76   notification = new XWiki.widgets.Notification(l10n['inProgress'], 'inprogress');
77 77   },
78 78   success : function() {
79 - liveData.data('liveData').updateEntries();
80 - notification.replace(new XWiki.widgets.Notification(l10n['done'], 'done'));
81 + // We do not have access to a liveData object before XWiki 14.4.
82 + if (liveData.data('liveData') !== undefined) {
83 + liveData.data('liveData').updateEntries();
84 + notification.replace(new XWiki.widgets.Notification(l10n['done'], 'done'));
85 + } else {
86 + location.reload();
87 + }
81 81   },
82 82   error: function() {
83 83   notification.replace(new XWiki.widgets.Notification(l10n['failed'], 'error'));
XWiki.StyleSheetExtension[0]
Code
... ... @@ -1,3 +1,15 @@
1 1  .confluenceAttachmentsMacro legend {
2 2   font-size: 1em;
3 3  }
4 + /* These should be deleted after upgrading to a XWiki parent >= 14.6. */
5 +.attachmentMimeType {
6 + color: $theme.textSecondaryColor;
7 + font-size: 32px;
8 + height: 32px;
9 + line-height: 32px;
10 + text-align: center;
11 +}
12 +.attachmentMimeType img {
13 + max-height: 32px;
14 + max-width: 48px;
15 +}
XWiki.WikiMacroClass[0]
Code de la macro
... ... @@ -100,6 +100,14 @@
100 100   #end
101 101  #end
102 102  
103 +#macro (supportsAttachJSON $supportsAttachJSON)
104 + ## The attachments.json code uses macros from attachment_macro.vm, so the existence of the attachments livedata macro
105 + ## is an indicator that the template exists and is adapted for livedata.
106 + #template('attachment_macros.vm')
107 + #set ($macroResult = "#showAttachmentsLiveData($doc 'id')")
108 + #set ($supportsAttachJSON = $macroResult.startsWith('{{liveData'))
109 +#end
110 +
103 103  ## Display a liveData with attachments from the specified document.
104 104  #macro (showConfluenceAttachmentsLiveData $attachmentsDoc $liveDataId)
105 105   #set ($liveDataConfig = {
... ... @@ -118,14 +118,35 @@
118 118   }
119 119   })
120 120  
129 + #if ("$!wikimacro.parameters.patterns" != '')
130 + #set ($liveDataConfig.query = {})
131 + #set ($liveDataConfig.query.filters = [
132 + {
133 + "property": "filename",
134 + "matchAll": true,
135 + "constraints": []
136 + }
137 + ])
138 + #set ($filters = $stringtool.split($wikimacro.parameters.patterns, ','))
139 + #foreach ($filter in $filters)
140 + #set ($discard = $liveDataConfig.query.filters[0].constraints.add(
141 + { "operator": "contains", "value": "$!filter.trim()" }
142 + ))
143 + #end
144 + #end
121 121   #set ($sourceParams = {
122 122   'translationPrefix': 'core.viewers.attachments.livetable.',
123 123   'className': 'XWiki.AllAttachments',
124 - "\$doc": "$attachmentsDoc",
125 - 'patterns': "$!wikimacro.parameters.patterns"
148 + "\$doc": "$attachmentsDoc"
126 126   })
127 - #set ($discard = $sourceParams.put('template', 'xpart.vm'))
128 - #set ($discard = $sourceParams.put('vm', 'filteredAttachments.vm'))
150 + ## Since the correct attachmentsjson.vm was added in XWiki 14.8, we use a copy of its code for backwards compatibility.
151 + #supportsAttachJSON($supportsAttachJSON)
152 + #if ($supportsAttachJSON)
153 + #set ($discard = $sourceParams.put('template', 'xpart.vm'))
154 + #set ($discard = $sourceParams.put('vm', 'attachmentsjson.vm'))
155 + #else
156 + #set ($discard = $sourceParams.put('resultPage', 'Confluence.Macros.AttachmentsJSON'))
157 + #end
129 129   #getLiveDataSort($liveDataSort)
130 130   #if ($invalidSortBy)
131 131   {{warning}}
... ... @@ -161,8 +161,8 @@
161 161   'forceSkinAction': true,
162 162   'language': $xcontext.locale
163 163   }))
164 - #set ($discard = $xwiki.jsx.use("Confluence.Macros.ConfluenceAttachments"))
165 - #set ($discard = $xwiki.ssx.use("Confluence.Macros.ConfluenceAttachments"))
193 + #set ($discard = $xwiki.jsx.use("Confluence.Macros.Attachments"))
194 + #set ($discard = $xwiki.ssx.use("Confluence.Macros.Attachments"))
166 166   #set ($document = $doc)
167 167   #if ("$!wikimacro.parameters.page" != '')
168 168   #set ($document = $xwiki.getDocument("$!wikimacro.parameters.page"))
... ... @@ -169,7 +169,7 @@
169 169   #end
170 170  
171 171   {{html clean="false" wiki="true"}}
172 - <div class='attachments confluenceAttachmentsMacro'>
201 + <div class='confluenceAttachmentsMacro'>
173 173   #showConfluenceAttachments($document)
174 174   </div>
175 175   {{/html}}
... ... @@ -181,7 +181,7 @@
181 181  ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right
182 182  ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that
183 183  ## don't have view right on those pages.
184 -#if ($services.licensing.licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference))
213 +#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))
185 185   #executeMacro
186 186  #else
187 187   {{missingLicenseMessage extensionName="proMacros.extension.name"/}}