Wiki source code of LiveTable Generator
Last modified by Aurelie Bertrand on 2024/09/13 16:12
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | |||
| 2 | This page allows to generate a LiveTable. You can also use the [[LiveTable Script Generator>>LiveTableScriptGenerator]] or the [[LiveTable Macro>>LiveTable]]. | ||
| 3 | |||
| 4 | {{velocity}} | ||
| 5 | #if(!$request.fields) | ||
| 6 | #if(!$request.classname) | ||
| 7 | {{html}} | ||
| 8 | <form action =""> | ||
| 9 | Generate LiveTable for class: <select name="classname"> | ||
| 10 | #set($classes = $xwiki.classList) | ||
| 11 | #foreach($classn in $classes) | ||
| 12 | <option value="${classn}" #if($dclass==$classn) selected #end>$classn</option> | ||
| 13 | #end | ||
| 14 | </select> | ||
| 15 | <input type="submit" value="Go" /> | ||
| 16 | </form> | ||
| 17 | {{/html}} | ||
| 18 | |||
| 19 | #foreach($item in $msg) | ||
| 20 | $item | ||
| 21 | #end | ||
| 22 | #else | ||
| 23 | {{html}} | ||
| 24 | <form action =""> | ||
| 25 | <input type="hidden" name="classname" value="$!request.classname" /> | ||
| 26 | Generate LiveTable for class: $request.classname | ||
| 27 | |||
| 28 | #set($classname = $request.classname) | ||
| 29 | #set($classdoc = $xwiki.getDocument($classname)) | ||
| 30 | #set($classx = $classdoc.getxWikiClass()) | ||
| 31 | #set($props = $classx.getProperties()) | ||
| 32 | <br /> | ||
| 33 | <select name="fields" multiple="1"> | ||
| 34 | #foreach($propname in [ "title", "name", "space", "fullName", "author", "date", "creator", "creationDate" ]) | ||
| 35 | <option value="doc.${propname}">$propname</option> | ||
| 36 | #end | ||
| 37 | #foreach($prop in $props) | ||
| 38 | <option value="${prop.name}">$prop.prettyName</option> | ||
| 39 | #end | ||
| 40 | #foreach($propname in [ "_avatar", "_images", "_attachments", "_actions" ]) | ||
| 41 | <option value="${propname}">$propname</option> | ||
| 42 | #end | ||
| 43 | </select> | ||
| 44 | <input type="submit" value="Go" /> | ||
| 45 | </form> | ||
| 46 | {{/html}} | ||
| 47 | #end | ||
| 48 | #else | ||
| 49 | #set($classname = $request.classname) | ||
| 50 | #set($classdoc = $xwiki.getDocument($classname)) | ||
| 51 | #set($classx = $classdoc.getxWikiClass()) | ||
| 52 | #set($props = $classx.getProperties()) | ||
| 53 | #set($fields = $request.getParameterValues("fields")) | ||
| 54 | #set($shortname = $classdoc.name.replaceAll("Class", "").toLowerCase()) | ||
| 55 | #set($columns = $fields) | ||
| 56 | #set($msg2 = $msg) | ||
| 57 | #set($msg = $xwiki.hashMap) | ||
| 58 | #foreach($prop in $props) | ||
| 59 | #if($listtool.contains($fields, $prop.name)) | ||
| 60 | #set($ok = $msg.put("${shortname}.livetable.${prop.name}", $prop.prettyName)) | ||
| 61 | #end | ||
| 62 | #end | ||
| 63 | ## need to inject the translations | ||
| 64 | #set($ok = $msg.put("${shortname}.livetable.doc.title","Title")) | ||
| 65 | #set($ok = $msg.put("${shortname}.livetable.doc.name","Name")) | ||
| 66 | #set($ok = $msg.put("${shortname}.livetable.doc.space","Space")) | ||
| 67 | #set($ok = $msg.put("${shortname}.livetable.doc.fullname","Full name")) | ||
| 68 | #set($ok = $msg.put("${shortname}.livetable.doc.author","Author")) | ||
| 69 | #set($ok = $msg.put("${shortname}.livetable.doc.creator","Creator")) | ||
| 70 | #set($ok = $msg.put("${shortname}.livetable.doc.date","Update date")) | ||
| 71 | #set($ok = $msg.put("${shortname}.livetable.doc.creationDate","Creation date")) | ||
| 72 | #set($ok = $msg.put("${shortname}.livetable._avatar","Avatar")) | ||
| 73 | #set($ok = $msg.put("${shortname}.livetable._images","Images")) | ||
| 74 | #set($ok = $msg.put("${shortname}.livetable._attachments","Attachments")) | ||
| 75 | #set($ok = $msg.put("${shortname}.livetable._actions","Actions")) | ||
| 76 | #set($ok = $msg.put("${shortname}.livetable.emptyvalue","-")) | ||
| 77 | ## need to get the pagination and livetable translations | ||
| 78 | #foreach($key in ["results", "resultsmacros","_actions.delete","_actions.rename","_actions.rights", "_actions.copy","filters.title","loading","tags.help","tags.help.cancel","environmentCannotLoadTableMessage", "pagesize.label", "tools", "tools.excel"]) | ||
| 79 | #set($ok = $msg.put("xe.livetable.${key}", $msg2.get("xe.livetable.${key}"))) | ||
| 80 | #end | ||
| 81 | #foreach($key in ["page","page.title","page.previous","page.prev.title","page.next","page.next.title","results.none","results.one","results.single","results.many"]) | ||
| 82 | #set($ok = $msg.put("xe.pagination.${key}", $msg2.get("xe.pagination.${key}"))) | ||
| 83 | #end | ||
| 84 | |||
| 85 | #set($columnsProperties = { "doc.title" : { "type" : "text", "link" : "view", "size" : "20", "filterable" : true, "sortable": true }}) | ||
| 86 | |||
| 87 | #foreach($prop in $props) | ||
| 88 | #set($ishtml = false) | ||
| 89 | #if($prop.classType.endsWith("TextAreaClass")) | ||
| 90 | #set($ishtml = true) | ||
| 91 | #end | ||
| 92 | #if($prop.classType.endsWith("ListClass")) | ||
| 93 | #set($type = "list") | ||
| 94 | #else | ||
| 95 | #set($type = "text") | ||
| 96 | #end | ||
| 97 | #set($sortable = "true") | ||
| 98 | #set($filterable = "true") | ||
| 99 | #if($ishtml) | ||
| 100 | #set($ok = $columsProperties.put($prop.name, { "type" : "${type}", "link" : "view", "size" : 10, "filterable" : $filterable, "sortable": $sortable, "html" : true })) | ||
| 101 | #else | ||
| 102 | #set($ok = $columsProperties.put($prop.name, { "type" : "${type}", "link" : "view", "size" : 10, "filterable" : $filterable, "sortable": $sortable })) | ||
| 103 | #end | ||
| 104 | #foreach($propname in [ "_avatar", "_images", "_attachments", "_actions" ]) | ||
| 105 | #set($ok = $columsProperties.put($propname, { "type" : "none", "link" : "none", "html" : "true", "sortable":false })) | ||
| 106 | #end | ||
| 107 | #foreach($propname in [ "name", "space", "fullName", "author", "date", "creator", "creationDate" ]) | ||
| 108 | #set($ok = $columsProperties.put("doc.${propname}", { "type" : "text", "link" : "view", "size" : "10", "filterable" : true, "sortable": true })) | ||
| 109 | #end | ||
| 110 | #end | ||
| 111 | |||
| 112 | #set($options = { | ||
| 113 | "className":"${classname}", | ||
| 114 | "resultPage" : "Macros.LiveTableGeneratorResults", | ||
| 115 | "translationPrefix" : "${shortname}.livetable.", | ||
| 116 | "tagCloud" : true, | ||
| 117 | "rowCount": 15, | ||
| 118 | "maxPages" : 10, | ||
| 119 | "selectedColumn" : "doc.title", | ||
| 120 | "defaultOrder" : "asc" | ||
| 121 | }) | ||
| 122 | |||
| 123 | #set($result = "#livetable($shortname $columns $columnsProperties $options)") | ||
| 124 | #set($str = "${shortname}.livetable.emptyvalue") | ||
| 125 | #set($result = $result.replaceAll($str,"-")) | ||
| 126 | $result | ||
| 127 | #set($msg = $msg2) | ||
| 128 | #end | ||
| 129 | {{/velocity}} |