Wiki source code of Import-Test-App-01
Last modified by Ophion Admin on 2026/10/06 14:27
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | #set ($appSpace = 'Import-Test-App-01') | ||
| 3 | #set ($templateRef = 'Import-Test-App-01.Code.Import-Test-App-01Template') | ||
| 4 | ## Allowed values for the first part of the page name | ||
| 5 | #set ($prefixes = ['variable-1', 'variable-2', 'variable-3']) | ||
| 6 | #set ($errorMsg = '') | ||
| 7 | #if ("$!request.createEntry" == '1') | ||
| 8 | #set ($prefix = "$!request.prefix") | ||
| 9 | #set ($suffix = "$!request.suffix") | ||
| 10 | #if (!$prefixes.contains($prefix)) | ||
| 11 | #set ($errorMsg = 'Invalid prefix.') | ||
| 12 | #elseif (!$suffix.matches('[a-z0-9_-]+')) | ||
| 13 | #set ($errorMsg = 'Only lowercase letters, digits, hyphen and underscore are allowed.') | ||
| 14 | #else | ||
| 15 | #set ($baseName = "${prefix}-${suffix}") | ||
| 16 | #set ($name = $baseName) | ||
| 17 | #set ($ref = $services.model.createDocumentReference('', [$appSpace, $name], 'WebHome')) | ||
| 18 | ## Append a running number until the page name is free: name-1, name-2, ... | ||
| 19 | #foreach ($i in [1..999]) | ||
| 20 | #if (!$xwiki.exists($ref)) | ||
| 21 | #break | ||
| 22 | #end | ||
| 23 | #set ($name = "${baseName}-${i}") | ||
| 24 | #set ($ref = $services.model.createDocumentReference('', [$appSpace, $name], 'WebHome')) | ||
| 25 | #end | ||
| 26 | #if ($xwiki.exists($ref)) | ||
| 27 | #set ($errorMsg = "No free page name found for '${baseName}'.") | ||
| 28 | #else | ||
| 29 | #set ($qs = $escapetool.url({'template': $templateRef, 'parent': "${appSpace}.WebHome", 'title': $name})) | ||
| 30 | $response.sendRedirect($xwiki.getURL($ref, 'edit', $qs)) | ||
| 31 | #end | ||
| 32 | #end | ||
| 33 | #end | ||
| 34 | #if ($errorMsg != '') | ||
| 35 | {{error}}$errorMsg{{/error}} | ||
| 36 | #end | ||
| 37 | {{html clean="false"}} | ||
| 38 | <style> | ||
| 39 | /* Hide the default AWM "Add new entry" button */ | ||
| 40 | ul.actions a.action.add, a.action.add { display: none !important; } | ||
| 41 | </style> | ||
| 42 | <form action="$doc.getURL()" method="get" class="form-inline"> | ||
| 43 | <input type="hidden" name="createEntry" value="1"/> | ||
| 44 | <select name="prefix" class="form-control"> | ||
| 45 | #foreach ($p in $prefixes) | ||
| 46 | <option value="$p">$p</option> | ||
| 47 | #end | ||
| 48 | </select> | ||
| 49 | - | ||
| 50 | <input type="text" name="suffix" class="form-control" required="required" | ||
| 51 | pattern="[a-z0-9_-]+" title="Lowercase letters, digits, - and _ only"/> | ||
| 52 | <input type="submit" class="btn btn-primary" value="Create entry"/> | ||
| 53 | </form> | ||
| 54 | {{/html}} | ||
| 55 | {{/velocity}} | ||
| 56 | {{velocity}} | ||
| 57 | #set ($columnsProperties = { | ||
| 58 | 'doc.title': {"link":"view"}, | ||
| 59 | 'doc.location': {"html":true}, | ||
| 60 | 'doc.date': {}, | ||
| 61 | 'doc.author': {"link":"author"}, | ||
| 62 | '_actions': {"sortable":false,"filterable":false,"html":true,"actions":["edit","delete"]} | ||
| 63 | }) | ||
| 64 | #set ($options = { | ||
| 65 | 'className': 'Import-Test-App-01.Code.Import-Test-App-01Class', | ||
| 66 | 'translationPrefix': 'import-test-app-01.livetable.', | ||
| 67 | 'tagCloud': true, | ||
| 68 | 'rowCount': 15, | ||
| 69 | 'maxPages': 10, | ||
| 70 | 'selectedColumn': 'doc.title', | ||
| 71 | 'defaultOrder': 'asc' | ||
| 72 | }) | ||
| 73 | #set ($columns = ['doc.title', 'doc.location', 'doc.date', 'doc.author', '_actions']) | ||
| 74 | #livetable('import-test-app-01' $columns $columnsProperties $options) | ||
| 75 | {{/velocity}} |