General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
ClassSheet
Search
default
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Wiki Home
»
XWiki Space
»
Data types
»
Default Class Sheet
Wiki source code of
Default Class Sheet
Last modified by
Administrator
on 2011/11/06 20:09
Content
·
Comments
(0)
·
Annotations
(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: #if($doc.name.endsWith('Class')) 39: #set($className = $doc.name.substring(0, $doc.name.lastIndexOf('Class'))) 40: #else 41: #set($className = $doc.name) 42: #end 43: ## Determine the class sheets. 44: #set($classSheetReferences = $services.sheet.getClassSheets($doc)) 45: #if ($classSheetReferences.isEmpty()) 46: ## There is no class sheet explicitly bound to this class. Fall-back on naming convention. 47: ## Before XWiki 2.0, the default class sheet was suffixed with "ClassSheet". Since 2.0, the suffix is just "Sheet". 48: #set($defaultClassSheetReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassSheet")) 49: #if(!$xwiki.exists($defaultClassSheetReference)) 50: #set($discard = $defaultClassSheetReference.setName("${className}Sheet")) 51: #end 52: #end 53: ## Determine the template using naming convention. 54: ## Before XWiki 2.0, the default class template was suffixed with "ClassTemplate". Since 2.0, the suffix is just "Template". 55: #set($classTemplateReference = $services.model.createDocumentReference($doc.wiki, $doc.space, "${className}ClassTemplate")) 56: #if(!$xwiki.exists($classTemplateReference)) 57: #set($discard = $classTemplateReference.setName("${className}Template")) 58: #end 59: #set($classTemplateDoc = $xwiki.getDocument($classTemplateReference)) 60: #set($hasClassSheets = !$classSheetReferences.isEmpty() || $xwiki.exists($defaultClassSheetReference)) 61: #set($hasClassTemplate = !$classTemplateDoc.isNew()) 62: #if(!$defaultSpace) 63: #set($defaultSpace = 'Main') 64: #end 65: #if(!$defaultParent) 66: #set($defaultParent = ${doc.fullName}) 67: #end 68: 69: #if($doc.getxWikiClass().properties.size() == 0) 70: {{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}} 71: #else 72: = Class properties = 73: #foreach($property in $doc.getxWikiClass().properties) 74: * $property.prettyName (${property.name}: $xwiki.metaclass.get($property.classType).prettyName) 75: #end 76: * //You can use the class editor to {{html}}<a href="$doc.getURL('edit', 'editor=class')">add or modify the class properties</a>{{/html}}.// 77: 78: #end 79: #if ($hasClassSheets && $hasClassTemplate) 80: = Create a new document = 81: 82: #if("$!targetDocName" != '' && $xwiki.exists($targetDocName)) 83: {{warning}}The target document already exists. Please choose a different name, or [[view the existing document>>$targetDocName]]{{/warning}} 84: #elseif("$!targetDocName" != '') 85: {{warning}}You don't have permission to create that document{{/warning}} 86: #end 87: 88: {{html}} 89: <form action="" id="newdoc" method="post"> 90: <div> 91: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 92: <input type="hidden" name="parent" value="${defaultParent}"/> 93: <input type="hidden" name="template" value="${classTemplateDoc}"/> 94: <input type="hidden" name="sheet" value="1"/> 95: <label for="spaceName">Space: </label><input type="text" id="spaceName" name="spaceName" value="${defaultSpace}" size="8"/> 96: <label for="docName">Document: </label><input type="text" id="docName" name="docName" value="Document name" class="withTip"'/> 97: <span class="buttonwrapper"><input type="submit" value="Create this document" class="button"/></span> 98: </div> 99: </form> 100: {{/html}} 101: 102: = Existing documents = 103: 104: #set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.fullName}' and obj.name<>'${classTemplateDoc.fullName}'") 105: #foreach ($item in $xwiki.searchDocuments($sql)) 106: * [[$item]] 107: #end 108: #end ## has class sheet and class template 109: = The class sheets = 110: 111: #if (!$hasClassSheets || !$hasClassTemplate) 112: Before using this class you must first create a sheet and a template for it. Follow the instructions below to do this. 113: #end 114: 115: {{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}} 116: 117: #if(!$hasClassSheets) 118: {{html}} 119: <form action="$xwiki.getURL($defaultClassSheetReference, 'save', 'editor=wiki')" method="post"> 120: <div> 121: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 122: <input type="hidden" name="parent" value="${doc.fullName}"/> 123: <input type="hidden" name="xredirect" value="${doc.URL}"/> 124: <input type="hidden" name="content" value="$escapetool.xml($xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass', $doc.fullName))"/> 125: <input type="hidden" name="title" value="$doc.name Sheet"/> 126: <span class="buttonwrapper"><input type="submit" value="Create the document sheet" class="button"/></span> 127: </div> 128: </form> 129: {{/html}} 130: #else 131: #set($defaultClassSheetDoc = $xwiki.getDocument($defaultClassSheetReference)) 132: #if($classSheetReferences.isEmpty() && !$defaultClassSheetDoc.getObject('XWiki.SheetClass')) 133: ## The sheet is not bound to the class. 134: #set($xredirect = $request.getRequestURL()) 135: #set($defaultClassSheetStringReference = $services.model.serialize($defaultClassSheetReference, "default")) 136: #set($bindURL = $doc.getURL('view', "bindSheet=${escapetool.url($defaultClassSheetStringReference)}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) 137: {{warning}} 138: 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}} 139: {{/warning}} 140: 141: #end 142: #if ($classSheetReferences.size() < 2) 143: #set($classSheetDoc = $defaultClassSheetDoc) 144: #if(!$classSheetReferences.isEmpty()) 145: #set($classSheetDoc = $xwiki.getDocument($classSheetReferences.get(0))) 146: #end 147: [[View the sheet document (${classSheetDoc.fullName}) »>>${classSheetDoc.fullName}]] 148: #else 149: The following class sheets are bound to this class: 150: 151: #foreach($classSheetReference in $classSheetReferences) 152: * [[$services.model.serialize($classSheetReference, "default")]] 153: #end 154: #end 155: #end 156: 157: = The class template = 158: 159: {{info}}The //Template// is the document used as the model for documents of this data type. It contains an instance of your //Class//.{{/info}} 160: 161: #if (!$hasClassTemplate) 162: {{html}} 163: <form action="$classTemplateDoc.getURL('save', 'editor=wiki')" method="post"> 164: <div> 165: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 166: <input type="hidden" name="parent" value="${doc.fullName}"/> 167: <input type="hidden" name="xredirect" value="${doc.URL}"/> 168: <input type="hidden" name="title" value="$doc.name Template"/> 169: <span class="buttonwrapper"><input type="submit" value="Create the document template" class="button"/></span> 170: </div> 171: </form> 172: {{/html}} 173: #else 174: #if(!$classTemplateDoc.getObject(${doc.fullName})) 175: #set($xredirect = $request.getRequestURL()) 176: #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&xredirect=${escapetool.url($xredirect)}&form_token=$!{services.csrf.getToken()}")) 177: {{warning}} 178: The template does not contain an object of type //$doc.fullName//. {{html}}<a href="$createUrl">Add a ${className} object to the template »</a>.{{/html}} 179: {{/warning}} 180: 181: #end 182: [[View the template document (${classTemplateDoc.fullName}) »>>${classTemplateDoc.fullName}]] 183: #end 184: 185: #end ## doc == XWiki.ClassSheet 186: {{/velocity}}