Wiki-Quellcode von ClassSheetGenerator
Zuletzt geändert von admin am 2025/02/23 10:22
Verstecke letzte Bearbeiter
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity output="false"}} |
| 2 | #macro(escapeSingleQuotes $string) | ||
| 3 | $string.replace("'", "''")## | ||
| 4 | #end | ||
| 5 | |||
| 6 | #** | ||
| 7 | * Generic property display. | ||
| 8 | *# | ||
| 9 | #macro(displayProperty $property $indentation) | ||
| 10 | ${indentation}<dt ${escapetool.h}if (!${escapetool.d}editing && ${escapetool.d}hasEdit) | ||
| 11 | ${indentation} class="editableProperty" | ||
| 12 | ${indentation} data-property="${escapetool.d}escapetool.xml(${escapetool.d}services.model.serialize(${escapetool.d}object.getPropertyReference('#escapeSingleQuotes($property.name)')))" | ||
| 13 | ${indentation} data-property-type="object"${escapetool.h}end> | ||
| 14 | ${indentation} <label${escapetool.h}if (${escapetool.d}editing) for="$escapetool.xml("${doc.fullName}_0_$property.name")"${escapetool.h}end> | ||
| 15 | ${indentation} ${escapetool.d}escapetool.xml(${escapetool.d}doc.displayPrettyName('#escapeSingleQuotes($property.name)', false, false)) | ||
| 16 | ${indentation} </label> | ||
| 17 | #if ("$!property.hint" != '') | ||
| 18 | ${indentation} <span class="xHint"> | ||
| 19 | ${indentation} ${escapetool.d}escapetool.xml(${escapetool.d}services.localization.render('#escapeSingleQuotes($property.hint)')) | ||
| 20 | ${indentation} </span> | ||
| 21 | #end | ||
| 22 | ${indentation}</dt> | ||
| 23 | ${indentation}<dd>${escapetool.d}doc.display('#escapeSingleQuotes($property.name)')</dd> | ||
| 24 | #end | ||
| 25 | |||
| 26 | #** | ||
| 27 | * Unfortunately the custom display mechanism for properties doesn't offer a clean way to overwrite the display only when | ||
| 28 | * some conditions are met (e.g. a specific action) so we're putting the custom display code in the sheet. | ||
| 29 | *# | ||
| 30 | #macro(displayBooleanProperty $property $indentation) | ||
| 31 | ${indentation}${escapetool.h}if (${escapetool.d}editing) | ||
| 32 | ${indentation} <dt> | ||
| 33 | ${indentation} <label for="$escapetool.xml("${doc.fullName}_0_$property.name")"> | ||
| 34 | ${indentation} ${escapetool.d}doc.display('#escapeSingleQuotes($property.name)') | ||
| 35 | ${indentation} ${escapetool.d}escapetool.xml(${escapetool.d}doc.displayPrettyName('#escapeSingleQuotes($property.name)', false, false)) | ||
| 36 | ${indentation} </label> | ||
| 37 | ${indentation} </dt> | ||
| 38 | #if ("$!property.hint" != '') | ||
| 39 | ${indentation} <dd> | ||
| 40 | ${indentation} <span class="xHint"> | ||
| 41 | ${indentation} ${escapetool.d}escapetool.xml(${escapetool.d}services.localization.render('#escapeSingleQuotes($property.hint)')) | ||
| 42 | ${indentation} </span> | ||
| 43 | ${indentation} </dd> | ||
| 44 | #end | ||
| 45 | ${indentation}${escapetool.h}else | ||
| 46 | #displayProperty($property "$indentation ") | ||
| 47 | ${indentation}${escapetool.h}end | ||
| 48 | #end | ||
| 49 | {{/velocity}} | ||
| 50 | |||
| 51 | {{velocity filter="none"}} | ||
| 52 | {{{## | ||
| 53 | {{velocity}} | ||
| 54 | ${escapetool.h}set (${escapetool.d}object = ${escapetool.d}doc.getObject('#escapeSingleQuotes($doc.fullName)')) | ||
| 55 | #set ($appName = $stringtool.removeEnd($doc.documentReference.name, 'Class')) | ||
| 56 | #set ($translationKeyPrefix = "#escapeSingleQuotes($appName.toLowerCase()).sheet.") | ||
| 57 | ${escapetool.h}if (!${escapetool.d}object) | ||
| 58 | ${escapetool.h}set (${escapetool.d}messageKey = '${translationKeyPrefix}description') | ||
| 59 | ${escapetool.h}set (${escapetool.d}messageType = 'info') | ||
| 60 | ${escapetool.h}if (${escapetool.d}doc.documentReference.name != '#escapeSingleQuotes("${appName}Sheet")') | ||
| 61 | ${escapetool.h}set (${escapetool.d}messageKey = '${translationKeyPrefix}noObject') | ||
| 62 | ${escapetool.h}set (${escapetool.d}messageType = 'warning') | ||
| 63 | ${escapetool.h}end | ||
| 64 | {{${escapetool.d}messageType}} | ||
| 65 | ${escapetool.d}services.localization.render(${escapetool.d}messageKey) | ||
| 66 | {{/${escapetool.d}messageType}} | ||
| 67 | ${escapetool.h}stop | ||
| 68 | ${escapetool.h}end | ||
| 69 | #set ($properties = $doc.getxWikiClass().properties) | ||
| 70 | #if ($properties && $properties.size() > 0) | ||
| 71 | ## This is needed for in-place editing. | ||
| 72 | ${escapetool.h}set (${escapetool.d}discard = ${escapetool.d}xwiki.jsfx.use('uicomponents/edit/editableProperty.js', { | ||
| 73 | 'forceSkinAction': true, | ||
| 74 | 'language': ${escapetool.d}xcontext.locale | ||
| 75 | })) | ||
| 76 | ${escapetool.h}set (${escapetool.d}discard = ${escapetool.d}doc.use(${escapetool.d}object)) | ||
| 77 | ${escapetool.h}set (${escapetool.d}editing = ${escapetool.d}xcontext.action == 'edit') | ||
| 78 | {{html wiki="true" clean="false"}} | ||
| 79 | ## We don't have access to the form element to set the CSS class for the vertical form layout standard. | ||
| 80 | <div class="xform"> | ||
| 81 | <dl> | ||
| 82 | #foreach ($property in $properties) | ||
| 83 | #set ($displayFormType = $property.getProperty('displayFormType')) | ||
| 84 | #if ($property.type.indexOf('Boolean') != -1 && "$!displayFormType.value" == 'checkbox') | ||
| 85 | #displayBooleanProperty($property ' ') | ||
| 86 | #else | ||
| 87 | #displayProperty($property ' ') | ||
| 88 | #end | ||
| 89 | #end | ||
| 90 | </dl> | ||
| 91 | </div> | ||
| 92 | {{/html}} | ||
| 93 | #else## No properties to display. | ||
| 94 | {{info}} | ||
| 95 | ${escapetool.d}services.localization.render('${translationKeyPrefix}noFields') | ||
| 96 | {{/info}} | ||
| 97 | #end | ||
| 98 | {{/velocity}}## | ||
| 99 | }}} | ||
| 100 | {{/velocity}} |