Wiki source code of Default Class Sheet

Last modified by Admin on 2010/05/19 20:19

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="parent" value="${defaultParent}"/>
66 <input type="hidden" name="template" value="${classTemplateDoc}"/>
67 <input type="hidden" name="sheet" value="1"/>
68 <label for="spaceName">Space: </label><input type="text" id="spaceName" name="spaceName" value="${defaultSpace}" size="8"/>
69 <label for="docName">Document: </label><input type="text" id="docName" name="docName" value="Document name" class="withTip"'/>
70 <span class="buttonwrapper"><input type="submit" value="Create this document" class="button"/></span>
71 </div>
72 </form>
73 {{/html}}
74
75 = Existing documents =
76
77 #set($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.fullName}' and obj.name<>'${classTemplateDoc.fullName}'")
78 #foreach ($item in $xwiki.searchDocuments($sql))
79 * [[$item]]
80 #end
81 #end ## class sheet and class template exist
82 = The class sheet =
83
84 #if (!$classSheetExists || !$classTemplateExists)
85 Before using this class you must first create the sheet and template for it. Follow the instructions below to do this.
86 #end
87
88 {{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}}
89
90 #if(!$classSheetExists)
91 {{html}}
92 <form action="$classSheetDoc.getURL('save', 'editor=wiki')" method="post">
93 <div>
94 <input type="hidden" name="parent" value="${doc.fullName}"/>
95 <input type="hidden" name="xredirect" value="${doc.URL}"/>
96 <input type="hidden" name="content" value="$xwiki.getFormEncoded($xwiki.getDocument('XWiki.ObjectSheet').getContent().replaceAll('XWiki.MyClass', $doc.fullName))"/>
97 <span class="buttonwrapper"><input type="submit" value="Create the document sheet" class="button"/></span>
98 </div>
99 </form>
100 {{/html}}
101 #else
102 #if($classSheetExists && !$classSheetDoc.getObject('XWiki.SheetClass'))
103 #set($xredirect = $request.getRequestURL())
104 #set($createUrl = $classSheetDoc.getURL('objectadd', "classname=XWiki.SheetClass&xredirect=${xredirect}"))
105 {{warning}}
106 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}}
107 {{/warning}}
108
109 #end
110 [[View the sheet document (${classSheetDoc.fullName}) »>>${classSheetDoc.fullName}]]
111 #end
112
113 = The class template =
114
115 {{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}}
116
117 #if (!$classTemplateExists)
118 {{html}}
119 <form action="$classTemplateDoc.getURL('save', 'editor=wiki')" method="post">
120 <div>
121 <input type="hidden" name="parent" value="${doc.fullName}"/>
122 <input type="hidden" name="xredirect" value="${doc.URL}"/>
123 <input type="hidden" name="content" value="$xwiki.getFormEncoded($xwiki.getDocument('XWiki.ObjectTemplate').getContent().replaceAll('XWiki.MySheet', $classSheetDoc.fullName))"/>
124 <span class="buttonwrapper"><input type="submit" value="Create the document template" class="button"/></span>
125 </div>
126 </form>
127 {{/html}}
128 #else
129 #if($classTemplateExists && !$classTemplateDoc.getObject(${doc.fullName}))
130 #set($xredirect = $request.getRequestURL())
131 #set($createUrl = $classTemplateDoc.getURL('objectadd', "classname=${doc.fullName}&amp;xredirect=${xredirect}"))
132 {{warning}}
133 The template does not contain an object of type //${className}Class//. {{html}}<a href="$createUrl">Add a ${className} object to the template »</a>.{{/html}}
134 {{/warning}}
135
136 #end
137 [[View the template document (${classTemplateDoc.fullName}) »>>${classTemplateDoc.fullName}]]
138
139 #end
140 #end ## doc == XWiki.ClassSheet
141 {{/velocity}}