General Actions:
Log-in
Wiki:
L3D's Wiki
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
AllAttachmentsResults
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Welcome to your wiki
»
Documents on this Wiki
»
Attachments
»
Attachments JSON Service
Wiki source code of
Attachments JSON Service
Last modified by
Administrator
on 2011/03/02 17:34
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{{velocity}} ## ============================================================================================ ## This page is called from live grids via Ajax with the argument xpage=plain. It returns a ## set of results serialized in JSON. ## @programming This service page needs to be saved by a user with the programming access level ## to work as expected ## ============================================================================================ #if ("$!request.get('xpage')" == 'plain') #set ($offset = $util.parseInt($request.get('offset'))) ## offset starts from 0 in velocity and 1 in javascript #set ($off = $offset - 1) #set ($limit = $util.parseInt($request.get('limit'))) #set ($title = $request.get('doc.name')) #set ($author = $request.get('doc.author')) #set ($space = $request.get('doc.space')) #set ($filename = $request.filename) #set ($formatDate = 'yyyy MMMM dd, HH:mm') #set ($query = '') #set ($queryParameters = []) #if ($title) #set ($title = $title.trim().toLowerCase()) #set ($query = $query + " and lower(doc.name) like ?") #set ($discard = $queryParameters.add("%${title}%")) #end #if ($author) #set ($author = $author.trim().toLowerCase()) #set ($query = $query + " and lower(attach.author) like ?") #set ($discard = $queryParameters.add("%${author}%")) #end #if ($filename) #set ($filename = $filename.trim().toLowerCase()) #set ($query = $query + " and lower(attach.filename) like ?") #set ($discard = $queryParameters.add("%${filename}%")) #end #if ($space) #set ($space = $space.trim().toLowerCase()) #set ($query = $query + " and lower(doc.space) like ?") #set ($discard = $queryParameters.add("%${space}%")) #end ## ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm) ## #if (!$hasAdmin) #foreach ($blacklistedSpace in $blacklistedSpaces) #set ($query = "${query} and doc.space <> ?") #set ($discard = $queryParameters.add($blacklistedSpace)) #end #end #set ($validSortOptions = ['filename', 'doc.name', 'doc.space', 'doc.date', 'doc.author']) #if($validSortOptions.contains($request.sort)) #set ($order = $request.sort) #else #set ($order = 'attach.filename') #end #if ($order == 'filename') #set ($order = 'attach.filename') #end #if ("$!request.dir" == 'desc') #set ($dir = 'desc') #else #set ($dir = 'asc') #end ## ## Compute the final query ## #set ($countQuery = "select count(*) from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query) #set ($query = "select doc.fullName, attach from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query + " order by $order $dir") #set ($items = $xwiki.search($query, $limit, $off, $queryParameters)) #set ($totalItems = $xwiki.search($countQuery, 0, 0, $queryParameters).get(0)) #set ($returnedItems = $items.size()) ## ============================================== ## json starts ## ============================================== { "totalrows": $totalItems, "returnedrows": #if($returnedItems < $limit) $returnedItems #else $limit #end, "offset": $offset, "reqNo": $util.parseInt($request.reqNo), "rows": [ #foreach ($item in $items) #set ($docName = $item.get(0)) #set ($hasAccess = $xwiki.hasAccessLevel('view', $context.user, $docName)) #set ($attachment = $item.get(1)) #if ($velocityCount > 1) , #end { "acclev" : $hasAccess, #if ($hasAccess) #set ($document = $xwiki.getDocument($docName)) "page" : "$escapetool.javascript($document.name)", "space" : "$escapetool.javascript($document.space)", "fullname" : "$escapetool.javascript($document.fullName)", "filename" : "$escapetool.javascript($attachment.filename)", "fileurl" : "$document.getAttachmentURL($attachment.filename)", "url" : "$document.getURL('view')", "spaceurl" : '$xwiki.getURL("${document.space}.WebHome")', "date" : "$xwiki.formatDate($attachment.date, $formatDate)", "author" : "$!escapetool.javascript($attachment.author)", "authorname" : "$!escapetool.javascript($xwiki.getDocument($attachment.author).name)", "authorurl" : "$xwiki.getURL($attachment.author)", "type" : "$!escapetool.javascript($attachment.getMimeType($context.context))" #else "fullname": "$escapetool.javascript($docName)" #end } #end ]} ## ============================================== ## json ended ## ============================================== #end {{/velocity}}
Quick Links
L3D Calendar
Wiki Dashboard
Document Index
Blog
Sandbox