Code source wiki de LiveTableScriptGenerator
Modifié par Jip-jan Alunkel le mars 10, 15:58
Afficher les derniers auteurs
author | version | line-number | content |
---|---|---|---|
1 | {{velocity}} | ||
2 | #if(!$request.fields) | ||
3 | #if(!$request.classname) | ||
4 | You also use the [[LiveTable Macro>>LiveTable]] or use the [[LiveTable generator>>LiveTableGenerator]]: | ||
5 | |||
6 | {{html}} | ||
7 | <form action =""> | ||
8 | Generate LiveTable for class: <select name="classname"> | ||
9 | #set($classes = $xwiki.classList) | ||
10 | #foreach($classn in $classes) | ||
11 | <option value="${classn}" #if($dclass==$classn) selected #end>$classn</option> | ||
12 | #end | ||
13 | </select> | ||
14 | <input type="submit" value="Go" /> | ||
15 | </form> | ||
16 | {{/html}} | ||
17 | |||
18 | #foreach($item in $msg) | ||
19 | $item | ||
20 | #end | ||
21 | #else | ||
22 | {{html}} | ||
23 | <form action =""> | ||
24 | <input type="hidden" name="classname" value="$!request.classname" /> | ||
25 | Generate LiveTable for class: $request.classname | ||
26 | |||
27 | #set($classname = $request.classname) | ||
28 | #set($classdoc = $xwiki.getDocument($classname)) | ||
29 | #set($classx = $classdoc.getxWikiClass()) | ||
30 | #set($props = $classx.getProperties()) | ||
31 | <br /> | ||
32 | <select name="fields" multiple="1"> | ||
33 | #foreach($propname in [ "title", "name", "space", "fullName", "author", "date", "creator", "creationDate" ]) | ||
34 | <option value="doc.${propname}">$propname</option> | ||
35 | #end | ||
36 | #foreach($prop in $props) | ||
37 | <option value="${prop.name}">$prop.prettyName</option> | ||
38 | #end | ||
39 | #foreach($propname in [ "_avatar", "_images", "_attachments", "_actions" ]) | ||
40 | <option value="${propname}">$propname</option> | ||
41 | #end | ||
42 | </select> | ||
43 | <input type="submit" value="Go" /> | ||
44 | </form> | ||
45 | {{/html}} | ||
46 | #end | ||
47 | #else | ||
48 | #set($classname = $request.classname) | ||
49 | #set($classdoc = $xwiki.getDocument($classname)) | ||
50 | #set($classx = $classdoc.getxWikiClass()) | ||
51 | #set($props = $classx.getProperties()) | ||
52 | #set($fields = $request.getParameterValues("fields")) | ||
53 | |||
54 | ~{~{velocity}} | ||
55 | \#set($columns = [ #foreach($propname in $fields) #if($velocityCount>1),#end "${propname}" #end]) | ||
56 | \#set($columnsProperties = { | ||
57 | #foreach($prop in $props) | ||
58 | #set($ishtml = false) | ||
59 | #if($prop.classType.endsWith("TextAreaClass")) | ||
60 | #set($ishtml = true) | ||
61 | #end | ||
62 | #if($prop.classType.endsWith("ListClass")) | ||
63 | #set($type = "list") | ||
64 | #else | ||
65 | #set($type = "text") | ||
66 | #end | ||
67 | #set($sortable = "true") | ||
68 | #set($filterable = "true") | ||
69 | #if($listtool.contains($fields, $prop.name)) | ||
70 | ~ ~ ~ ~ ~ "${prop.name}" : { "type" : "${type}", "link" : "view", "size" : 10, "filterable" : $filterable, "sortable": $sortable #if($ishtml), "html" : true #end }, | ||
71 | #end | ||
72 | #end | ||
73 | #foreach($propname in [ "_avatar", "_images", "_attachments", "_actions" ]) | ||
74 | #if($listtool.contains($fields, $prop.name)) | ||
75 | ~ ~ ~ ~ ~ "${propname}" : { "type" : "none", "link" : "none", "html" : "true", "sortable":false }, | ||
76 | #end | ||
77 | #end | ||
78 | #foreach($propname in [ "name", "space", "fullName", "author", "date", "creator", "creationDate" ]) | ||
79 | #if($listtool.contains($fields, $prop.name)) | ||
80 | ~ ~ ~ ~ ~ "doc.${propname}" : { "type" : "text", "link" : "view", "size" : "10", "filterable" : true, "sortable": true }, | ||
81 | #end | ||
82 | #end | ||
83 | ~ ~ ~ ~ ~ "doc.title" : { "type" : "text", "link" : "view", "size" : "20", "filterable" : true, "sortable": true } | ||
84 | }) | ||
85 | |||
86 | #set($shortname = $classdoc.name.replaceAll("Class", "").toLowerCase()) | ||
87 | |||
88 | \#set($options = { | ||
89 | "className":"${classname}", | ||
90 | "translationPrefix" : "${shortname}.livetable.", | ||
91 | "tagCloud" : true, | ||
92 | "rowCount": 15, | ||
93 | "maxPages" : 10, | ||
94 | "selectedColumn" : "doc.title", | ||
95 | "defaultOrder" : "asc" | ||
96 | }) | ||
97 | |||
98 | \#livetable("${shortname}" $columns $columnsProperties $options) | ||
99 | ~{~{/velocity}} | ||
100 | |||
101 | == Translations | ||
102 | |||
103 | #foreach($prop in $props) | ||
104 | ${shortname}.livetable.${prop.name}=${prop.prettyName} | ||
105 | #end | ||
106 | ${shortname}.livetable.doc.title=Title | ||
107 | ${shortname}.livetable.doc.name=Name | ||
108 | ${shortname}.livetable.doc.space=Space | ||
109 | ${shortname}.livetable.doc.fullname=Full name | ||
110 | ${shortname}.livetable.doc.author=Author | ||
111 | ${shortname}.livetable.doc.creator=Creator | ||
112 | ${shortname}.livetable.doc.date=Update date | ||
113 | ${shortname}.livetable.doc.creationDate=Creation date | ||
114 | ${shortname}.livetable._avatar=Avatar | ||
115 | ${shortname}.livetable._images=Images | ||
116 | ${shortname}.livetable._attachments=Attachments | ||
117 | ${shortname}.livetable._actions=Actions | ||
118 | ${shortname}.livetable.emptyvalue=- | ||
119 | |||
120 | == How to customize the property definitions == | ||
121 | |||
122 | |=Name|=Descriptions|=Default value | ||
123 | |displayName|The name to display as a column header for this column (wins over the translationPrefix table option) (Note: available starting with XE 2.3)|None | ||
124 | |filterable|Should the column present a filter on its header?|true | ||
125 | |sortable|Should the column be available as a sort key?|true | ||
126 | |type|For filterable columns, the type of filter for the column. Also allows to hide a column. Possible values in hidden, text, list, number.|None (no type) | ||
127 | |size|The size of the filter field. CSS might override this value to make the field 100%.|None | ||
128 | |link|The type of link to use for the field value, in view, field, none. "view" links to the page corresponding to the row. "field" links to the page corresponding to the field value (for DBListClass). "hidden" hides the column. "none" has not link.|None(no link) | ||
129 | |html|Should the returned value be treated as HTML and injected as is in the row ?|false | ||
130 | |class|Specifies the full name of the XWiki class for the type of data to display in the table. Used by the filtering options in the live table header, when the $options hash has resultPage key instead of className.|None | ||
131 | |||
132 | == How to customize the live table options == | ||
133 | |||
134 | |=Name|=Description | ||
135 | |doc.name|The name of the document (for example, **WebHome**, in Sandbox.WebHome). | ||
136 | |doc.title|The title of the document. | ||
137 | |doc.space|The space of the document (for example, **Sandbox**, in Sandbox.WebHome). | ||
138 | |doc.fullName|The full name of the document (for example **Sandbox.WebHome**). | ||
139 | |doc.creationDate|The date at which the document was created. | ||
140 | |doc.creator|The username of the user that created the document. | ||
141 | |doc.author|The username of the last author of the document. | ||
142 | |doc.date|The date at which the document has been last modified. | ||
143 | |propertyName|Any property of an XWiki Class the table is bound to. (See the className parameter of the $option argument for more information on how to bind a table to a XWiki Class). | ||
144 | |_images|A special column to display all images attached to the retrieved document. | ||
145 | |_attachments|A special column to display links to all attachments of the retrieved document. | ||
146 | |_actions|A special column to display a list of actions that can be performed by administrators on the matched documents. | ||
147 | |_avatar|A special column to display the user avatar. Works only for a table bound to the XWiki.XWikiUsers XWiki class. | ||
148 | |||
149 | #end | ||
150 | {{/velocity}} |