General Actions:
Log-in
Register
Add
▼
:
Space
Page
Comment to Page
Attachment to Page
Wiki:
Cops
▼
:
Administration
»
Space:
XWiki
▼
:
Administer Space
Delete
»
Page:
ClassSheet
▼
:
Copy
Search
default
Page Actions:
Edit
▼
:
Wiki
WYSIWYG
Inline form
Access Rights
Objects
Class
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
Export as XAR
More actions
▼
:
Print preview
View Source
WebHome
»
Data types
»
Default Class Sheet
Wiki source code of
Default Class Sheet
Last modified by XWikiGuest on 2021/09/20 02:53
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{{velocity}} #if($doc.fullName == 'XWiki.ClassSheet') ## Viewing the sheet document itself You can edit this document to change the default presentation of classes, or you can copy it to create a customized view just for one or several classes. #elseif("$!request.bindSheet" != '') ## Bind the sheet to the class #set($classSheetReference = $services.model.resolveDocument($request.bindSheet)) #if($services.sheet.bindClassSheet($doc, $classSheetReference)) $doc.save("Bind class sheet.") #end $response.sendRedirect($request.xredirect) ## Stop processing, since we already sent a redirect. #stop #elseif("$!request.docName" != '') ## Request for creating a new instance #set($targetDocName = "${request.spaceName}.${request.docName}") #if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $context.user, $targetDocName)) ## Compute the default edit mode to ensure backward compatibility with documents still using the deprecated inline action. #set($editAction = $xwiki.getDocument($request.template).getDefaultEditMode()) $response.sendRedirect($xwiki.getURL($targetDocName, $editAction, "template=${request.template}&parent=${request.parent}")) ## Stop processing, since we already sent a redirect. #stop #end #end {{/velocity}} {{velocity}} ## If XWiki.ClassSheet is explicitly bound to the displayed class then print the class document content before the ## sheet output. Class authors can put the description of the class in the class document content. #set($classSheetReference = $services.model.createDocumentReference($doc.wiki, 'XWiki', 'ClassSheet')) #if($services.sheet.getDocumentSheets($doc).contains($classSheetReference)) {{include document="$doc.name" /}} #end {{/velocity}} {{velocity}} #if($doc.fullName != 'XWiki.ClassSheet') #set($className = $stringtool.removeEnd($doc.name, 'Class')) ## Determine the class sheets. #set($classSheetReferences = $services.sheet.getClassSheets($doc)) #if ($classSheetReferences.isEmpty()) ## There is no class sheet explicitly bound to this class. Fall-back on naming convention. ## Before XWiki 2.0, the default class sheet was suffixed with "ClassSheet". Since 2.0, the suffix is just "Sheet". #set($defaultClassSheetReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassSheet")) #if(!$xwiki.exists($defaultClassSheetReference)) #set($defaultClassSheetReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}Sheet")) #end #end ## Determine the template using naming convention. ## Before XWiki 2.0, the default class template was suffixed with "ClassTemplate". Since 2.0, the suffix is just "Template". #set($classTemplateReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassTemplate")) #if(!$xwiki.exists($classTemplateReference)) #set($classTemplateReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}Template")) #end #set($classTemplateDoc = $xwiki.getDocument($classTemplateReference)) #set($hasClassSheets = !$classSheetReferences.isEmpty() || $xwiki.exists($defaultClassSheetReference)) #set($hasClassTemplate = !$classTemplateDoc.isNew()) #if(!$defaultSpace) #set($defaultSpace = 'Main') #end #if(!$defaultParent) #set($defaultParent = ${doc.fullName}) #end #if($doc.getxWikiClass().properties.size() == 0) {{warning}}The class does not have any properties yet. You can use the {{html}}<a href="$doc.getURL('edit', 'editor=class')">class editor</a>{{/html}} to define them.{{/warning}} #else = Class properties = #foreach($property in $doc.getxWikiClass().properties) * $property.prettyName (${property.name}: $xwiki.metaclass.get($property.classType).prettyName) #end * //You can use the class editor to {{html}}<a href="$doc.getURL('edit', 'editor=class')">add or modify the class properties</a>{{/html}}.// #end #if ($hasClassSheets && $hasClassTemplate) = Create a new document = #if("$!targetDocName" != '' && $xwiki.exists($targetDocName)) {{warning}}The target document already exists. Please choose a different name, or [[view the existing document>>$targetDocName]]{{/warning}} #elseif("$!targetDocName" != '') {{warning}}You don't have permission to create that document{{/warning}} #end {{html}} <form action="" id="newdoc" method="post"> <div> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> <input type="hidden" name="parent" value="${defaultParent}"/> <input type="hidden" name="template" value="${classTemplateDoc}"/> <input type="hidden" name="sheet" value="1"/> <label for="spaceName">Space: </label><input type="text" id="spaceName" name="spaceName" value="${defaultSpace}" size="8"/> <label for="docName">Document: </label><input type="text" id="docName" name="docName" value="Document name" class="withTip"'/> <span class="buttonwrapper"><input type="submit" value="Create this document" class="button"/></span> </div> </form> {{/html}} = Existing documents = #set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.fullName}' and obj.name<>'${classTemplateDoc.fullName}'") #foreach ($item in $xwiki.searchDocuments($sql)) * [[$item]] #end #end ## has class sheet and class template = The class sheets = #if (!$hasClassSheets || !$hasClassTemplate) Before using this class you must first create a sheet and a template for it. Follow the instructions below to do this. #end {{info}}The //Sheet// allows to control the presentation of documents of this data type. You can use the default presentation, which enumerates all the available fields, or you can design your own presentation. You can also choose different presentations for the viewing and for the editing modes.{{/info}} #if(!$hasClassSheets) {{html}} <form action="$xwiki.getURL($defaultClassSheetReference, 'save', 'editor=wiki')" method="post"> <div> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> <input type="hidden" name="parent" value="${doc.fullName}"/> <input type="hidden" name="xredirect" value="${doc.URL}"/> <input type="hidden" name="content" value="$escapetool.xml($xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass', $doc.fullName))"/> <input type="hidden" name="title" value="${escapetool.h}if(${escapetool.d}doc.name == '$escapetool.xml($defaultClassSheetReference.name)')$escapetool.xml($className) Sheet${escapetool.h}{else}${escapetool.d}services.display.title(${escapetool.d}doc, {'displayerHint': 'default'})${escapetool.h}end"/> <span class="buttonwrapper"><input type="submit" value="Create the document sheet" class="button"/></span> </div> </form> {{/html}} #else #set($defaultClassSheetDoc = $xwiki.getDocument($defaultClassSheetReference)) #if($classSheetReferences.isEmpty() && !$defaultClassSheetDoc.getObject('XWiki.SheetClass')) ## The sheet is not bound to the class. #set($xredirect = $request.getRequestURL()) #set($defaultClassSheetStringReference = $services.model.serialize($defaultClassSheetReference, "default")) #set($bindURL = $doc.getURL('view', "bindSheet=${escapetool.url($defaultClassSheetStringReference)}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) {{warning}} The sheet is not bound to the class so it won't be applied automatically when a document that has an object of this class is displayed. {{html}}<a href="$bindURL">Bind the sheet to the class »</a>.{{/html}} {{/warning}} #end #if ($classSheetReferences.size() < 2) #set($classSheetDoc = $defaultClassSheetDoc) #if(!$classSheetReferences.isEmpty()) #set($classSheetDoc = $xwiki.getDocument($classSheetReferences.get(0))) #end [[View the sheet document (${classSheetDoc.fullName}) »>>${classSheetDoc.fullName}]] #else The following class sheets are bound to this class: #foreach($classSheetReference in $classSheetReferences) * [[$services.model.serialize($classSheetReference, "default")]] #end #end #end = The class template = {{info}}The //Template// is the document used as the model for documents of this data type. It contains an instance of your //Class//.{{/info}} #if (!$hasClassTemplate) {{html}} <form action="$classTemplateDoc.getURL('save', 'editor=wiki')" method="post"> <div> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> <input type="hidden" name="parent" value="${doc.fullName}"/> <input type="hidden" name="xredirect" value="${doc.URL}"/> <input type="hidden" name="title" value="$className Template"/> <span class="buttonwrapper"><input type="submit" value="Create the document template" class="button"/></span> </div> </form> {{/html}} #else #if(!$classTemplateDoc.getObject(${doc.fullName})) #set($xredirect = $request.getRequestURL()) #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) {{warning}} The template does not contain an object of type //$doc.fullName//. {{html}}<a href="$createUrl">Add a ${className} object to the template »</a>.{{/html}} {{/warning}} #end [[View the template document (${classTemplateDoc.fullName}) »>>${classTemplateDoc.fullName}]] #end #end ## doc == XWiki.ClassSheet {{/velocity}}