Changes for page Attachments

Last modified by Ludovic Dubost on 2024/07/22 15:50

From version 14.1
edited by Ludovic Dubost
on 2022/04/20 17:58
Change comment: Install extension [org.xwiki.platform:xwiki-platform-attachment-ui/14.0]
To version 5.1
edited by Ludovic Dubost
on 2017/03/08 18:02
Change comment: Install extension [org.xwiki.platform:xwiki-platform-attachment-ui-9.1.1]

Summary

Details

Page properties
Content
... ... @@ -1,21 +1,17 @@
1 1  {{velocity output="false"}}
2 -#set ($translationPrefix = 'xe.attachmentSelector')
3 -
4 4  #if ($request.xaction == 'postUpload')
5 5   #set ($targetDocument = $xwiki.getDocument($request.get('docname')))
6 6   #set ($targetAttachDocument = $xwiki.getDocument($request.get('targetdocname')))
7 7  
8 8   #set ($fieldname = $request.get('fieldname'))
9 - #set ($comment = $services.localization.render("${translationPrefix}.postUpload.comment", [$fieldname]))
10 10   #set ($docAction = $request.get('docAction'))
11 11   #set ($attachmentList = $targetAttachDocument.getAttachmentList())
12 12   #if ($attachmentList && $attachmentList.size() > 0)
13 - #set ($sortedAttachments = $collectiontool.sort($attachmentList, 'date:desc'))
10 + #set ($sortedAttachments = $sorttool.sort($attachmentList, 'date:desc'))
14 14   #set ($lastAttachment = $sortedAttachments.get(0))
15 15   #end
16 16   $response.sendRedirect($targetDocument.getURL($docAction, $escapetool.url({
17 17   $fieldname: $lastAttachment.filename,
18 - 'comment': $comment,
19 19   'form_token': $request.form_token
20 20   })))
21 21   #stop
... ... @@ -26,6 +26,7 @@
26 26  ##
27 27  ## Macros
28 28  ##
25 +#set ($translationPrefix = 'xe.attachmentSelector')
29 29  #set ($attachmentPickerDocName = 'XWiki.AttachmentSelector')
30 30  
31 31  $xwiki.ssx.use($attachmentPickerDocName)
... ... @@ -49,7 +49,7 @@
49 49   #attachmentPicker_displayUploadForm($targetDocument, $targetAttachDocument, $options)
50 50   #end
51 51   #attachmentPicker_displayAttachmentGalleryEmptyValue($targetDocument, $targetAttachDocument, $options, $currentValue)
52 - #set ($sortedAttachments = $collectiontool.sort($targetAttachDocument.getAttachmentList(), "${options.sortAttachmentsBy}") )
49 + #set ($sortedAttachments = $sorttool.sort($targetAttachDocument.getAttachmentList(), "${options.sortAttachmentsBy}") )
53 53   #foreach ($attachment in $sortedAttachments)
54 54   #set ($extension = $attachment.getFilename())
55 55   #set ($extension = $extension.substring($mathtool.add($extension.lastIndexOf('.'), 1)).toLowerCase())
... ... @@ -105,19 +105,14 @@
105 105   *#
106 106  #macro (attachmentPicker_displayAttachmentDetails $attachment $options)
107 107   #if ($attachment)
108 - ## Compute the attachment reference because there's no getter.
109 - #set ($attachmentReference = $services.model.createAttachmentReference($attachment.document.documentReference,
110 - $attachment.filename))
111 - #set ($attachmentStringReference = $services.model.serialize($attachmentReference, 'default'))
112 112   #if ($attachment.isImage() && $options.displayImage)
113 - ## We add the version to the query string in order to invalidate the cache when an image attachment is replaced.
114 - #set ($queryString = $escapetool.url({'version': $attachment.version}))
115 - [[[[image:${attachmentStringReference}||width=180 queryString="$queryString"]]>>attach:$attachmentStringReference]]
106 + #set ($attachmentDocument = $attachment.getDocument())
107 +[[[[image:${attachmentDocument.fullName}@${attachment.filename}||width=180]]>>attach:${attachmentDocument.fullName}@${attachment.filename}||rel="lightbox[attachments]"]]
116 116   #else
117 117   * (% class="mime" %){{html wiki=false clean=false}}#mimetypeimg($attachment.getMimeType().toLowerCase() $attachment.getFilename().toLowerCase()){{/html}}(%%) (% class="filename" %)$attachment.getFilename()(% %)
118 118   * v$attachment.getVersion() (#dynamicsize($attachment.longSize))
119 119   * $services.localization.render('core.viewers.attachments.author', [$!{xwiki.getUserName($attachment.author, false)}]) $services.localization.render('core.viewers.attachments.date', [$!{xwiki.formatDate($attachment.date, 'dd/MM/yyyy hh:mm')}])
120 - * (% class="buttonwrapper" %)[[${services.localization.render("${translationPrefix}.actions.download")}>>attach:${attachmentStringReference}||title="$services.localization.render("${translationPrefix}.actions.download")" rel="__blank" class="button"]](%%)
112 + * (% class="buttonwrapper" %)[[${services.localization.render("${translationPrefix}.actions.download")}>>attach:${attachment.getDocument()}@${attachment.filename}||title="$services.localization.render("${translationPrefix}.actions.download")" rel="__blank" class="button"]](%%)
121 121   #end
122 122   #end
123 123  #end
... ... @@ -165,7 +165,7 @@
165 165   #if (${options.rawfilter} != '')
166 166   <span class="xHint">$escapetool.xml($services.localization.render("${translationPrefix}.upload.hint", [${options.rawfilter}]))</span>
167 167   #end
168 - <input type="file" name="filepath" id="attachfile" class="noitems" title="$!{escapetool.xml($options.rawfilter)}"/>
160 + <input type="file" name="filepath" id="attachfile" class="attachment" size="30" title="$!{escapetool.xml($options.rawfilter)}"/>
169 169   <input type="hidden" name="xredirect" value="$xwiki.getDocument($attachmentPickerDocName).getURL('get', "xaction=postUpload&amp;docAction=$!{escapetool.url($options.get('docAction'))}&amp;targetdocname=$!{escapetool.url($targetAttachDocument.fullName)}&amp;docname=$!{escapetool.url($targetDocument.fullName)}&amp;fieldname=$!{escapetool.url($options.get('classname'))}_$!{escapetool.url($options.get('object'))}_$!{escapetool.url($options.get('property'))}&amp;form_token=$!{services.csrf.getToken()}")" />
170 170   <input type="hidden" name="docname" value="$!{escapetool.xml($targetDocument.fullName)}" />
171 171   <input type="hidden" name="classname" value="$!{escapetool.xml($options.get('classname'))}" />
... ... @@ -173,27 +173,6 @@
173 173   <input type="hidden" name="property" value="$!{escapetool.xml($options.get('property'))}" />
174 174   <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
175 175   </div>
176 - #if ("$!currentValue" != '' && $currentValue != $options.defaultValue)
177 - <div>
178 - <label>
179 - <input type="checkbox" name="filename" value="$!escapetool.xml($currentValue)"
180 - />$services.localization.render('attachmentSelector.replace',
181 - ["<strong>$!escapetool.xml($currentValue)</strong>"])
182 - </label>
183 - <span class="xHint">$escapetool.xml($services.localization.render('attachmentSelector.replace.hint'))</span>
184 - </div>
185 - #end
186 - #if ($xwiki.hasEditComment() && $options.versionSummary)
187 - <div>
188 - #if ($xwiki.isEditCommentFieldHidden())
189 - <input type="hidden" name="comment" value="$!escapetool.xml($request.comment)" />
190 - #else
191 - <label for="commentinput">$services.localization.render('core.comment')</label>
192 - <input type="text" name="comment" id="commentinput" value="$!escapetool.xml($request.comment)"
193 - title="$services.localization.render('core.comment.tooltip')" />
194 - #end
195 - </div>
196 - #end
197 197   <div class="buttons">
198 198   <span class="buttonwrapper">
199 199   <input type="submit" name="action_upload" class="button " value='$services.localization.render("${translationPrefix}.upload.submit")' title='$services.localization.render("${translationPrefix}.upload.submit")'/>
... ... @@ -285,7 +285,7 @@
285 285   #end
286 286   #set ($options = {
287 287   'classname' : ${request.get('classname')},
288 - 'object' : $!{numbertool.toNumber($request.object).intValue()},
259 + 'object' : $!{mathtool.toInteger($request.object)},
289 289   'property' : ${request.property},
290 290   'displayImage' : ${displayImage},
291 291   'docAction' : ${docAction},
... ... @@ -292,14 +292,13 @@
292 292   'defaultValue' : "$!{request.defaultValue}",
293 293   'rawfilter': "$!{rawfilter}",
294 294   'filter': ${filter},
295 - 'sortAttachmentsBy': ${sortAttachmentsBy},
296 - 'versionSummary': $request.versionSummary.equals('true')
266 + 'sortAttachmentsBy': ${sortAttachmentsBy}
297 297   })
298 298   $!targetDocument.use($targetDocument.getObject($options.classname, $options.object))##
299 299   #attachmentPicker_displayAttachmentGallery($targetDocument, $targetAttachDocument, $options)
300 300  
301 301   (% class="gallery_buttons buttons" %)(((
302 - (% class="buttonwrapper secondary" %)[[$services.localization.render("${translationPrefix}.cancel")>>${targetDocument}||class="button secondary" id="attachment-picker-close"]]
272 + (% class="buttonwrapper secondary" %)[[$services.localization.render("${translationPrefix}.cancel")>>$targetDocument||class="button secondary" id="attachment-picker-close"]]
303 303   )))
304 304  #end
305 305  {{/velocity}}
XWiki.JavaScriptExtension[0]
Code
... ... @@ -40,7 +40,7 @@
40 40   * and saves the underlying form (if any) so that any unsaved changes won't be lost.
41 41   */
42 42   filterFormUpload : function() {
43 - this.gallery.select('.uploadAttachment input[type="file"]').each(function(fileInput) {
43 + this.gallery.select('.uploadAttachment input.attachment').each(function(fileInput) {
44 44   fileInput.__allowedExtensions = fileInput.title.toLowerCase().replace(/\s*[,|; ]\s*/g, " ").strip();
45 45   if (fileInput.__allowedExtensions != '') {
46 46   fileInput.__allowedExtensions = fileInput.__allowedExtensions.split(" ");
... ... @@ -52,7 +52,7 @@
52 52   event.stop();
53 53   var uploadForm = event.element();
54 54   var hasErrors = false;
55 - uploadForm.select('input[type="file"]').each(function(fileInput) {
55 + uploadForm.select('input.attachment').each(function(fileInput) {
56 56   if (fileInput.value == '') {
57 57   new XWiki.widgets.Notification("$services.localization.render('xe.attachmentSelector.upload.error.noFile')", 'error');
58 58   hasErrors = true;
... ... @@ -68,7 +68,7 @@
68 68   uploadForm.submit();
69 69   } else {
70 70   // FIXME This fails in HTML5, will deal with it later:
71 - // this.property.down('input').value = uploadForm.down('input[type="file"]').value;
71 + // this.property.down('input').value = uploadForm.down('.attachment').value;
72 72   // uploadForm.xredirect.value = window.location.pathname;
73 73   document.observe('xwiki:document:saved', function() {
74 74   new XWiki.widgets.Notification("$services.localization.render('xe.attachmentSelector.upload.inProgress')", 'inprogress');
... ... @@ -117,11 +117,6 @@
117 117   if (this.gallery.down('.gallery_emptyChoice')) {
118 118   this.gallery.down('.gallery_emptyChoice').addClassName('current');
119 119   }
120 - // Disable the replace feature because there's no selection.
121 - var fileNameInput = this.gallery.down('input[type="checkbox"][name="filename"]');
122 - fileNameInput.disabled = true;
123 - // Empty the displayed selected file name.
124 - fileNameInput.up('label').down('strong').update('');
125 125   if (!this.directSave) {
126 126   this.property.down('input').value = this.defaultValue;
127 127   }
... ... @@ -173,7 +173,10 @@
173 173   this.dialog.closeDialog();
174 174   }.bindAsEventListener(this),
175 175   onFailure : function(response) {
176 - var failureReason = response.statusText || 'Server not responding';
171 + var failureReason = response.statusText;
172 + if (response.statusText == '' /* No response */ || response.status == 12031 /* In IE */) {
173 + failureReason = 'Server not responding';
174 + }
177 177   if (targetElement._x_notif) {
178 178   targetElement._x_notif.replace(new XWiki.widgets.Notification("$services.localization.render('core.widgets.confirmationBox.notification.failed')" + failureReason, "error"));
179 179   } else {
... ... @@ -180,6 +180,9 @@
180 180   new XWiki.widgets.Notification(this.interactionParameters.failureMessageText + failureReason, "error");
181 181   }
182 182   },
181 + on1223 : function(response) {
182 + response.request.options.onSuccess(response);
183 + },
183 183   on0 : function(response) {
184 184   response.request.options.onFailure(response);
185 185   },
XWiki.StyleSheetExtension[0]
Code
... ... @@ -140,6 +140,9 @@
140 140   ## Make this box twice as large as the others
141 141   width: ${uploadBoxSize}px;
142 142  }
143 +* html .gallery_upload {
144 + width: ${mathtool.add($uploadBoxSize, 2)}px;
145 +}
143 143  .gallery_upload, .gallery_upload:hover {
144 144   background-color: $theme.backgroundSecondaryColor;
145 145  }
... ... @@ -150,29 +150,24 @@
150 150   background-repeat: no-repeat;
151 151   padding-left: 16px;
152 152  }
153 -.gallery_upload .gallery_attachmentframe {
154 - height: auto;
156 +.gallery_upload form {
157 + height: ${imgSize}px;
155 155  }
156 -.gallery_upload_input {
157 - margin-bottom: 10px;
159 +.gallery_upload .xHint {
160 + text-transform: none !important;
158 158  }
159 -.gallery_upload input[type="file"] {
160 - font-size: 86%;
162 +.gallery_upload input.attachment {
163 + font-size: 83.3%;
164 + margin: 0; /* Overrides viewers/attachments.css */
165 + padding: 0; /* Overrides viewers/attachments.css */
161 161   width: ${mathtool.sub($uploadBoxSize, $mathtool.mul($boxPadding, 2))}px;
162 162  }
163 163  .gallery_upload .buttonwrapper {
164 164   margin: 0;
165 165  }
166 -.gallery_upload .button,
167 -.gallery_upload label {
168 - font-size: 86%;
171 +.gallery_upload .button {
172 + font-size: .65em;
169 169  }
170 -.gallery_upload input[type="checkbox"] {
171 - vertical-align: text-bottom;
172 -}
173 -.gallery_upload label[for="commentinput"] {
174 - margin-top: 10px;
175 -}
176 176  
177 177  /* ------------------------------------ */
178 178  /* Buttons on top: */
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -3,6 +3,7 @@
3 3  $xwiki.ssfx.use('js/xwiki/widgets/modalPopup.css', true)##
4 4  $xwiki.jsx.use($xcontext.macro.doc.fullName)##
5 5  $xwiki.ssx.use($xcontext.macro.doc.fullName)##
6 +$xwiki.jsfx.use('js/scriptaculous/builder.js')##
6 6  ## Integrates the optional Lightbox widget (from http://extensions.xwiki.org/xwiki/bin/view/Extension/Lightbox+Application )
7 7  #if ($xwiki.exists('XWiki.Lightbox'))
8 8   $xwiki.jsx.use('XWiki.Lightbox')
... ... @@ -31,7 +31,7 @@
31 31  #end
32 32  #set ($classname = "$!{xcontext.macro.params.classname}")
33 33  #set ($property = "$!{xcontext.macro.params.property}")
34 -#set ($object = $numbertool.toNumber("$!{xcontext.macro.params.object}").intValue())
35 +#set ($object = $mathtool.toInteger("$!{xcontext.macro.params.object}"))
35 35  #if ("$!{object}" != $!{xcontext.macro.params.object})
36 36   #set ($object = ${doc.getObject($classname).number})
37 37   #if ("$!{object}" == '')
... ... @@ -122,24 +122,7 @@
122 122  ## 1. Edit the current page
123 123  ## 2. View the target attachment page. (can be the same page)
124 124  #macro (attachmentPicker_displayButton)
125 - #if ($hasEdit && $targetPermView)
126 - #set ($queryString = {
127 - 'docname': $doc.fullName,
128 - 'classname': $classname,
129 - 'property': $property,
130 - 'object': $object,
131 - 'savemode': $savemode,
132 - 'defaultValue': $defaultValue,
133 - 'filter': $filter,
134 - 'displayImage': $displayImage,
135 - 'versionSummary': $xcontext.macro.params.versionSummary.equals('true')
136 - })
137 - #if ($hasTargetDoc)
138 - #set ($queryString.targetdocname = $targetdoc.fullName)
139 - #end
140 - (% class="buttonwrapper" %)[[$buttontext>>${xcontext.macro.doc.fullName}||queryString="$escapetool.url($queryString)"
141 - class="attachment-picker-start button" title="$buttontext"]](%%)##
142 - #end
126 + #if ($hasEdit && $targetPermView)(% class="buttonwrapper" %)[[${buttontext}>>${xcontext.macro.doc.fullName}||queryString="#if ($hasTargetDoc)targetdocname=${escapetool.url($targetdoc.fullName)}&#{end}docname=${escapetool.url($doc.fullName)}&classname=${classname}&property=${property}&object=${object}&savemode=${savemode}&defaultValue=$escapetool.url($defaultValue)&filter=$!{filter}&displayImage=${displayImage}" class="attachment-picker-start button" title="${buttontext}"]](%%)#end
143 143  #end
144 144  {{/velocity}}
145 145  
Default category
... ... @@ -1,1 +1,0 @@
1 -Development
Cached
... ... @@ -1,1 +1,0 @@
1 -No
Asynchronous rendering
... ... @@ -1,1 +1,0 @@
1 -No
XWiki.WikiMacroParameterClass[0]
Parameter type
... ... @@ -1,1 +1,0 @@
1 -org.xwiki.model.reference.DocumentReference
XWiki.WikiMacroParameterClass[10]
Parameter type
... ... @@ -1,1 +1,0 @@
1 -org.xwiki.model.reference.AttachmentReference
XWiki.WikiMacroParameterClass[18]
Parameter type
... ... @@ -1,1 +1,0 @@
1 -org.xwiki.model.reference.DocumentReference
XWiki.WikiMacroParameterClass[19]
Parameter default value
... ... @@ -1,1 +1,0 @@
1 -false
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Whether to allow the user to enter a version summary that will be recorded in the history. An automatic message is used when no version summary is provided or if the version summary input is not displayed.
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No
Parameter name
... ... @@ -1,1 +1,0 @@
1 -versionSummary