Wiki source code of CreateForm

Version 1.1 by Laura Sagunski on 2022/09/27 12:39

Show last authors
1 {{template name="display_macros.vm" /}}
2
3 {{include reference="AnnotationCode.Macros" /}}
4
5 {{velocity output="false"}}
6 #if ("$!{request.reference}" != '')
7 #set($annotationReference = $services.model.resolveDocument($request.reference))
8 #elseif("$!{request.wiki}" != '' && "$!{request.space}" != '' && "$!{request.page}" != '')
9 #set($annotationReference = $services.model.createDocumentReference("$!{request.wiki}", "$!{request.space}", "$!{request.page}"))
10 #end
11 {{/velocity}}
12
13 {{velocity}}
14 #if(!$annotationReference)
15 {{warning}}$services.localization.render('annotations.action.create.error.notarget'){{/warning}}
16 #else
17 ## pretty dirtish but it's so gonna do the job: don't display this form to users which don't have the right to create annotations, instead send a nice unauthorized message
18 #if(!$services.annotations.canAddAnnotation($annotationReference))
19 #set($message = $services.localization.render('annotations.action.create.error.unauthorized'))
20 #if ($xcontext.user.equals("XWiki.XWikiGuest"))
21 #set($message = $services.localization.render('annotations.action.create.error.unauthorizedguest'))
22 #end
23 ## unauthorized, with a nice i18n message
24 $response.sendError(401, $message)
25 #end
26
27 {{html}}
28 ## get create a hashmap with request data about the selection
29 #set($annData = {})
30 #set($dispose = $annData.put("selection", $!request.selection))
31 #set($dispose = $annData.put("selectionContext", $!request.selectionContext))
32 #set($dispose = $annData.put("selectionOffset", $!request.selectionOffset))
33 ## pretend that annotation author is current user, and annotation date is now
34 ##Even if they get sent to the server, the server will overwrite with anything's logged in in there anyway
35 #set($dispose = $annData.put("author", $xcontext.user))
36 #set($dispose = $annData.put("date", $datetool.date))
37 ## The annotation creation form is loaded asynchronously so we need to send back also the required JavaScript and CSS
38 ## resources (besides the form HTML).
39 #initRequiredSkinExtensions()
40 #displayCreateBoxFromReference($annotationReference, $annData)
41 #getRequiredSkinExtensions($requiredSkinExtensions)
42 #set ($discard = $response.setHeader('X-XWIKI-HTML-HEAD', $requiredSkinExtensions))
43 {{/html}}
44 #end
45 {{/velocity}}