# Zdrojový kód wiki Vytvořit aplikaci

Naposledy upravil David Brazda 06.11.2020 11:45
Export
Office Formats
Export do PDF
Other Formats
Export do HTML

Hide last authors

author | version | line-number | content
--- | --- | --- | ---
| 1.1 | 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="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 | #locationPicker({
|  | 31 | 'id': 'app',
|  | 32 | 'title': {
|  | 33 | 'label': 'platform.appwithinminutes.appNameLabel',
|  | 34 | 'hint': 'platform.appwithinminutes.appNameHint',
|  | 35 | 'name': 'appName'
|  | 36 | },
|  | 37 | 'preview': {
|  | 38 | 'label': 'appWithinMinutes.createApp.location.label',
|  | 39 | 'hint': 'appWithinMinutes.createApp.location.hint'
|  | 40 | },
|  | 41 | 'parent': {
|  | 42 | 'label': 'appWithinMinutes.createApp.parent.label',
|  | 43 | 'hint': 'appWithinMinutes.createApp.parent.hint',
|  | 44 | 'name': 'appParentReference',
|  | 45 | 'reference': $doc.documentReference.wikiReference,
|  | 46 | 'placeholder': 'appWithinMinutes.createApp.parent.placeholder'
|  | 47 | }
|  | 48 | })
|  | 49 | <div class="appName-preview"></div>
|  | 50 | #appWizardFooter(1)
|  | 51 | </form>
|  | 52 | #end
|  | 53 |
|  | 54 | #macro (processStep)
|  | 55 | ## Check if the application already exists.
|  | 56 | #getAppReference
|  | 57 | #getAppDescriptor($appReference)
|  | 58 | #if ($appDescriptor)
|  | 59 | ## Edit an existing application.
|  | 60 | #getAppClassReference($appDescriptor)
|  | 61 | #set ($appClassRef = $classReference)
|  | 62 | #else
|  | 63 | ## Create a new application. Use the default class name.
|  | 64 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference))
|  | 65 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef))
|  | 66 | #end
|  | 67 | #set ($queryString = {'wizard': true})
|  | 68 | #if (!$xwiki.exists($appClassRef))
|  | 69 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference))
|  | 70 | #set ($discard = $queryString.putAll({
|  | 71 | 'template': 'AppWithinMinutes.ClassTemplate',
|  | 72 | 'parent': $services.model.serialize($appHomeRef),
|  | 73 | 'title': "$appReference.name Class"
|  | 74 | }))
|  | 75 | #end
|  | 76 | $response.sendRedirect($xwiki.getURL($appClassRef, 'edit', $escapetool.url($queryString)))
|  | 77 | #end
|  | 78 |
|  | 79 | #macro (validateAppName)
|  | 80 | #getAppReference
|  | 81 | #if (!$appReference)
|  | 82 | <span class="xErrorMsg">$services.localization.render('platform.appwithinminutes.appNameEmptyError')</span>
|  | 83 | #else
|  | 84 | #getAppDescriptor($appReference)
|  | 85 | #if ($appDescriptor)
|  | 86 | ## Edit an existing application.
|  | 87 | #getAppClassReference($appDescriptor)
|  | 88 | #set ($appClassRef = $classReference)
|  | 89 | #else
|  | 90 | ## Create a new application.
|  | 91 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference))
|  | 92 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef))
|  | 93 | #end
|  | 94 | <dl>
|  | 95 | <dt>$services.localization.render('platform.appwithinminutes.appNamePreviewHomePageUrlLabel')</dt>
|  | 96 | <dd><pre>$!escapetool.xml($xwiki.getDocument($appReference).externalURL)</pre></dd>
|  | 97 | <dt>$services.localization.render('platform.appwithinminutes.appNamePreviewCodeSpaceLabel')</dt>
|  | 98 | <dd>#hierarchy($appClassRef.parent)</dd>
|  | 99 | </dl>
|  | 100 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference))
|  | 101 | #if ($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef))
|  | 102 | <div class="box warningmessage">
|  | 103 | $services.localization.render('platform.appwithinminutes.appNameIsUsedWarning')
|  | 104 | </div>
|  | 105 | #end
|  | 106 | #end
|  | 107 | #end
|  | 108 |
|  | 109 | #macro (getAppReference)
|  | 110 | #if ($request.resolve == 'true')
|  | 111 | #set ($appReference = $services.model.resolveSpace($request.appName))
|  | 112 | #elseif ("$!request.appName" != '')
|  | 113 | #set ($parentReference = $doc.documentReference.wikiReference)
|  | 114 | #if ("$!request.appParentReference" != '')
|  | 115 | #set ($parentReference = $services.model.resolveSpace($request.appParentReference))
|  | 116 | #end
|  | 117 | #set ($appReference = $services.model.createSpaceReference($request.appName, $parentReference))
|  | 118 | #else
|  | 119 | #set ($appReference = $NULL)
|  | 120 | #end
|  | 121 | #end
|  | 122 |
|  | 123 | #macro (getAppDescriptor $appReference)
|  | 124 | #set ($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass')
|  | 125 | #set ($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space")
|  | 126 | #set ($localSpaceReference = $services.model.serialize($appReference, 'local'))
|  | 127 | #set ($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $localSpaceReference).execute())
|  | 128 | #if ($appDescriptors.size() > 0)
|  | 129 | #set ($appDescriptor = $xwiki.getDocument($appDescriptors.get(0)))
|  | 130 | #else
|  | 131 | #set ($appDescriptor = $NULL)
|  | 132 | #end
|  | 133 | #end
|  | 134 | {{/velocity}}
|  | 135 |
|  | 136 | {{velocity}}
|  | 137 | {{html clean="false"}}
|  | 138 | #if ("$!request.appName" != '')
|  | 139 | #if ($xcontext.action == 'get')
|  | 140 | #validateAppName
|  | 141 | #else
|  | 142 | ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string.
|  | 143 | #processStep
|  | 144 | #end
|  | 145 | #elseif ($request.wizard == 'true')
|  | 146 | #showStep
|  | 147 | #set ($displayDocExtra = false)
|  | 148 | #end
|  | 149 | {{/html}}
|  | 150 | {{/velocity}}

Můj Deník
XWiki Debian 12.9