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
Hide line numbers
1: {{velocity}} 2: ## ============================================================================================ 3: ## This page is called from live grids via Ajax with the argument xpage=plain. It returns a 4: ## set of results serialized in JSON. 5: ## @programming This service page needs to be saved by a user with the programming access level 6: ## to work as expected 7: ## ============================================================================================ 8: #if ("$!request.get('xpage')" == 'plain') 9: #set ($offset = $util.parseInt($request.get('offset'))) 10: ## offset starts from 0 in velocity and 1 in javascript 11: #set ($off = $offset - 1) 12: #set ($limit = $util.parseInt($request.get('limit'))) 13: #set ($title = $request.get('doc.name')) 14: #set ($author = $request.get('doc.author')) 15: #set ($space = $request.get('doc.space')) 16: #set ($filename = $request.filename) 17: #set ($formatDate = 'yyyy MMMM dd, HH:mm') 18: #set ($query = '') 19: #set ($queryParameters = []) 20: #if ($title) 21: #set ($title = $title.trim().toLowerCase()) 22: #set ($query = $query + " and lower(doc.name) like ?") 23: #set ($discard = $queryParameters.add("%${title}%")) 24: #end 25: #if ($author) 26: #set ($author = $author.trim().toLowerCase()) 27: #set ($query = $query + " and lower(attach.author) like ?") 28: #set ($discard = $queryParameters.add("%${author}%")) 29: #end 30: #if ($filename) 31: #set ($filename = $filename.trim().toLowerCase()) 32: #set ($query = $query + " and lower(attach.filename) like ?") 33: #set ($discard = $queryParameters.add("%${filename}%")) 34: #end 35: #if ($space) 36: #set ($space = $space.trim().toLowerCase()) 37: #set ($query = $query + " and lower(doc.space) like ?") 38: #set ($discard = $queryParameters.add("%${space}%")) 39: #end 40: ## 41: ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm) 42: ## 43: #if (!$hasAdmin) 44: #foreach ($blacklistedSpace in $blacklistedSpaces) 45: #set ($query = "${query} and doc.space <> ?") 46: #set ($discard = $queryParameters.add($blacklistedSpace)) 47: #end 48: #end 49: #set ($validSortOptions = ['filename', 'doc.name', 'doc.space', 'doc.date', 'doc.author']) 50: #if($validSortOptions.contains($request.sort)) 51: #set ($order = $request.sort) 52: #else 53: #set ($order = 'attach.filename') 54: #end 55: #if ($order == 'filename') 56: #set ($order = 'attach.filename') 57: #end 58: #if ("$!request.dir" == 'desc') 59: #set ($dir = 'desc') 60: #else 61: #set ($dir = 'asc') 62: #end 63: ## 64: ## Compute the final query 65: ## 66: #set ($countQuery = "select count(*) from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query) 67: #set ($query = "select doc.fullName, attach from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query + " order by $order $dir") 68: #set ($items = $xwiki.search($query, $limit, $off, $queryParameters)) 69: #set ($totalItems = $xwiki.search($countQuery, 0, 0, $queryParameters).get(0)) 70: #set ($returnedItems = $items.size()) 71: ## ============================================== 72: ## json starts 73: ## ============================================== 74: { 75: "totalrows": $totalItems, 76: "returnedrows": #if($returnedItems < $limit) $returnedItems #else $limit #end, 77: "offset": $offset, 78: "reqNo": $util.parseInt($request.reqNo), 79: "rows": [ 80: #foreach ($item in $items) 81: #set ($docName = $item.get(0)) 82: #set ($hasAccess = $xwiki.hasAccessLevel('view', $context.user, $docName)) 83: #set ($attachment = $item.get(1)) 84: #if ($velocityCount > 1) , #end 85: { "acclev" : $hasAccess, 86: #if ($hasAccess) 87: #set ($document = $xwiki.getDocument($docName)) 88: "page" : "$escapetool.javascript($document.name)", 89: "space" : "$escapetool.javascript($document.space)", 90: "fullname" : "$escapetool.javascript($document.fullName)", 91: "filename" : "$escapetool.javascript($attachment.filename)", 92: "fileurl" : "$document.getAttachmentURL($attachment.filename)", 93: "url" : "$document.getURL('view')", 94: "spaceurl" : '$xwiki.getURL("${document.space}.WebHome")', 95: "date" : "$xwiki.formatDate($attachment.date, $formatDate)", 96: "author" : "$!escapetool.javascript($attachment.author)", 97: "authorname" : "$!escapetool.javascript($xwiki.getDocument($attachment.author).name)", 98: "authorurl" : "$xwiki.getURL($attachment.author)", 99: "type" : "$!escapetool.javascript($attachment.getMimeType($context.context))" 100: #else 101: "fullname": "$escapetool.javascript($docName)" 102: #end 103: } 104: #end 105: ]} 106: ## ============================================== 107: ## json ended 108: ## ============================================== 109: #end 110: {{/velocity}}
Quick Links
L3D Calendar
Wiki Dashboard
Document Index
Blog
Sandbox