Wiki-Quellcode von Anwendung erstellen
Zuletzt geändert von kalcom Support am 2024/11/15 14:37
Zeige letzte Bearbeiter
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{include reference="AppWithinMinutes.VelocityMacros"/}} | ||
| 2 | |||
| 3 | {{velocity}} | ||
| 4 | #if ($request.wizard == 'true') | ||
| 5 | {{include reference="AppWithinMinutes.WizardStep"/}} | ||
| 6 | #end | ||
| 7 | {{/velocity}} | ||
| 8 | |||
| 9 | {{template name="locationPicker_macros.vm" /}} | ||
| 10 | |||
| 11 | {{velocity output="false"}} | ||
| 12 | #macro (showStep) | ||
| 13 | #appWizardHeader('name') | ||
| 14 | <div class="wizard-help"> | ||
| 15 | <p> | ||
| 16 | <strong>$services.localization.render('platform.appwithinminutes.wizardStepHelpTitle')</strong> | ||
| 17 | $services.localization.render('platform.appwithinminutes.wizardStepHelpDescription') | ||
| 18 | </p> | ||
| 19 | <ul class="steps vertical"> | ||
| 20 | #foreach($step in $awmSteps) | ||
| 21 | <li> | ||
| 22 | <span class="btn btn-xs number">$mathtool.add($foreach.index, 1)</span> | ||
| 23 | <span class="name">$services.localization.render("appWithinMinutes.wizardStep.${step}.name")</span> | ||
| 24 | <span class="description">$services.localization.render("appWithinMinutes.wizardStep.${step}.description")</span> | ||
| 25 | </li> | ||
| 26 | #end | ||
| 27 | </ul> | ||
| 28 | </div> | ||
| 29 | <form action="$doc.getURL()" method="post" class="xform wizard-body"> | ||
| 30 | <fieldset> | ||
| 31 | #locationPicker({ | ||
| 32 | 'id': 'app', | ||
| 33 | 'title': { | ||
| 34 | 'label': 'platform.appwithinminutes.appNameLabel', | ||
| 35 | 'hint': 'platform.appwithinminutes.appNameHint', | ||
| 36 | 'name': 'appName' | ||
| 37 | }, | ||
| 38 | 'preview': { | ||
| 39 | 'label': 'appWithinMinutes.createApp.location.label', | ||
| 40 | 'hint': 'appWithinMinutes.createApp.location.hint' | ||
| 41 | }, | ||
| 42 | 'parent': { | ||
| 43 | 'label': 'appWithinMinutes.createApp.parent.label', | ||
| 44 | 'hint': 'appWithinMinutes.createApp.parent.hint', | ||
| 45 | 'name': 'appParentReference', | ||
| 46 | 'reference': $doc.documentReference.wikiReference, | ||
| 47 | 'placeholder': 'appWithinMinutes.createApp.parent.placeholder' | ||
| 48 | } | ||
| 49 | }) | ||
| 50 | <div class="appName-preview"></div> | ||
| 51 | #appWizardFooter(1) | ||
| 52 | </fieldset> | ||
| 53 | </form> | ||
| 54 | #end | ||
| 55 | |||
| 56 | #macro (processStep) | ||
| 57 | ## Check if the application already exists. | ||
| 58 | #getAppReference | ||
| 59 | #getAppDescriptor($appReference) | ||
| 60 | #if ($appDescriptor) | ||
| 61 | ## Edit an existing application. | ||
| 62 | #getAppClassReference($appDescriptor) | ||
| 63 | #set ($appClassRef = $classReference) | ||
| 64 | #else | ||
| 65 | ## Create a new application. Use the default class name. | ||
| 66 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) | ||
| 67 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) | ||
| 68 | #end | ||
| 69 | #set ($queryString = {'wizard': true}) | ||
| 70 | #if (!$xwiki.exists($appClassRef)) | ||
| 71 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) | ||
| 72 | #set ($discard = $queryString.putAll({ | ||
| 73 | 'form_token': $services.csrf.getToken(), | ||
| 74 | 'template': 'AppWithinMinutes.ClassTemplate', | ||
| 75 | 'parent': $services.model.serialize($appHomeRef), | ||
| 76 | 'title': "$appReference.name Class" | ||
| 77 | })) | ||
| 78 | #end | ||
| 79 | $response.sendRedirect($xwiki.getURL($appClassRef, 'edit', $escapetool.url($queryString))) | ||
| 80 | #end | ||
| 81 | |||
| 82 | #macro (validateAppName) | ||
| 83 | #getAppReference | ||
| 84 | #if (!$appReference) | ||
| 85 | <span class="xErrorMsg">$services.localization.render('platform.appwithinminutes.appNameEmptyError')</span> | ||
| 86 | #else | ||
| 87 | #getAppDescriptor($appReference) | ||
| 88 | #if ($appDescriptor) | ||
| 89 | ## Edit an existing application. | ||
| 90 | #getAppClassReference($appDescriptor) | ||
| 91 | #set ($appClassRef = $classReference) | ||
| 92 | #else | ||
| 93 | ## Create a new application. | ||
| 94 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) | ||
| 95 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) | ||
| 96 | #end | ||
| 97 | <dl> | ||
| 98 | <dt>$services.localization.render('platform.appwithinminutes.appNamePreviewHomePageUrlLabel')</dt> | ||
| 99 | <dd><pre>$!escapetool.xml($xwiki.getDocument($appReference).externalURL)</pre></dd> | ||
| 100 | <dt>$services.localization.render('platform.appwithinminutes.appNamePreviewCodeSpaceLabel')</dt> | ||
| 101 | <dd>#hierarchy($appClassRef.parent)</dd> | ||
| 102 | </dl> | ||
| 103 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) | ||
| 104 | #if ($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef)) | ||
| 105 | <div class="box warningmessage"> | ||
| 106 | $services.localization.render('platform.appwithinminutes.appNameIsUsedWarning') | ||
| 107 | </div> | ||
| 108 | #end | ||
| 109 | #if (!$services.security.authorization.hasAccess('script', $xcontext.userReference, $appHomeRef)) | ||
| 110 | <div class="box errormessage"> | ||
| 111 | $escapetool.xml($services.localization.render('platform.appwithinminutes.appHomePageNoScriptRight')) | ||
| 112 | </div> | ||
| 113 | #end | ||
| 114 | #end | ||
| 115 | #end | ||
| 116 | |||
| 117 | #macro (getAppReference) | ||
| 118 | #if ($request.resolve == 'true') | ||
| 119 | #set ($appReference = $services.model.resolveSpace($request.appName)) | ||
| 120 | #elseif ("$!request.appName" != '') | ||
| 121 | #set ($parentReference = $doc.documentReference.wikiReference) | ||
| 122 | #if ("$!request.appParentReference" != '') | ||
| 123 | #set ($parentReference = $services.model.resolveSpace($request.appParentReference)) | ||
| 124 | #end | ||
| 125 | #set ($appReference = $services.model.createSpaceReference($request.appName, $parentReference)) | ||
| 126 | #else | ||
| 127 | #set ($appReference = $NULL) | ||
| 128 | #end | ||
| 129 | #end | ||
| 130 | |||
| 131 | #macro (getAppDescriptor $appReference) | ||
| 132 | #set ($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass') | ||
| 133 | #set ($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space") | ||
| 134 | #set ($localSpaceReference = $services.model.serialize($appReference, 'local')) | ||
| 135 | #set ($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $localSpaceReference).execute()) | ||
| 136 | #if ($appDescriptors.size() > 0) | ||
| 137 | #set ($appDescriptor = $xwiki.getDocument($appDescriptors.get(0))) | ||
| 138 | #else | ||
| 139 | #set ($appDescriptor = $NULL) | ||
| 140 | #end | ||
| 141 | #end | ||
| 142 | {{/velocity}} | ||
| 143 | |||
| 144 | {{velocity}} | ||
| 145 | {{html clean="false"}} | ||
| 146 | #if ("$!request.appName" != '') | ||
| 147 | #if ($xcontext.action == 'get') | ||
| 148 | #validateAppName | ||
| 149 | #else | ||
| 150 | ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string. | ||
| 151 | #processStep | ||
| 152 | #end | ||
| 153 | #elseif ($request.wizard == 'true') | ||
| 154 | #showStep | ||
| 155 | #set ($displayDocExtra = false) | ||
| 156 | #end | ||
| 157 | {{/html}} | ||
| 158 | {{/velocity}} |