Version 3.1 by Thomas Coelho (local) on 2023/02/24 19:45

Show last authors
1 {{template name="locationPicker_macros.vm" /}}
2
3 {{velocity}}
4 ## This document can be copied in order to be customized so we cannot rely on its name to determine if the currently
5 ## displayed document is a class or the class sheet itself. We look for the sheet descriptor instead.
6 #set ($isSheet = $doc.getObject('XWiki.SheetDescriptorClass'))
7 #if ($isSheet)
8 ## Viewing the sheet document itself.
9 {{translation key="platform.xclass.defaultClassSheet.description"/}}
10 #elseif ("$!request.bindSheet" != '' && $hasEdit)
11 #if ($services.csrf.isTokenValid($request.getParameter('form_token')))
12 ## Bind the sheet to the class.
13 #set ($classSheetReference = $services.model.resolveDocument($request.bindSheet))
14 #if ($services.sheet.bindClassSheet($doc, $classSheetReference))
15 $doc.save($services.localization.render('platform.xclass.defaultClassSheet.sheets.bind'))
16 #end
17 $response.sendRedirect($request.xredirect)
18 #else
19 $response.sendRedirect($services.csrf.getResubmissionURL())
20 #end
21 ## Stop processing, since we already sent a redirect.
22 #stop
23 #elseif("$!request.docName" != '')
24 ## Request for creating a new instance.
25 ## We don't actually create a new instance here, we just redirect to the edit mode.
26 #set ($targetSpaceRef = $services.model.resolveSpace($request.spaceName))
27 #set ($targetDocRef = $services.model.createDocumentReference($request.docName, $targetSpaceRef))
28 #if (!$xwiki.exists($targetDocRef) && $services.security.authorization.hasAccess('edit', $targetDocRef))
29 ## Compute the default edit mode to ensure backward compatibility with documents that are still using the deprecated
30 ## inline action.
31 #set ($editAction = $xwiki.getDocument($request.template).getDefaultEditMode())
32 $response.sendRedirect($xwiki.getURL($targetDocRef, $editAction, $escapetool.url({
33 'template': $request.template,
34 'parent': $request.parent,
35 'title': $request.docName
36 })))
37 ## Stop processing, since we already sent a redirect.
38 #stop
39 #end
40 #end
41 {{/velocity}}
42
43 {{velocity}}
44 ## If this sheet is explicitly bound to the displayed class then print the class document content before the
45 ## sheet output. Class authors can put the description of the class in the class document content.
46 #set($classSheetReference = $services.model.createDocumentReference($doc.wiki, 'XWiki', 'ClassSheet'))
47 #if($services.sheet.getDocumentSheets($doc).contains($classSheetReference))
48 {{include reference="" /}}
49 #end
50 {{/velocity}}
51
52 {{velocity}}
53 #if (!$isSheet)
54 #set ($className = $doc.pageReference.name)
55 #set ($className = $stringtool.removeEnd($className, 'Class'))
56 ## Determine the class sheets.
57 #set ($classSheetReferences = $services.sheet.getClassSheets($doc))
58 #if ($classSheetReferences.isEmpty())
59 ## There is no class sheet explicitly bound to this class. Fall-back on naming convention.
60 ## Before XWiki 2.0, the default class sheet was suffixed with "ClassSheet". Since 2.0, the suffix is just "Sheet".
61 #set ($defaultClassSheetReference = $services.model.createDocumentReference("${className}ClassSheet",
62 $doc.documentReference.parent))
63 #if (!$xwiki.exists($defaultClassSheetReference))
64 #set ($defaultClassSheetReference = $services.model.createDocumentReference("${className}Sheet",
65 $doc.documentReference.parent))
66 #end
67 #end
68 ## Determine the template using naming convention.
69 ## Before XWiki 2.0, the default class template was suffixed with "ClassTemplate".
70 ## Since 2.0, the suffix is just "Template".
71 #set ($classTemplateReference = $services.model.createDocumentReference("${className}ClassTemplate",
72 $doc.documentReference.parent))
73 #if (!$xwiki.exists($classTemplateReference))
74 #set ($classTemplateReference = $services.model.createDocumentReference("${className}Template",
75 $doc.documentReference.parent))
76 #end
77 ## Determine the template provider using naming convention.
78 #set ($classTemplateProviderReference = $services.model.createDocumentReference("${className}TemplateProvider",
79 $doc.documentReference.parent))
80 #set ($classTemplateProviderDoc = $xwiki.getDocument($classTemplateProviderReference))
81 #set ($hasClassTemplateProvider = !$classTemplateProviderDoc.isNew())
82 #set($classTemplateDoc = $xwiki.getDocument($classTemplateReference))
83 #set($hasClassSheets = !$classSheetReferences.isEmpty() || $xwiki.exists($defaultClassSheetReference))
84 #set($hasClassTemplate = !$classTemplateDoc.isNew())
85 #if(!$defaultSpace)
86 #set($defaultSpace = $doc.space)
87 #end
88 #if(!$defaultParent)
89 #set($defaultParent = ${doc.fullName})
90 #end
91
92 #set ($classEditorURL = $doc.getURL('edit', 'editor=class'))
93 #if($doc.getxWikiClass().properties.size() == 0)
94 #set ($openLink = "<a href='$escapetool.xml($classEditorURL)'>")
95 #set ($closeLink = '</a>')
96 {{warning}}
97 {{html}}
98 ## First escape the content of the translation, then replace the placeholders with content that would otherwise be
99 ## escaped during the first escaping.
100 #set ($warningMessage = $services.localization.render('platform.xclass.defaultClassSheet.properties.empty',
101 ['__OPEN_LINK__', '__CLOSE_LINK__']))
102 $escapetool.xml($warningMessage).replace('__OPEN_LINK__', $openLink).replace('__CLOSE_LINK__', $closeLink)
103 {{/html}}
104 {{/warning}}
105 #else
106 (% id="HClassProperties" %)
107 = {{translation key="platform.xclass.defaultClassSheet.properties.heading"/}} =
108 #foreach($property in $doc.getxWikiClass().properties)
109 * $services.rendering.escape("$property.prettyName ($property.name: $xwiki.metaclass.get($property.classType).prettyName)", $xwiki.currentContentSyntaxId)
110 #end
111 #set ($openLink = "<a href='$escapetool.xml($classEditorURL)'>")
112 #set ($closeLink = '</a>')
113 #set ($warningMessage = $escapetool.xml($services.localization.render('platform.xclass.defaultClassSheet.properties.edit', ['__OPEN_LINK__', '__CLOSE_LINK__'])))
114 ## First escape the content of the translation, then replace the placeholders with content that would otherwise be
115 ## escaped during the first escaping.
116 * //{{html}}$warningMessage.replace('__OPEN_LINK__', $openLink).replace('__CLOSE_LINK__', $closeLink){{/html}}//
117
118 #end
119 #if ($hasClassSheets && $hasClassTemplate)
120 (% id="HCreatePage" %)
121 = {{translation key="platform.xclass.defaultClassSheet.createPage.heading"/}} =
122 #if("$!targetDocRef" != '' && $xwiki.exists($targetDocRef))
123 {{warning}}
124 {{html}}
125 #set ($targetDocLink = $xwiki.getURL($targetDocRef))
126 #set ($openLink = "<a href='$escapetool.xml($targetDocLink)'>")
127 #set ($message = $escapetool.xml($services.localization.render('platform.xclass.defaultClassSheet.createPage.pageAlreadyExists', ['__OPEN_LINK__', '__CLOSE_LINK__'])))
128 ## First escape the content of the translation, then replace the placeholders with content that would
129 ## otherwise be escaped during the first escaping.
130 $message.replace('__OPEN_LINK__', $openLink).replace('__CLOSE_LINK__', '</a>')
131 {{/html}}
132 {{/warning}}
133 #elseif("$!targetDocRef" != '')
134
135 {{warning}}{{translation key="platform.xclass.defaultClassSheet.createPage.denied"/}}{{/warning}}
136 #end
137
138 {{html}}
139 <form action="$doc.getURL()" id="newdoc" method="post" class="xform half">
140 <fieldset>
141 <div class="hidden">
142 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
143 <input type="hidden" name="parent" value="$escapetool.xml(${defaultParent})"/>
144 <input type="hidden" name="template" value="$escapetool.xml(${classTemplateDoc})"/>
145 <input type="hidden" name="sheet" value="1"/>
146 </div>
147 #locationPicker({
148 'id': 'target',
149 'title': {
150 'label': 'core.create.title',
151 'hint': 'core.create.title.hint',
152 'name': 'docTitle',
153 'placeholder': 'core.create.name.placeholder'
154 },
155 'preview': {
156 'label': 'core.create.locationPreview.label',
157 'hint': 'core.create.locationPreview.hint'
158 },
159 'parent': {
160 'label': 'core.create.spaceReference.label',
161 'hint': 'core.create.spaceReference.hint',
162 'name': 'spaceName',
163 'reference': $services.model.resolveSpace($defaultSpace),
164 'placeholder': 'core.create.spaceReference.placeholder'
165 },
166 'name': {
167 'label': 'core.create.name.label',
168 'hint': 'core.create.name.hint',
169 'name': 'docName',
170 'placeholder': 'core.create.name.placeholder'
171 }
172 })
173 <p>
174 <span class="buttonwrapper">
175 <input type="submit" class="button" value="$escapetool.xml($services.localization.render(
176 'platform.xclass.defaultClassSheet.createPage.label'))"/>
177 </span>
178 </p>
179 </fieldset>
180 </form>
181 {{/html}}
182
183 #end## has class sheet and class template
184 (% id="HExistingPages" %)
185 = {{translation key="platform.xclass.defaultClassSheet.pages.heading"/}} =
186
187 {{translation key="platform.xclass.defaultClassSheet.pages.description"/}}
188
189 #set ($options = {
190 'className': $doc.fullName,
191 'translationPrefix' : 'platform.index.',
192 'queryFilters': ['unique']
193 })
194 {{liveData
195 id="classEntries"
196 properties="doc.title,doc.location,doc.date,doc.author,doc.objectCount,_actions"
197 source="liveTable"
198 className="$services.rendering.escape(${doc.fullName}, 'xwiki/2.1')"
199 sourceParameters="$services.rendering.escape($escapetool.url($options), 'xwiki/2.1')"
200 }}
201 {
202 "meta": {
203 "propertyDescriptors": [
204 {
205 "id": "doc.title",
206 "editable": false
207 },
208 {
209 "id": "doc.objectCount",
210 "editable": false,
211 "filterable": false,
212 "sortable": false
213 }
214 ]
215 }
216 }
217 {{/liveData}}
218
219 (% id="HClassSheets" %)
220 = {{translation key="platform.xclass.defaultClassSheet.sheets.heading"/}} =
221 #if (!$hasClassSheets || !$hasClassTemplate)
222
223 {{translation key="platform.xclass.defaultClassSheet.sheets.missing"/}}
224 #end
225
226 {{info}}
227 #set ($message = $services.localization.render('platform.xclass.defaultClassSheet.sheets.description', ['__START_EM__', '__END_EM__']))
228 #set ($message = $escapetool.xml($message))
229 ## First escape the content of the translation, then replace the placeholders with content that would
230 ## otherwise be escaped during the first escaping.
231 {{html}}$message.replace('__START_EM__', '<em>').replace('__END_EM__', '</em>'){{/html}}
232 {{/info}}
233
234 #if(!$hasClassSheets)
235 {{html}}
236 <form action="$xwiki.getURL($defaultClassSheetReference, 'save', 'editor=wiki')" method="post">
237 <div>
238 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
239 <input type="hidden" name="parent" value="$escapetool.xml(${doc.fullName})"/>
240 <input type="hidden" name="xredirect" value="$escapetool.xml(${doc.URL})"/>
241 #set ($sheetContent = $xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass',
242 $doc.fullName))
243 ## We have to encode the new line characters in order to preserve them, otherwise they are replace with a
244 ## space when the HTML is cleaned.
245 ## FIXME: Use a dedicated escape tool method when XCOMMONS-405 is implemented.
246 #set ($sheetContent = $escapetool.xml($sheetContent).replaceAll("\n", '&#10;'))
247 <input type="hidden" name="content" value="$sheetContent"/>
248 <input type="hidden" name="title" value="${escapetool.h}if(${escapetool.d}doc.documentReference.name == '$escapetool.xml($defaultClassSheetReference.name)')$escapetool.xml($className) Sheet${escapetool.h}{else}${escapetool.d}services.display.title(${escapetool.d}doc, {'displayerHint': 'default', 'outputSyntaxId': 'plain/1.0'})${escapetool.h}end"/>
249 <span class="buttonwrapper"><input type="submit" class="button" value="$escapetool.xml(
250 $services.localization.render('platform.xclass.defaultClassSheet.sheets.create'))"/></span>
251 </div>
252 </form>
253 {{/html}}
254 #else
255 #set($defaultClassSheetDoc = $xwiki.getDocument($defaultClassSheetReference))
256 #if($classSheetReferences.isEmpty() && !$defaultClassSheetDoc.getObject('XWiki.SheetClass'))
257 ## The sheet is not bound to the class.
258 #set($xredirect = $xwiki.relativeRequestURL)
259 #set($defaultClassSheetStringReference = $services.model.serialize($defaultClassSheetReference, "default"))
260 #set($bindURL = $doc.getURL('view', "bindSheet=${escapetool.url($defaultClassSheetStringReference)}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}"))
261 {{warning}}
262 {{translation key="platform.xclass.defaultClassSheet.sheets.notBound"/}} ##
263 #if ($hasEdit)
264 {{html}}
265 <a href="$escapetool.xml($bindURL)">##
266 $escapetool.xml($services.localization.render('platform.xclass.defaultClassSheet.sheets.bind')) »##
267 </a>.
268 {{/html}}
269 #end
270 {{/warning}}
271
272 #end
273 #if ($classSheetReferences.size() < 2)
274 #set($classSheetDoc = $defaultClassSheetDoc)
275 #if(!$classSheetReferences.isEmpty())
276 #set($classSheetDoc = $xwiki.getDocument($classSheetReferences.get(0)))
277 #end
278 #set ($sheetPath = "#hierarchy($classSheetDoc.documentReference, {'plain': true, 'local': true, 'limit': 4})")
279 #set ($classSheetLink = "$services.localization.render('platform.xclass.defaultClassSheet.sheets.view', [$sheetPath.trim()]) »")
280 #set ($classSheetLink = $services.rendering.escape($classSheetLink, 'xwiki/2.1'))
281 #set ($classSheetLink = $services.rendering.escape($classSheetLink, 'xwiki/2.1'))
282 #set ($classSheetText = ${classSheetDoc.fullName})
283 #set ($classSheetText = $services.rendering.escape($classSheetText, 'xwiki/2.1'))
284 [[$classSheetLink>>$classSheetText]]
285 #else
286 {{translation key="platform.xclass.defaultClassSheet.sheets.list"/}}
287
288 #foreach($classSheetReference in $classSheetReferences)
289 * [[$services.model.serialize($classSheetReference, "default")]]
290 #end
291 #end
292 #end
293
294 (% id="HClassTemplate" %)
295 = {{translation key="platform.xclass.defaultClassSheet.template.heading"/}} =
296
297 {{info}}
298 #set ($message = $services.localization.render('platform.xclass.defaultClassSheet.template.description', ['__START_EM__', '__END_EM__']))
299 #set ($message = $escapetool.xml($message))
300 ## First escape the content of the translation, then replace the placeholders with content that would
301 ## otherwise be escaped during the first escaping.
302 {{html}}$message.replace('__START_EM__', '<em>').replace('__END_EM__', '</em>'){{/html}}
303 {{/info}}
304
305 #if (!$hasClassTemplate)
306 {{html}}
307 <form action="$escapetool.xml($classTemplateDoc.getURL('save', 'editor=wiki'))" method="post">
308 <div>
309 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
310 <input type="hidden" name="parent" value="$escapetool.xml(${doc.fullName})"/>
311 <input type="hidden" name="xredirect" value="$escapetool.xml(${doc.URL})"/>
312 <input type="hidden" name="title" value="$escapetool.xml($className) Template"/>
313 <span class="buttonwrapper"><input type="submit" class="button" value="$escapetool.xml(
314 $services.localization.render('platform.xclass.defaultClassSheet.template.create'))"/></span>
315 </div>
316 </form>
317 {{/html}}
318 #else
319 #if(!$classTemplateDoc.getObject(${doc.fullName}))
320 #set($xredirect = $xwiki.relativeRequestURL)
321 #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${escapetool.url($doc.fullName)}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}"))
322 {{warning}}
323 #set ($message = $services.localization.render('platform.xclass.defaultClassSheet.template.missingObject', ['__CLASS_NAME__']))
324 #set ($message = $escapetool.xml($message))
325 {{html}}
326 ## First escape the content of the translation, then replace the placeholders with content that would
327 ## otherwise be escaped during the first escaping.
328 $message.replace('__CLASS_NAME__', "<em>$escapetool.xml($className)</em>")
329 <a href="$escapetool.xml($createUrl)">##
330 $escapetool.xml($services.localization.render('platform.xclass.defaultClassSheet.template.addObject', [$className])) »##
331 </a>.
332 {{/html}}
333 {{/warning}}
334
335 #end
336 #set ($templatePath = "#hierarchy($classTemplateDoc.documentReference, {'plain': true, 'local': true, 'limit': 4})")
337 #set ($templateDocLink = "$services.localization.render('platform.xclass.defaultClassSheet.template.view', [$templatePath.trim()]) »")
338 #set ($templateDocLink = $services.rendering.escape($templateDocLink, 'xwiki/2.1'))
339 #set ($templateDocLink = $services.rendering.escape($templateDocLink, 'xwiki/2.1'))
340 #set ($templateDocText = "${classTemplateDoc.fullName}")
341 ## First escape the xwiki/2.1 syntax of the translation, then replace the placeholders with content that would
342 ## otherwise be escaped during the first escaping.
343 #set ($templateDocText = $services.rendering.escape($templateDocText, 'xwiki/2.1'))
344 [[$templateDocLink>>$templateDocText]]
345 #end
346 ## Create a template provider only if a template for the current class exists.
347 #if ($classTemplateDoc.getObject(${doc.fullName}))
348 (% id="HClassTemplateProvider" %)
349 = {{translation key="platform.xclass.defaultClassSheet.templateProvider.heading"/}} =
350
351 {{info}}
352 #set ($message = $services.localization.render('platform.xclass.defaultClassSheet.templateProvider.description', ['__EM__']))
353 #set ($message = $services.rendering.escape($message, 'xwiki/2.1'))
354 ## First escape the xwiki/2.1 syntax of the translation, then replace the placeholders with content that would
355 ## otherwise be escaped during the first escaping.
356 ## The replacement key is itself escaped, and it's escaped form needs to be used for the replacement.
357 $message.replace('~_~_~E~M~_~_', '//')
358 {{/info}}
359
360 #if (!$hasClassTemplateProvider)
361 #set ($templateProviderClassName = 'XWiki.TemplateProviderClass')
362 ## Do the page creation and object addition in one step, providing some default values.
363 ## In order to get the root space of the class and use it as restrictionSpace, we need to be sure that we have
364 ## the expected result for multiple level hierarchies, like MyApplication.Code.MyApplicationClass. In this case,
365 ## the template provider in enabled in MyApplication space.
366 #set ($restrictionSpace = $doc.documentReference.spaceReferences.get(0).name)
367 #set ($createUrlQueryString = $escapetool.url({
368 'classname': $templateProviderClassName,
369 'xredirect': $xwiki.relativeRequestURL,
370 'form_token': $services.csrf.token,
371 "${templateProviderClassName}_name": $className,
372 "${templateProviderClassName}_description":
373 $services.localization.render('platform.xclass.templateProvider.defaultDescription', [$className]),
374 "${templateProviderClassName}_template": $classTemplateDoc,
375 "${templateProviderClassName}_visibilityRestrictions": $restrictionSpace}))
376 #set ($createUrl = $classTemplateProviderDoc.getURL('objectadd', $createUrlQueryString))
377 {{html}}
378 <form action="$escapetool.xml($classTemplateProviderDoc.getURL('save', 'editor=wiki'))" method="post">
379 <div>
380 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
381 <input type="hidden" name="parent" value="$escapetool.xml(${doc.fullName})"/>
382 <input type="hidden" name="xredirect" value="$escapetool.xml($createUrl)"/>
383 <input type="hidden" name="title" value="$escapetool.xml($className) Template Provider"/>
384 <span class="buttonwrapper"><input type="submit" class="button" value="$escapetool.xml(
385 $services.localization.render('platform.xclass.defaultClassSheet.templateProvider.create'))"/></span>
386 </div>
387 </form>
388 {{/html}}
389 #else
390 #set ($templateProviderPath = "#hierarchy($classTemplateProviderDoc.documentReference, {'plain': true, 'local': true, 'limit': 4})")
391 #set ($linkTarget = "$services.localization.render('platform.xclass.defaultClassSheet.templateProvider.view', [$templateProviderPath.trim()]) »")
392 #set ($linkTarget = $services.rendering.escape($linkTarget, 'xwiki/2.1'))
393 #set ($linkTarget = $services.rendering.escape($linkTarget, 'xwiki/2.1'))
394 #set ($linkLabel = $services.rendering.escape(${classTemplateProviderDoc.fullName}, 'xwiki/2.1'))
395 [[$linkTarget>>$linkLabel]]
396 #end
397 #end
398
399 #end## !$isSheet
400 {{/velocity}}