|
1.1 |
1 |
{{velocity output="false"}} |
|
|
2 |
#set ($translationPrefix = 'xe.attachmentSelector') |
|
|
3 |
|
|
|
4 |
#if ($request.xaction == 'postUpload') |
|
|
5 |
#set ($targetDocument = $xwiki.getDocument($request.get('docname'))) |
|
|
6 |
#set ($targetAttachDocument = $xwiki.getDocument($request.get('targetdocname'))) |
|
|
7 |
|
|
|
8 |
#set ($fieldname = $request.get('fieldname')) |
|
|
9 |
#set ($comment = $services.localization.render("${translationPrefix}.postUpload.comment", [$fieldname])) |
|
|
10 |
#set ($docAction = $request.get('docAction')) |
|
|
11 |
#set ($attachmentList = $targetAttachDocument.getAttachmentList()) |
|
|
12 |
#if ($attachmentList && $attachmentList.size() > 0) |
|
|
13 |
#set ($sortedAttachments = $collectiontool.sort($attachmentList, 'date:desc')) |
|
|
14 |
#set ($lastAttachment = $sortedAttachments.get(0)) |
|
|
15 |
#end |
|
|
16 |
$response.sendRedirect($targetDocument.getURL($docAction, $escapetool.url({ |
|
|
17 |
$fieldname: $lastAttachment.filename, |
|
|
18 |
'comment': $comment, |
|
|
19 |
'form_token': $request.form_token |
|
|
20 |
}))) |
|
|
21 |
#stop |
|
|
22 |
#end |
|
|
23 |
{{/velocity}} |
|
|
24 |
|
|
|
25 |
{{velocity output="false"}} |
|
|
26 |
## |
|
|
27 |
## Macros |
|
|
28 |
## |
|
|
29 |
#set ($attachmentPickerDocName = 'XWiki.AttachmentSelector') |
|
|
30 |
|
|
|
31 |
$xwiki.ssx.use($attachmentPickerDocName) |
|
|
32 |
$xwiki.jsx.use($attachmentPickerDocName) |
|
|
33 |
|
|
|
34 |
#** |
|
|
35 |
* Displays the attachment gallery as a list of attachment boxes, starting with special boxes for uploading a new attachment and for setting a default value. |
|
|
36 |
* |
|
|
37 |
* @param $targetDocument the document to recieve the field value being modified |
|
|
38 |
* @param $targetAttachDocument the document to list/save attachments to |
|
|
39 |
* @param $options generic picker options |
|
|
40 |
*# |
|
|
41 |
#macro (attachmentPicker_displayAttachmentGallery $targetDocument, $targetAttachDocument, $options) |
|
|
42 |
#set ($currentValue = $targetDocument.getValue($options.property)) |
|
|
43 |
#if ("$!{targetAttachDocument.getAttachment($currentValue)}" == '') |
|
|
44 |
#set ($currentValue = "$!{options.defaultValue}") |
|
|
45 |
#end |
|
|
46 |
(% class="gallery" %)((( |
|
|
47 |
## Only display the upload form if they have edit permission on targetAttachDocument |
|
1.1 |
180 |
)))## actions |
|
|
181 |
)))## attachmentbox |
|
|
182 |
#end |
|
|
183 |
|
|
|
184 |
#** |
|
|
185 |
* Displays the upload box used for adding and selecting a new attachment. |
|
|
186 |
* |
|
|
187 |
* @param $targetDocument the document with the property being modified |
|
|
188 |
* @param $targetAttachDocument the document to upload the attachment to |
|
|
189 |
* @param $options generic picker options |
|
|
190 |
*# |
|
|
191 |
#macro (attachmentPicker_displayUploadForm $targetDocument, $targetAttachDocument, $options) |
|
|
192 |
#attachmentPicker_displayStartFrame({ |
|
|
193 |
'value' : $services.localization.render("${translationPrefix}.upload.title"), |
|
|
194 |
'text' : $services.localization.render("${translationPrefix}.upload.title"), |
|
|
195 |
'cssClass' : 'gallery_upload' |
|
|
196 |
} $NULL) |
|
|
197 |
{{html clean="false"}} |
|
|
198 |
<form action="$targetAttachDocument.getURL('upload')" enctype="multipart/form-data" method="post" id="uploadAttachment" class="uploadAttachment xform"> |
|
|
199 |
<div class="gallery_upload_input"> |
|
|
200 |
#if (${options.rawfilter} != '') |
|
|
201 |
<span class="xHint">$escapetool.xml($services.localization.render("${translationPrefix}.upload.hint", [${options.rawfilter}]))</span> |
|
|
202 |
#end |
|
|
203 |
<input type="file" name="filepath" id="attachfile" class="noitems" title="$!{escapetool.xml($options.rawfilter)}"/> |
|
|
204 |
<input type="hidden" name="xredirect" value="$xwiki.getDocument($attachmentPickerDocName).getURL('get', "xaction=postUpload&docAction=$!{escapetool.url($options.get('docAction'))}&targetdocname=$!{escapetool.url($targetAttachDocument.fullName)}&docname=$!{escapetool.url($targetDocument.fullName)}&fieldname=$!{escapetool.url($options.get('classname'))}_$!{escapetool.url($options.get('object'))}_$!{escapetool.url($options.get('property'))}&form_token=$!{services.csrf.getToken()}")" /> |
|
|
205 |
<input type="hidden" name="docname" value="$!{escapetool.xml($targetDocument.fullName)}" /> |
|
|
206 |
<input type="hidden" name="classname" value="$!{escapetool.xml($options.get('classname'))}" /> |
|
|
207 |
<input type="hidden" name="object" value="$!{escapetool.xml($options.get('object'))}" /> |
|
|
208 |
<input type="hidden" name="property" value="$!{escapetool.xml($options.get('property'))}" /> |
|
|
209 |
<input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> |
|
|
210 |
</div> |
|
|
211 |
#if ("$!currentValue" != '' && $currentValue != $options.defaultValue) |
|
|
212 |
<div> |
|
|
213 |
<label> |
|
|
214 |
<input type="checkbox" name="filename" value="$!escapetool.xml($currentValue)" |
|
|
215 |
/>$services.localization.render('attachmentSelector.replace', |
|
|
216 |
["<strong>$!escapetool.xml($currentValue)</strong>"]) |
|
|
217 |
</label> |
|
|
218 |
<span class="xHint">$escapetool.xml($services.localization.render('attachmentSelector.replace.hint'))</span> |
|
|
219 |
</div> |
|
|
220 |
#end |
|
|
221 |
#if ($xwiki.hasEditComment() && $options.versionSummary) |
|
|
222 |
<div> |
|
|
223 |
#if ($xwiki.isEditCommentFieldHidden()) |
|
|
224 |
<input type="hidden" name="comment" value="$!escapetool.xml($request.comment)" /> |
|
|
225 |
#else |
|
|
226 |
<label for="commentinput">$services.localization.render('core.comment')</label> |
|
|
227 |
<input type="text" name="comment" id="commentinput" value="$!escapetool.xml($request.comment)" |
|
|
228 |
title="$services.localization.render('core.comment.tooltip')" /> |
|
|
229 |
#end |
|
|
230 |
</div> |
|
|
231 |
#end |
|
|
232 |
<div class="buttons"> |
|
|
233 |
<span class="buttonwrapper"> |
|
|
234 |
<input type="submit" name="action_upload" class="button " value='$services.localization.render("${translationPrefix}.upload.submit")' title='$services.localization.render("${translationPrefix}.upload.submit")'/> |
|
|
235 |
</span> |
|
|
236 |
</div> |
|
|
237 |
</form> |
|
|
238 |
{{/html}} |
|
|
239 |
#attachmentPicker_displayEndFrame ([]) |
|
|
240 |
#end |
|
|
241 |
|
|
|
242 |
#** |
|
|
243 |
* Displays the "empty value" box, used for unsetting the field value. |
|
|
244 |
* |
|
|
245 |
* @param $targetDocument the document being modified |
|
|
246 |
* @param $targetAttachDocument the document that the attachments will the loaded from/saved to |
|
|
247 |
* @param $options generic picker options |
|
|
248 |
* @param $currentValue the currently selected file, used for determining if the empty box should be highlighted as the current value |
|
|
249 |
*# |
|
|
250 |
#macro (attachmentPicker_displayAttachmentGalleryEmptyValue $targetDocument, $targetAttachDocument, $options, $currentValue) |
|
|
251 |
#if ("$!{options.get('defaultValue')}" != '') |
|
|
252 |
#set ($reference = ${options.get('defaultValue')}) |
|
|
253 |
#set ($docNameLimit = $reference.indexOf('@')) |
|
|
254 |
#if ($docNameLimit > 0) |
|
|
255 |
#set ($docName = $reference.substring(0, $docNameLimit)) |
|
|
256 |
#else |
|
|
257 |
#set ($docName = $targetAttachDocument.fullName) |
|
|
258 |
#end |
|
|
259 |
#set ($attachmentName = $reference.substring($mathtool.add($docNameLimit, 1))) |
|
|
260 |
#set ($defaultAttachment = $xwiki.getDocument($docName).getAttachment($attachmentName)) |
|
|
261 |
#if ($defaultAttachment.isImage()) |
|
|
262 |
#set($dcssClass = 'gallery_image') |
|
|
263 |
#end |
|
|
264 |
#end |
|
|
265 |
#attachmentPicker_displayStartFrame({'cssClass' : "gallery_emptyChoice $!{dcssClass}", 'text' : $services.localization.render("${translationPrefix}.default"), 'value' : "${options.defaultValue}"} $currentValue) |
|
|
266 |
#attachmentPicker_displayAttachmentDetails($defaultAttachment $options) |
|
|
267 |
#set ($returnURL = $escapetool.url($doc.getURL('view', $request.queryString))) |
|
|
268 |
#set ($selectURL = $targetDocument.getURL(${options.get('docAction')}, "${options.get('classname')}_${options.get('object')}_${options.get('property')}=&form_token=$!{services.csrf.getToken()}")) |
|
|
269 |
#attachmentPicker_displayEndFrame ([{'name' : 'select', 'url' : $selectURL}]) |
|
|
270 |
#end |
|
|
271 |
{{/velocity}} |
|
|
272 |
|
|
|
273 |
{{velocity}} |
|
|
274 |
#if ($request.docname) |
|
|
275 |
#set ($targetDocument = $xwiki.getDocument($request.docname)) |
|
|
276 |
#if ($request.targetdocname) |
|
|
277 |
## Use the target document if it exists. |
|
|
278 |
#set ($targetAttachDocument = $xwiki.getDocument($request.targetdocname)) |
|
|
279 |
#else |
|
|
280 |
## Otherwise, just use the current document as the target to save/load attachments |
|
|
281 |
#set ($targetAttachDocument = $targetDocument) |
|
|
282 |
#end |
|
|
283 |
#if ("$!{request.savemode}" == 'direct') |
|
|
284 |
#set($docAction = 'save') |
|
|
285 |
#else |
|
|
286 |
#set($docAction = $targetAttachDocument.getDefaultEditMode()) |
|
|
287 |
#end |
|
|
288 |
#set ($filter = []) |
|
|
289 |
#set ($rawfilter = '') |
|
|
290 |
#if ("$!{request.filter}" != '') |
|
|
291 |
#foreach ($value in $request.filter.trim().split('\s*+[,|; ]\s*+')) |
|
|
292 |
#if ("$!value" != '') |
|
|
293 |
#set ($discard = $filter.add($value.toLowerCase())) |
|
|
294 |
#set ($rawfilter = "${rawfilter}, ${value}") |
|
|
295 |
#end |
|
|
296 |
#end |
|
|
297 |
#if ($rawfilter != '') |
|
|
298 |
#set ($rawfilter = $rawfilter.substring(2)) |
|
|
299 |
#end |
|
|
300 |
#end |
|
|
301 |
#if ("$!{request.displayImage}" == 'true') |
|
|
302 |
#set ($displayImage = true) |
|
|
303 |
#else |
|
|
304 |
#set ($displayImage = false) |
|
|
305 |
#end |
|
|
306 |
### Determine attachment sorting |
|
|
307 |
#set($sortAttachmentsBy = "$!{request.sortAttachmentsBy}") |
|
|
308 |
#set ($validAttachmentProperties = ['filename', 'date', 'filesize', 'author', 'version', 'mimeType']) |
|
|
309 |
#if($sortAttachmentsBy == '' || $validAttachmentProperties.indexOf($sortAttachmentsBy) == -1) |
|
|
310 |
### Default to sorting by filename, sort not requested. |
|
|
311 |
#set($sortAttachmentsBy = "filename") |
|
|
312 |
#end |
|
|
313 |
### Set attachment sorting direction |
|
|
314 |
#if($sortAttachmentsBy == 'date') |
|
|
315 |
### Sort the date descending |
|
|
316 |
#set($sortAttachmentsBy = "date:desc") |
|
|
317 |
#else |
|
|
318 |
### Sort everything else ascending |
|
|
319 |
#set($sortAttachmentsBy = "${sortAttachmentsBy}:asc") |
|
|
320 |
#end |
|
|
321 |
#set ($options = { |
|
|
322 |
'classname' : ${request.get('classname')}, |
|
|
323 |
'object' : $!{numbertool.toNumber($request.object).intValue()}, |
|
|
324 |
'property' : ${request.property}, |
|
|
325 |
'displayImage' : ${displayImage}, |
|
|
326 |
'docAction' : ${docAction}, |
|
|
327 |
'defaultValue' : "$!{request.defaultValue}", |
|
|
328 |
'rawfilter': "$!{rawfilter}", |
|
|
329 |
'filter': ${filter}, |
|
|
330 |
'sortAttachmentsBy': ${sortAttachmentsBy}, |
|
|
331 |
'versionSummary': $request.versionSummary.equals('true') |
|
|
332 |
}) |
|
|
333 |
$!targetDocument.use($targetDocument.getObject($options.classname, $options.object))## |
|
|
334 |
#attachmentPicker_displayAttachmentGallery($targetDocument, $targetAttachDocument, $options) |
|
|
335 |
|