General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
AttachmentSelector
Search
default
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Wiki Home
»
Attachments
Wiki source code of
Attachments
Last modified by
Administrator
on 2011/11/06 20:09
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{{velocity output="false"}} #if ($request.xaction == 'postUpload') #set ($targetDocument = $xwiki.getDocument($request.get('docname'))) #set ($fieldname = $request.get('fieldname')) #set ($docAction = $request.get('docAction')) #set ($attachmentList = $targetDocument.getAttachmentList()) #if ($attachmentList && $attachmentList.size() > 0) #set ($sortedAttachments = $sorttool.sort($attachmentList, 'date:desc')) #set ($lastAttachment = $sortedAttachments.get(0)) #end $response.sendRedirect($targetDocument.getURL($docAction, "$!{fieldname}=$!{lastAttachment.filename}&form_token=$!{escapetool.url($request.get('form_token'))}")) #stop #end {{/velocity}} {{velocity output="false"}} ## ## Macros ## #set ($translationPrefix = 'xe.attachmentSelector') #set ($attachmentPickerDocName = 'XWiki.AttachmentSelector') $xwiki.ssx.use($attachmentPickerDocName) $xwiki.jsx.use($attachmentPickerDocName) #** * 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. * * @param $targetDocument the document being modified * @param $options generic picker options *# #macro (attachmentPicker_displayAttachmentGallery $targetDocument, $options) #set ($currentValue = $targetDocument.getValue($options.property)) #if ("$!{targetDocument.getAttachment($currentValue)}" == '') #set ($currentValue = "$!{options.defaultValue}") #end (% class="gallery" %)((( #attachmentPicker_displayUploadForm($targetDocument, $options) #attachmentPicker_displayAttachmentGalleryEmptyValue($targetDocument, $options, $currentValue) #set ($sortedAttachments = $sorttool.sort($targetDocument.getAttachmentList(), 'date:desc') ) #foreach ($attachment in $sortedAttachments) #set ($extension = $attachment.getFilename()) #set ($extension = $extension.substring($mathtool.add($extension.lastIndexOf('.'), 1)).toLowerCase()) #if ($options.filter.size() == 0 || $options.filter.contains($extension)) #attachmentPicker_displayAttachment($attachment $targetDocument, $options $currentValue) #end #end ))) #end #** * Displays an attachment box. * * @param $attachment the target attachment to display * @param $targetDocument the document being modified * @param $options generic picker options * @param $currentValue the currently selected file, used for determining if the box should be highlighted as the current value *# #macro (attachmentPicker_displayAttachment $attachment $targetDocument, $options $currentValue) #if ($options.displayImage && $attachment.isImage()) #set ($cssClass = 'gallery_image') #else #set ($cssClass = '') #end #attachmentPicker_displayStartFrame({'value' : $attachment.filename, 'text' : $attachment.filename, 'cssClass' : "$!{cssClass}"} $targetDocument $currentValue) #attachmentPicker_displayAttachmentDetails($attachment $options) #set ($returnURL = $escapetool.url($doc.getURL('view', $request.queryString))) #set ($deleteURL = $targetDocument.getAttachmentURL($attachment.filename, 'delattachment', "xredirect=${returnURL}&form_token=$!{services.csrf.getToken()}") ) #set ($viewURL = $targetDocument.getAttachmentURL($attachment.filename) )##{'name' : 'download', 'url' : $viewURL, 'rel' : '__blank'} #set ($selectURL = $targetDocument.getURL(${options.get('docAction')}, "${options.get('classname')}_${options.get('object')}_${options.get('property')}=${attachment.filename}&form_token=$!{services.csrf.getToken()}")) #attachmentPicker_displayEndFrame ([{'name' : 'select', 'url' : $selectURL}, {'name' : 'delete', 'url' : $deleteURL}]) #end #** * Writes the wiki code used at the start of an attachment box. Outputs the attachment title bar, and opens the inner frame div. * * @param $boxOptions a map of parameters/options for the current attachment, holding, for example, the attachment name (boxOptions.value), * the title to display (boxOptions.text), optional extra CSS classnames to put on the box (boxOptions.cssClass) * @param $targetDocument the document being modified * @param $currentValue the currently selected file, used for determining if this attachment should be highlighted as the current value *# #macro (attachmentPicker_displayStartFrame $boxOptions $targetDocument $currentValue) (% class="gallery_attachmentbox $!{boxOptions.cssClass} #if ("$!{boxOptions.value}" == $currentValue) current#{end}" %)((( (% class="gallery_attachmenttitle" title="$!{boxOptions.value}" %)((($boxOptions.text))) (% class="gallery_attachmentframe" %)((( #end #** * Displays details about an attachment inside the attachment box. If the attachment is an image and the "displayImage" option is on, * then the image is displayed. Otherwise, some basic information is displayed: the version, the size, the date and the author. * * @param $attachment the target attachment to display * @param $options generic picker options *# #macro (attachmentPicker_displayAttachmentDetails $attachment $options) #if ($attachment) #if ($attachment.isImage() && $options.displayImage) #set ($attachmentDocument = $attachment.getDocument()) [[[[image:${attachmentDocument.fullName}@${attachment.filename}||width=160]]>>attach:${attachmentDocument.fullName}@${attachment.filename}||rel="lightbox[attachments]"]] #else * (% class="mime" %){{html wiki=false clean=false}}#mimetypeimg($attachment.getMimeType().toLowerCase() $attachment.getFilename().toLowerCase()){{/html}}(%%) (% class="filename" %)$attachment.getFilename()(% %) * v$attachment.getVersion() (#dynamicsize($attachment.filesize)) * $msg.get('core.viewers.attachments.author', [$!{xwiki.getUserName($attachment.author, false)}]) $msg.get('core.viewers.attachments.date', [$!{xwiki.formatDate($attachment.date, 'dd/MM/yyyy hh:mm')}]) * (% class="buttonwrapper" %)[[${msg.get("${translationPrefix}.actions.download")}>>attach:${attachment.getDocument()}@${attachment.filename}||title="$msg.get("${translationPrefix}.actions.download")" rel="__blank" class="button"]](%%) #end #end #end #** * Writes the wiki code used at the end of an attachment box. Closes the inner frame div, and outputs the attachment actions. * * @param $actions a list of maps defining action buttons, where each entry contains a subset of the following: * <dl> * <dt>name</dt> * <dd>identifies the action; the name is used as a CSS classname, and in the translation key for the display text, as "xe.attachmentSelector.actions.<name>"</dd> * <dt>url</dt> * <dd>the destination of the button</dd> * <dt>rel</dt> * <dd>an optional parameter to be used in the "rel" HTML attribute; for example "__blank" can be used to open the link in a new tab/window</dd> * </dl> *# #macro (attachmentPicker_displayEndFrame $actions) )))## attachmentframe (% class="gallery_actions" %)((( #foreach ($action in $actions) {{html}}<a href="${action.url}" class="tool ${action.name}" title="$msg.get("${translationPrefix}.actions.${action.name}")" #if($action.rel) rel="${action.rel}"#end>$msg.get("${translationPrefix}.actions.${action.name}")</a>{{/html}} ## #end )))## actions )))## attachmentbox #end #** * Displays the upload box used for adding and selecting a new attachment. * * @param $targetDocument the document being modified * @param $options generic picker options *# #macro (attachmentPicker_displayUploadForm $targetDocument, $options) #attachmentPicker_displayStartFrame({ 'value' : $msg.get("${translationPrefix}.upload.title"), 'text' : $msg.get("${translationPrefix}.upload.title"), 'cssClass' : 'gallery_upload' } $targetDocument $util.null) {{html clean="false"}} <form action="$targetDocument.getURL('upload')" enctype="multipart/form-data" method="post" id="uploadAttachment" class="uploadAttachment xform"> <div class="gallery_upload_input"> #if (${options.rawfilter} != '') <span class="xHint">$msg.get("${translationPrefix}.upload.hint", [${options.rawfilter}])</span> #end <input type="file" name="filepath" id="attachfile" class="attachment" size="30" title="$!{escapetool.xml($options.rawfilter)}"/> <input type="hidden" name="xredirect" value="$xwiki.getDocument($attachmentPickerDocName).getURL('get', "xaction=postUpload&docAction=$!{escapetool.url($options.get('docAction'))}&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()}")" /> <input type="hidden" name="docname" value="$!{escapetool.xml($targetDocument.fullName)}" /> <input type="hidden" name="classname" value="$!{escapetool.xml($options.get('classname'))}" /> <input type="hidden" name="object" value="$!{escapetool.xml($options.get('object'))}" /> <input type="hidden" name="property" value="$!{escapetool.xml($options.get('property'))}" /> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> </div> <div class="buttons"> <span class="buttonwrapper"> <input type="submit" name="action_upload" class="button " value='$msg.get("${translationPrefix}.upload.submit")' title='$msg.get("${translationPrefix}.upload.submit")'/> </span> </div> </form> {{/html}} #attachmentPicker_displayEndFrame ([]) #end #** * Displays the "empty value" box, used for unsetting the field value. * * @param $targetDocument the document being modified * @param $options generic picker options * @param $currentValue the currently selected file, used for determining if the empty box should be highlighted as the current value *# #macro (attachmentPicker_displayAttachmentGalleryEmptyValue $targetDocument, $options, $currentValue) #if ("$!{options.get('defaultValue')}" != '') #set ($reference = ${options.get('defaultValue')}) #set ($docNameLimit = $reference.indexOf('@')) #if ($docNameLimit > 0) #set ($docName = $reference.substring(0, $docNameLimit)) #else #set ($docName = $targetDocument.fullName) #end #set ($attachmentName = $reference.substring($mathtool.add($docNameLimit, 1))) #set ($defaultAttachment = $xwiki.getDocument($docName).getAttachment($attachmentName)) #if ($defaultAttachment.isImage()) #set($dcssClass = 'gallery_image') #end #end #attachmentPicker_displayStartFrame({'cssClass' : "gallery_emptyChoice $!{dcssClass}", 'text' : $msg.get("${translationPrefix}.default"), 'value' : "${options.defaultValue}"} $targetDocument $currentValue) #attachmentPicker_displayAttachmentDetails($defaultAttachment $options) #set ($returnURL = $escapetool.url($doc.getURL('view', $request.queryString))) #set ($selectURL = $targetDocument.getURL(${options.get('docAction')}, "${options.get('classname')}_${options.get('object')}_${options.get('property')}=&form_token=$!{services.csrf.getToken()}")) #attachmentPicker_displayEndFrame ([{'name' : 'select', 'url' : $selectURL}]) #end {{/velocity}} {{velocity}} #if ($request.docname) ###if ($request.xpage == 'plain') ## ## IE6 + XHR + gzip compression = BOOM! ## ## This disables the automatic gzip compression ## $response.setContentType('multipart/formdata') ###end #set ($targetDocument = $xwiki.getDocument($request.docname)) #if ("$!{request.savemode}" == 'direct') #set($docAction = 'save') #else #set($docAction = 'inline') #end #set ($filter = []) #set ($rawfilter = '') #if ("$!{request.filter}" != '') #foreach ($value in $request.filter.trim().split('\s*+[,|; ]\s*+')) #if ("$!value" != '') #set ($discard = $filter.add($value.toLowerCase())) #set ($rawfilter = "${rawfilter}, ${value}") #end #end #if ($rawfilter != '') #set ($rawfilter = $rawfilter.substring(2)) #end #end #if ("$!{request.displayImage}" == 'true') #set ($displayImage = true) #else #set ($displayImage = false) #end #set ($options = { 'classname' : ${request.get('classname')}, 'object' : ${util.parseInt($request.object)}, 'property' : ${request.property}, 'displayImage' : ${displayImage}, 'docAction' : ${docAction}, 'defaultValue' : "$!{request.defaultValue}", 'rawfilter': "$!{rawfilter}", 'filter': ${filter} }) $!targetDocument.use($targetDocument.getObject($options.classname, $options.object))## #attachmentPicker_displayAttachmentGallery($targetDocument, $options) (% class="gallery_buttons buttons" %)((( (% class="buttonwrapper secondary" %)[[$msg.get("${translationPrefix}.cancel")>>$targetDocument||class="button secondary" id="attachment-picker-close"]] ))) #end {{/velocity}}