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 anzeigen {{velocity}} ## This document can be copied in order to be customized so we cannot rely on its name to determine if the currently ## displayed document is a class or the class sheet itself. We look for the sheet descriptor instead. #set ($isSheet = $doc.getObject('XWiki.SheetDescriptorClass')) #if ($isSheet) ## 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" != '' && $hasEdit) #if ($services.csrf.isTokenValid($request.getParameter('form_token'))) ## 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) #else $response.sendRedirect($services.csrf.getResubmissionURL()) #end ## Stop processing, since we already sent a redirect. #stop #elseif("$!request.docName" != '') ## Request for creating a new instance. We don't actually create a new instance here, we just redirect to the edit mode. #set($targetDocName = "${request.spaceName}.${request.docName}") #if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $xcontext.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=$!escapetool.url($request.template)&parent=$!escapetool.url($request.parent)&title=$!escapetool.url($request.docName)")) ## Stop processing, since we already sent a redirect. #stop #end #end {{/velocity}} {{velocity}} ## If this sheet 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 reference="" /}} #end {{/velocity}} {{velocity}} #if (!$isSheet) #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=? and obj.name<>?") #foreach ($item in $services.query.hql($sql).bindValues([$doc.fullName, $classTemplateDoc.fullName]).execute()) * [[$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}"/> #set ($sheetContent = $xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass', $doc.fullName)) ## We have to encode the new line characters in order to preserve them, otherwise they are replace with a ## space when the HTML is cleaned. ## FIXME: Use a dedicated escape tool method when XCOMMONS-405 is implemented. #set ($sheetContent = $escapetool.xml($sheetContent).replaceAll("\n", '&#10;')) <input type="hidden" name="content" value="$sheetContent"/> <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 = $xwiki.relativeRequestURL) #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.#if ($hasEdit) {{html}}<a href="$bindURL">Bind the sheet to the class »</a>.{{/html}}#end {{/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 = $xwiki.relativeRequestURL) #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&amp;xredirect=${escapetool.url($xredirect)}&amp;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 ## !$isSheet {{/velocity}}

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