Wiki source code of Macros
Last modified by superadmin on 2019/11/08 17:56
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{velocity filter="none" output="false"}} | ||
2 | ## Not used here but kept for retro-compatibility | ||
3 | #set($restURL = "${request.contextPath}/rest") | ||
4 | ## Retrieve the annotation class from the configuration | ||
5 | #set($config = 'AnnotationCode.AnnotationConfig') | ||
6 | #set($annotationClassDocName = $xwiki.getDocument($config).getObject($config).getProperty('annotationClass').value) | ||
7 | #set($annotationClass = $xwiki.getDocument("$!{annotationClassDocName}").getxWikiClass()) | ||
8 | ## | ||
9 | ## | ||
10 | ## Do not display these 'internal' properties in the form: | ||
11 | #set($hiddenProperties = ['selection', 'selectionLeftContext', 'selectionRightContext', 'originalSelection', 'target', 'date', 'author', 'state', 'replyto', 'highlight'])## TODO: 'color' | ||
12 | ## | ||
13 | ## | ||
14 | #* | ||
15 | * Display a box for creating an annotation | ||
16 | * | ||
17 | * @param $docWiki the wiki of the annotated document | ||
18 | * @param $docSpace the space of the annotated document | ||
19 | * @param $docPage the page of the annotated document | ||
20 | * @param $annData a map containing the mandatory selection-related fields | ||
21 | * @deprecated since 7.2M2, use #displayCreateBoxFromReference instead | ||
22 | *# | ||
23 | #macro(displayCreateBox $docWiki $docSpace $docPage $annData) | ||
24 | #displayCreateBoxFromReference($services.model.createDocumentReference($docWiki, $docSpace, $docPage)) | ||
25 | #end | ||
26 | #* | ||
27 | * Display a box for creating an annotation | ||
28 | * | ||
29 | * @param $docRef the reference of the annotated document | ||
30 | * @param $annData a map containing the mandatory selection-related fields | ||
31 | *# | ||
32 | #macro(displayCreateBoxFromReference $docRef $annData) | ||
33 | <div class="annotation-box annotation-box-create"> | ||
34 | #set ($fullRestURL = "${services.rest.url($docRef)}/annotations?media=json") | ||
35 | <form method="POST" action="$escapetool.xml($response.encodeURL($fullRestURL))"> | ||
36 | <div class="hidden"> | ||
37 | #foreach($field in $annData.keySet()) | ||
38 | <input type="hidden" name="${field}" value="$!{escapetool.xml($annData.get(${field}))}"/> | ||
39 | #end | ||
40 | </div> | ||
41 | #displayAnnotationFromReference($annData, 'create', $docRef) | ||
42 | #displayAnnotationBoxButtons('create') | ||
43 | </form> | ||
44 | </div> | ||
45 | #end | ||
46 | #* | ||
47 | * Display a box for editing an annotation | ||
48 | * | ||
49 | * @param $id the annotation identifier | ||
50 | * @param $docWiki the wiki of the annotated document | ||
51 | * @param $docSpace the space of the annotated document | ||
52 | * @param $docPage the page of the annotated document | ||
53 | * @deprecated, starting with 7.2M3, use #displayEditBoxFromReference instead | ||
54 | *# | ||
55 | #macro(displayEditBox $id $docWiki $docSpace $docPage) | ||
56 | #displayEditBoxFromReference($id, $services.model.createDocumentReference($docWiki, $docSpace, $docPage)) | ||
57 | #end | ||
58 | #* | ||
59 | * Display a box for editing an annotation | ||
60 | * | ||
61 | * @param $id the annotation identifier | ||
62 | * @param $docRef the reference of the annotated document | ||
63 | *# | ||
64 | #macro(displayEditBoxFromReference $id $docRef) | ||
65 | #set($ann = $services.annotations.getAnnotation($docRef, $id)) | ||
66 | <div class="annotation-box annotation-box-edit"> | ||
67 | #if($ann) | ||
68 | #set($editURL = "${services.rest.url($docRef)}/annotation/${escapetool.url($ann.id)}?method=PUT&media=json") | ||
69 | <form method='POST' action="${editURL}"> | ||
70 | #displayAnnotationFromReference($ann, 'edit', $docRef) | ||
71 | #displayAnnotationBoxButtons('edit') | ||
72 | </form> | ||
73 | #else | ||
74 | <div class="box infomessage">$services.localization.render('annotations.action.edit.error.notfound')</div> | ||
75 | #end | ||
76 | </div> | ||
77 | #end | ||
78 | #* | ||
79 | * Display a box containing the annotation | ||
80 | * | ||
81 | * @param $id the annotation identifier | ||
82 | * @param $docWiki the wiki of the annotated document | ||
83 | * @param $docSpace the space of the annotated document | ||
84 | * @param $docPage the page of the annotated document | ||
85 | * @deprecated since 7.2M3, use #displayViewBoxFromReference instead | ||
86 | *# | ||
87 | #macro(displayViewBox $id $docWiki $docSpace $docPage) | ||
88 | #displayViewBoxFromReference($id, $services.model.createDocumentReference($docWiki, $docSpace, $docPage)) | ||
89 | #end | ||
90 | #* | ||
91 | * Display a box containing the annotation | ||
92 | * | ||
93 | * @param $target the annotated entity identifier | ||
94 | * @param $id the annotation identifier | ||
95 | * @param $docRef the reference of the annotated document | ||
96 | *# | ||
97 | #macro(displayViewBoxFromReference $id $docRef) | ||
98 | #set($ann = $services.annotations.getAnnotation($docRef, $id)) | ||
99 | <div class="annotation-box annotation-box-view"> | ||
100 | #if ($ann) | ||
101 | #*<div class="links"> | ||
102 | <a href="#" class='annotation-view-hide'>$services.localization.render('annotations.action.view.hide.text')</a> | ||
103 | </div>*# | ||
104 | ##<div class="clearfloats"></div> | ||
105 | #displayAnnotationFromReference($ann $mode $docRef) | ||
106 | #else | ||
107 | <div class="box infomessage">$services.localization.render('annotations.action.view.error.notfound')</div> | ||
108 | #end | ||
109 | </div> | ||
110 | #end | ||
111 | ## | ||
112 | ## | ||
113 | ## | ||
114 | #* | ||
115 | * Display form buttons | ||
116 | * | ||
117 | * @param $mode 'create' or 'edit' | ||
118 | *# | ||
119 | #macro(displayAnnotationBoxButtons $mode) | ||
120 | <div class="buttons"> | ||
121 | <span class='buttonwrapper'><input type="submit" class='button' value='$!{escapetool.xml($services.localization.render("annotations.action.${mode}.submit.text"))}'/></span> | ||
122 | <span class='buttonwrapper'><input type="reset" class='button secondary' value='$!{escapetool.xml($services.localization.render("annotations.action.${mode}.cancel.text"))}'/></span> | ||
123 | </div> | ||
124 | #end | ||
125 | ## | ||
126 | ## | ||
127 | #** | ||
128 | * Display an annotation | ||
129 | * | ||
130 | * @param $ann the annotation object | ||
131 | * @param $mode view (default), list, create or edit | ||
132 | * @param $docWiki the wiki of the annotated document | ||
133 | * @param $docSpace the space of the annotated document | ||
134 | * @param $docPage the page of the annotated document | ||
135 | * @deprecated since 7.2M3, use #displayAnnotationFromReference instead | ||
136 | *# | ||
137 | #macro(displayAnnotation $ann $mode $docWiki $docSpace $docPage) | ||
138 | #displayAnnotationFromReference($ann, $mode, $services.model.createDocumentReference($docWiki, $docSpace, $docPage)) | ||
139 | #end | ||
140 | #** | ||
141 | * Display an annotation | ||
142 | * | ||
143 | * @param $ann the annotation object | ||
144 | * @param $mode view (default), list, create or edit | ||
145 | * @param $docRef the reference of the annotated document | ||
146 | *# | ||
147 | #macro(displayAnnotationFromReference $ann $mode $docRef) | ||
148 | #set ($availableModes = ['view', 'list', 'create', 'edit']) | ||
149 | #if(!$availableModes.contains("$!{mode}")) | ||
150 | #set($mode = 'view') | ||
151 | #end | ||
152 | <div class="annotation $!{ann.state}" id="annotation_${mode}_$!{ann.id}"> | ||
153 | <div class="annotationAvatar">#mediumUserAvatar($ann.author)</div> | ||
154 | <div class="annotationHeader"> | ||
155 | #displayAnnotationTitle($ann) | ||
156 | #displayAnnotationToolboxFromReference($ann $mode $docRef) | ||
157 | </div> | ||
158 | <div class="annotationContent"> | ||
159 | #displayAnnotationBody($ann $mode) | ||
160 | #if ($mode == 'view' && $annotationClassDocName == 'XWiki.XWikiComments') | ||
161 | #set($annoDoc = $xwiki.getDocument($docRef)) | ||
162 | #set($repliesList = $annoDoc.getObjects('XWiki.XWikiComments', 'replyto', $ann.id)) | ||
163 | #if($repliesList.size() > 0) | ||
164 | <a href="#xwikicomment_${ann.id}">$services.localization.render('annotations.action.view.thread')</a> | ||
165 | #end | ||
166 | #end | ||
167 | </div> | ||
168 | </div> | ||
169 | #end | ||
170 | ## | ||
171 | ## | ||
172 | #** | ||
173 | * Display the annotation title, containing author and date | ||
174 | * | ||
175 | * @param $ann the annotation object | ||
176 | *# | ||
177 | #macro(displayAnnotationTitle $ann) | ||
178 | #set ($dateFormat = $xwiki.getXWikiPreference('dateformat', 'dd/MM/yyyy')) | ||
179 | <div class="annotationTitle"> | ||
180 | <span class="annotationAuthor">$!xwiki.getUserName($ann.author)</span>## | ||
181 | ## Do not indent this, or the comma will be misplaced | ||
182 | #if("$!{ann.date}" != '')<span class="sep">, </span><span class="annotationDate">$xwiki.formatDate($ann.date, $dateFormat)</span>#end | ||
183 | </div> | ||
184 | #end | ||
185 | ## | ||
186 | ## | ||
187 | #** | ||
188 | * Display the annotation toolbox: | ||
189 | * - 'verify' button for modified annotations | ||
190 | * - 'edit' button for annotation authors and other users with edit rights, unless already editing | ||
191 | * - 'delete' button for annotation authors and other users with edit rights | ||
192 | * | ||
193 | * @param $ann the annotation object | ||
194 | * @param $mode view (default), list, create or edit | ||
195 | * @param $docWiki the wiki of the annotated document | ||
196 | * @param $docSpace the space of the annotated document | ||
197 | * @param $docPage the page of the annotated document | ||
198 | *# | ||
199 | #macro(displayAnnotationToolbox $ann $mode $docWiki $docSpace $docPage) | ||
200 | #displayAnnotationToolboxFromReference($ann, $mode, $services.model.createDocumentReference($docWiki, $docSpace, $docPage)) | ||
201 | #end | ||
202 | #** | ||
203 | * Display the annotation toolbox: | ||
204 | * - 'verify' button for modified annotations | ||
205 | * - 'edit' button for annotation authors and other users with edit rights, unless already editing | ||
206 | * - 'delete' button for annotation authors and other users with edit rights | ||
207 | * | ||
208 | * @param $ann the annotation object | ||
209 | * @param $mode view (default), list, create or edit | ||
210 | * @param $docRef the reference of the annotated document | ||
211 | *# | ||
212 | #macro(displayAnnotationToolboxFromReference $ann $mode $docRef) | ||
213 | <span class="annotationTools btn-group"> | ||
214 | #if($mode != 'create' && $services.annotations.canEditAnnotation($ann.id, $docRef)) | ||
215 | #set($isUserComment = $services.model.resolveDocument("$!ann.get('author')", 'user') == $xcontext.userReference) | ||
216 | #set($editURL = "${services.rest.url($docRef)}/annotation/${escapetool.url($ann.id)}?method=PUT&media=json") | ||
217 | #if ("$!{ann.state}" == 'UPDATED') | ||
218 | <a class='btn btn-default btn-xs validate' href="${editURL}" | ||
219 | title="$services.localization.render('annotations.action.validate.tooltip')"> | ||
220 | $services.icon.renderHTML('check') | ||
221 | </a> | ||
222 | #end | ||
223 | #if ($mode != 'edit') | ||
224 | ## Comment reply button only for default annotations. | ||
225 | #if ("$!annotationClassDocName" == 'XWiki.XWikiComments') | ||
226 | #set($xredirect = $!escapetool.xml($request.get('xredirect'))) | ||
227 | #if("$!xredirect" == '') | ||
228 | #set($xredirect = "$xwiki.getURL($docRef, 'view', $!{request.queryString})") | ||
229 | #end | ||
230 | ## add "comment reply" button | ||
231 | <a class='btn btn-default btn-xs reply' href="${xredirect}#xwikicomment_${ann.id}" | ||
232 | title="$services.localization.render('core.viewers.comments.reply')"> | ||
233 | $services.icon.renderHTML('comment') | ||
234 | </a> | ||
235 | #end | ||
236 | #if($hasAdmin || $isUserComment) | ||
237 | ## use an edit url just for the fanciness of it, it won't really be used in this case. An edit form will be loaded | ||
238 | <a class='edit btn btn-default btn-xs' href="${editURL}" | ||
239 | title="$services.localization.render('annotations.action.edit.tooltip')"> | ||
240 | $services.icon.renderHTML('pencil') | ||
241 | </a> | ||
242 | #end | ||
243 | #end | ||
244 | #if($hasAdmin || $isUserComment) | ||
245 | #set($deleteURL = "${services.rest.url($docRef)}/annotation/${escapetool.url($ann.id)}?method=DELETE&media=json") | ||
246 | <a class='delete btn btn-default btn-xs' href="${deleteURL}" | ||
247 | title="$services.localization.render('annotations.action.delete.tooltip')"> | ||
248 | $services.icon.renderHTML('cross') | ||
249 | </a> | ||
250 | #end | ||
251 | #end | ||
252 | </span> | ||
253 | #end | ||
254 | ## | ||
255 | ## | ||
256 | #** | ||
257 | * Display the annotation body, containing all but the hidden fields. | ||
258 | * For annotation lists (which are not displayed near the actual annotation text), also display | ||
259 | * in a block quote the corresponding annotated extract. | ||
260 | * Depending on the mode, display for each field label + input (edit, create) or the field value (view, list). | ||
261 | * | ||
262 | * @param $ann the annotation object | ||
263 | * @param $mode view (default), list, create or edit | ||
264 | *# | ||
265 | #macro(displayAnnotationBody $ann $mode) | ||
266 | #if ($mode == 'list') | ||
267 | #if ($ann.state == 'ALTERED') | ||
268 | <div class="annotationOriginalSelection">$services.localization.render('annotations.altered.text')</div> | ||
269 | #end | ||
270 | <blockquote class="annotatedText">$!escapetool.xml($ann.selection)</blockquote> | ||
271 | #end | ||
272 | ## in view mode and list mode, also display the original selection of this annotation | ||
273 | #if (($mode == 'view' || $mode == 'list') && $ann.state == 'UPDATED') | ||
274 | <div class="annotationOriginalSelection">$services.localization.render('annotations.updated.text')</div> | ||
275 | <blockquote class="annotatedText originalAnnotatedText">$!escapetool.xml($ann.originalSelection)</blockquote> | ||
276 | #end | ||
277 | ## Fake object that allows to use the API to generate the display | ||
278 | #set($fakeObj = $doc.newObject($annotationClassDocName)) | ||
279 | #set($properties = $annotationClass.properties) | ||
280 | #if ($properties.size() == $hiddenProperties.size() + 1) | ||
281 | ## Do not show property labels if there's only one property to display | ||
282 | ## get the only property that is to be displayed | ||
283 | #set($onlyProperty = '') | ||
284 | #foreach($prop in $properties) | ||
285 | #if(!$hiddenProperties.contains($prop.name)) | ||
286 | #set($onlyProperty = $prop) | ||
287 | #break | ||
288 | #end | ||
289 | #end | ||
290 | #set($discard = $fakeObj.set($onlyProperty.name, "$!{ann.get($onlyProperty.name)}")) | ||
291 | <div class="annotationText"> | ||
292 | #if($mode == 'edit' || $mode == 'create') | ||
293 | $doc.displayEdit($onlyProperty, '', $fakeObj) | ||
294 | #else | ||
295 | $doc.displayView($onlyProperty, '', $fakeObj) | ||
296 | #end | ||
297 | </div> | ||
298 | #else | ||
299 | <dl> | ||
300 | #foreach($prop in $properties) | ||
301 | #if (!$hiddenProperties.contains($prop.name)) | ||
302 | #set($discard = $fakeObj.set($prop.name, "$!{ann.get($prop.name)}")) | ||
303 | <dt class="annotationLabel"><label for="$prop.name">$prop.prettyName</label></dt> | ||
304 | #if($mode == 'edit' || $mode == 'create') | ||
305 | <dd>$doc.displayEdit($prop, '', $fakeObj)</dd> | ||
306 | #else | ||
307 | <dd>$doc.displayView($prop, '', $fakeObj)</dd> | ||
308 | #end | ||
309 | #end | ||
310 | #end | ||
311 | </dl> | ||
312 | #end | ||
313 | #end | ||
314 | {{/velocity}} |