Wiki source code of Default Class Sheet

Last modified by Admin on 2009/09/17 14:40

Show last authors
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 #else
6 #if("$!request.docName" != '')
7 ## Request for creating a new instance
8 #set($targetDocName = "${request.spaceName}.${request.docName}")
9 #if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $context.user, $targetDocName))
10 $response.sendRedirect($xwiki.getURL($targetDocName, 'inline', "template=${request.template}&parent=${request.parent}"))
11 ## Stop processing, since we already sent a redirect.
12 #stop
13 #end
14 #end
15 #if($doc.name.endsWith('Class'))
16 #set($className = $doc.name.substring(0, $doc.name.lastIndexOf('Class')))
17 #else
18 #set($className = $doc.name)
19 #end
20 #set($classSheetDoc = $xwiki.getDocument("${doc.space}.${className}Sheet"))
21 ## Before XWiki 2.0, the default class sheet was suffixed with "ClassSheet". Since 2.0, the suffix is just "Sheet".
22 #if($xwiki.exists("${doc.space}.${className}ClassSheet"))
23 #set($classSheetDoc = $xwiki.getDocument("${doc.space}.${className}ClassSheet"))
24 #else
25 #set($classSheetDoc = $xwiki.getDocument("${doc.space}.${className}Sheet"))
26 #end
27 ## Before XWiki 2.0, the default class template was suffixed with "ClassTemplate". Since 2.0, the suffix is just "Template".
28 #if($xwiki.exists("${doc.space}.${className}ClassTemplate"))
29 #set($classTemplateDoc = $xwiki.getDocument("${doc.space}.${className}ClassTemplate"))
30 #else
31 #set($classTemplateDoc = $xwiki.getDocument("${doc.space}.${className}Template"))
32 #end
33 #set($classSheetExists = !($classSheetDoc.isNew()))
34 #set($classTemplateExists = !($classTemplateDoc.isNew()))
35 #if(!$defaultSpace)
36 #set($defaultSpace = 'Main')
37 #end
38 #if(!$defaultParent)
39 #set($defaultParent = ${doc.fullName})
40 #end
41 = Class: $className =
42
43 #if($doc.getxWikiClass().properties.size() == 0)
44 {{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}}
45 #else
46 Class properties:
47 #foreach($property in $doc.getxWikiClass().properties)
48 * $property.prettyName (${property.name}: $xwiki.metaclass.get($property.classType).prettyName)
49 #end
50 * //You can use the class editor to {{html}}<a href="$doc.getURL('edit', 'editor=class')">add or modify the class properties</a>{{/html}}.//
51
52 #end
53 #if ($classSheetExists && $classTemplateExists)
54 = Create a new document =
55
56 #if("$!targetDocName" != '' && $xwiki.exists($targetDocName))
57 {{warning}}The target document already exists. Please choose a different name, or [[view the existing document>>$targetDocName]]{{/warning}}
58 #elseif("$!targetDocName" != '')
59 {{warning}}You don't have permission to create that document{{/warning}}
60 #end
61
62 {{html}}
63 <form action="" id="newdoc" method="post">
64 <div>
65 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
66 <input type="hidden" name="parent" value="${defaultParent}"/>
67 <input type="hidden" name="template" value="${classTemplateDoc}"/>
68 <input type="hidden" name="sheet" value="1"/>
69 <label for="spaceName">Space: </label><input type="text" id="spaceName" name="spaceName" value="${defaultSpace}" size="8"/>
70 <label for="docName">Document: </label><input type="text" id="docName" name="docName" value="Document name" class="withTip"'/>
71 <span class="buttonwrapper"><input type="submit" value="Create this document" class="button"/></span>
72 </div>
73 </form>
74 {{/html}}
75
76 = Existing documents =
77
78 #set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.fullName}' and obj.name<>'${classTemplateDoc.fullName}'")
79 #foreach ($item in $xwiki.searchDocuments($sql))
80 * [[$item]]
81 #end
82 #end ## class sheet and class template exist
83 = The class sheet =
84
85 #if (!$classSheetExists || !$classTemplateExists)
86 Before using this class you must first create the sheet and template for it. Follow the instructions below to do this.
87 #end
88
89 {{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}}
90
91 #if(!$classSheetExists)
92 {{html}}
93 <form action="$classSheetDoc.getURL('save', 'editor=wiki')" method="post">
94 <div>
95 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
96 <input type="hidden" name="parent" value="${doc.fullName}"/>
97 <input type="hidden" name="xredirect" value="${doc.URL}"/>
98 <input type="hidden" name="content" value="$escapetool.xml($xwiki.getDocument('XWiki.ObjectSheet').getContent().replace('XWiki.MyClass', $doc.fullName))"/>
99 <input type="hidden" name="title" value="$doc.name Sheet"/>
100 <span class="buttonwrapper"><input type="submit" value="Create the document sheet" class="button"/></span>
101 </div>
102 </form>
103 {{/html}}
104 #else
105 #if($classSheetExists && !$classSheetDoc.getObject('XWiki.SheetClass'))
106 #set($xredirect = $request.getRequestURL())
107 #set($createUrl = $classSheetDoc.getURL('objectadd', "classname=XWiki.SheetClass&xredirect=${xredirect}&form_token=$!{services.csrf.getToken()}"))
108 {{warning}}
109 The sheet does not contain an object of type //XWiki.SheetClass//. To trigger the inline edit mode automatically, {{html}}<a href="$createUrl">add a SheetClass object to the sheet »</a>.{{/html}}
110 {{/warning}}
111
112 #end
113 [[View the sheet document (${classSheetDoc.fullName}) »>>${classSheetDoc.fullName}]]
114 #end
115
116 = The class template =
117
118 {{info}}The //Template// is the document used as the model for documents of this data type. It will automatically contain a reference to the //Sheet// and an instance of your //Class//.{{/info}}
119
120 #if (!$classTemplateExists)
121 {{html}}
122 <form action="$classTemplateDoc.getURL('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 <input type="hidden" name="content" value="$escapetool.xml($xwiki.getDocument('XWiki.ObjectTemplate').getContent().replace('XWiki.MySheet', $classSheetDoc.fullName))"/>
128 <input type="hidden" name="title" value="$doc.name Template"/>
129 <span class="buttonwrapper"><input type="submit" value="Create the document template" class="button"/></span>
130 </div>
131 </form>
132 {{/html}}
133 #else
134 #if($classTemplateExists && !$classTemplateDoc.getObject(${doc.fullName}))
135 #set($xredirect = $request.getRequestURL())
136 #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&amp;xredirect=${xredirect}&amp;form_token=$!{services.csrf.getToken()}"))
137 {{warning}}
138 The template does not contain an object of type //${className}Class//. {{html}}<a href="$createUrl">Add a ${className} object to the template »</a>.{{/html}}
139 {{/warning}}
140
141 #end
142 [[View the template document (${classTemplateDoc.fullName}) »>>${classTemplateDoc.fullName}]]
143 #end
144
145 #end ## doc == XWiki.ClassSheet
146 {{/velocity}}