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
Hide line numbers
1: {{velocity}} 2: #if($doc.fullName == 'XWiki.ClassSheet') 3: ## Viewing the sheet document itself 4: 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. 5: #elseif("$!request.bindSheet" != '') 6: ## Bind the sheet to the class 7: #set($classSheetReference = $services.model.resolveDocument($request.bindSheet)) 8: #if($services.sheet.bindClassSheet($doc, $classSheetReference)) 9: $doc.save("Bind class sheet.") 10: #end 11: $response.sendRedirect($request.xredirect) 12: ## Stop processing, since we already sent a redirect. 13: #stop 14: #elseif("$!request.docName" != '') 15: ## Request for creating a new instance 16: #set($targetDocName = "${request.spaceName}.${request.docName}") 17: #if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $context.user, $targetDocName)) 18: ## Compute the default edit mode to ensure backward compatibility with documents still using the deprecated inline action. 19: #set($editAction = $xwiki.getDocument($request.template).getDefaultEditMode()) 20: $response.sendRedirect($xwiki.getURL($targetDocName, $editAction, "template=${request.template}&parent=${request.parent}")) 21: ## Stop processing, since we already sent a redirect. 22: #stop 23: #end 24: #end 25: {{/velocity}} 26: 27: {{velocity}} 28: ## If XWiki.ClassSheet is explicitly bound to the displayed class then print the class document content before the 29: ## sheet output. Class authors can put the description of the class in the class document content. 30: #set($classSheetReference = $services.model.createDocumentReference($doc.wiki, 'XWiki', 'ClassSheet')) 31: #if($services.sheet.getDocumentSheets($doc).contains($classSheetReference)) 32: {{include document="$doc.name" /}} 33: #end 34: {{/velocity}} 35: 36: {{velocity}} 37: #if($doc.fullName != 'XWiki.ClassSheet') 38: #set($className = $stringtool.removeEnd($doc.name, 'Class')) 39: ## Determine the class sheets. 40: #set($classSheetReferences = $services.sheet.getClassSheets($doc)) 41: #if ($classSheetReferences.isEmpty()) 42: ## There is no class sheet explicitly bound to this class. Fall-back on naming convention. 43: ## Before XWiki 2.0, the default class sheet was suffixed with "ClassSheet". Since 2.0, the suffix is just "Sheet". 44: #set($defaultClassSheetReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassSheet")) 45: #if(!$xwiki.exists($defaultClassSheetReference)) 46: #set($defaultClassSheetReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}Sheet")) 47: #end 48: #end 49: ## Determine the template using naming convention. 50: ## Before XWiki 2.0, the default class template was suffixed with "ClassTemplate". Since 2.0, the suffix is just "Template". 51: #set($classTemplateReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassTemplate")) 52: #if(!$xwiki.exists($classTemplateReference)) 53: #set($classTemplateReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}Template")) 54: #end 55: #set($classTemplateDoc = $xwiki.getDocument($classTemplateReference)) 56: #set($hasClassSheets = !$classSheetReferences.isEmpty() || $xwiki.exists($defaultClassSheetReference)) 57: #set($hasClassTemplate = !$classTemplateDoc.isNew()) 58: #if(!$defaultSpace) 59: #set($defaultSpace = 'Main') 60: #end 61: #if(!$defaultParent) 62: #set($defaultParent = ${doc.fullName}) 63: #end 64: 65: #if($doc.getxWikiClass().properties.size() == 0) 66: {{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}} 67: #else 68: = Class properties = 69: #foreach($property in $doc.getxWikiClass().properties) 70: * $property.prettyName (${property.name}: $xwiki.metaclass.get($property.classType).prettyName) 71: #end 72: * //You can use the class editor to {{html}}<a href="$doc.getURL('edit', 'editor=class')">add or modify the class properties</a>{{/html}}.// 73: 74: #end 75: #if ($hasClassSheets && $hasClassTemplate) 76: = Create a new document = 77: 78: #if("$!targetDocName" != '' && $xwiki.exists($targetDocName)) 79: {{warning}}The target document already exists. Please choose a different name, or [[view the existing document>>$targetDocName]]{{/warning}} 80: #elseif("$!targetDocName" != '') 81: {{warning}}You don't have permission to create that document{{/warning}} 82: #end 83: 84: {{html}} 85: <form action="" id="newdoc" method="post"> 86: <div> 87: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 88: <input type="hidden" name="parent" value="${defaultParent}"/> 89: <input type="hidden" name="template" value="${classTemplateDoc}"/> 90: <input type="hidden" name="sheet" value="1"/> 91: <label for="spaceName">Space: </label><input type="text" id="spaceName" name="spaceName" value="${defaultSpace}" size="8"/> 92: <label for="docName">Document: </label><input type="text" id="docName" name="docName" value="Document name" class="withTip"'/> 93: <span class="buttonwrapper"><input type="submit" value="Create this document" class="button"/></span> 94: </div> 95: </form> 96: {{/html}} 97: 98: = Existing documents = 99: 100: #set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.fullName}' and obj.name<>'${classTemplateDoc.fullName}'") 101: #foreach ($item in $xwiki.searchDocuments($sql)) 102: * [[$item]] 103: #end 104: #end ## has class sheet and class template 105: = The class sheets = 106: 107: #if (!$hasClassSheets || !$hasClassTemplate) 108: Before using this class you must first create a sheet and a template for it. Follow the instructions below to do this. 109: #end 110: 111: {{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}} 112: 113: #if(!$hasClassSheets) 114: {{html}} 115: <form action="$xwiki.getURL($defaultClassSheetReference, 'save', 'editor=wiki')" method="post"> 116: <div> 117: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 118: <input type="hidden" name="parent" value="${doc.fullName}"/> 119: <input type="hidden" name="xredirect" value="${doc.URL}"/> 120: <input type="hidden" name="content" value="$escapetool.xml($xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass', $doc.fullName))"/> 121: <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"/> 122: <span class="buttonwrapper"><input type="submit" value="Create the document sheet" class="button"/></span> 123: </div> 124: </form> 125: {{/html}} 126: #else 127: #set($defaultClassSheetDoc = $xwiki.getDocument($defaultClassSheetReference)) 128: #if($classSheetReferences.isEmpty() && !$defaultClassSheetDoc.getObject('XWiki.SheetClass')) 129: ## The sheet is not bound to the class. 130: #set($xredirect = $request.getRequestURL()) 131: #set($defaultClassSheetStringReference = $services.model.serialize($defaultClassSheetReference, "default")) 132: #set($bindURL = $doc.getURL('view', "bindSheet=${escapetool.url($defaultClassSheetStringReference)}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) 133: {{warning}} 134: 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}} 135: {{/warning}} 136: 137: #end 138: #if ($classSheetReferences.size() < 2) 139: #set($classSheetDoc = $defaultClassSheetDoc) 140: #if(!$classSheetReferences.isEmpty()) 141: #set($classSheetDoc = $xwiki.getDocument($classSheetReferences.get(0))) 142: #end 143: [[View the sheet document (${classSheetDoc.fullName}) »>>${classSheetDoc.fullName}]] 144: #else 145: The following class sheets are bound to this class: 146: 147: #foreach($classSheetReference in $classSheetReferences) 148: * [[$services.model.serialize($classSheetReference, "default")]] 149: #end 150: #end 151: #end 152: 153: = The class template = 154: 155: {{info}}The //Template// is the document used as the model for documents of this data type. It contains an instance of your //Class//.{{/info}} 156: 157: #if (!$hasClassTemplate) 158: {{html}} 159: <form action="$classTemplateDoc.getURL('save', 'editor=wiki')" method="post"> 160: <div> 161: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 162: <input type="hidden" name="parent" value="${doc.fullName}"/> 163: <input type="hidden" name="xredirect" value="${doc.URL}"/> 164: <input type="hidden" name="title" value="$className Template"/> 165: <span class="buttonwrapper"><input type="submit" value="Create the document template" class="button"/></span> 166: </div> 167: </form> 168: {{/html}} 169: #else 170: #if(!$classTemplateDoc.getObject(${doc.fullName})) 171: #set($xredirect = $request.getRequestURL()) 172: #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) 173: {{warning}} 174: The template does not contain an object of type //$doc.fullName//. {{html}}<a href="$createUrl">Add a ${className} object to the template »</a>.{{/html}} 175: {{/warning}} 176: 177: #end 178: [[View the template document (${classTemplateDoc.fullName}) »>>${classTemplateDoc.fullName}]] 179: #end 180: 181: #end ## doc == XWiki.ClassSheet 182: {{/velocity}}