Allgemeine Aktionen:
Anmelden
Registrieren
Start ▼: Wiki Verzeichnis
»
Bereich: XWiki
»
Seite: ClassSheet
default
Aktionen:
Exportieren ▼: Als PDF exportieren Als RTF exportieren Als HTML exportieren
Weitere Aktionen ▼: Druckvorschau Zeige den Quellcode
Willkommen bei bytebang » XWiki Bereich » Data types » Default Class Sheet

# Wiki-Quellcode von Default Class Sheet

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

(c) 2026, by bytebang e.U. - Impressum - Datenschutz / Nutzungsbedingungen
-