Wiki source code of Create Application
Last modified by Andrey Che on 2018/12/10 14:08
Show last authors
1 | {{include reference="AppWithinMinutes.WizardStep"/}} |
2 | |
3 | {{template name="locationPicker_macros.vm" /}} |
4 | |
5 | {{velocity output="false"}} |
6 | #macro(showStep) |
7 | {{html wiki="true"}} |
8 | #appWizardHeader('name') |
9 | (% class="wizard-help" %) |
10 | ((( |
11 | **$services.localization.render('platform.appwithinminutes.wizardStepHelpTitle')** $services.localization.render('platform.appwithinminutes.wizardStepHelpDescription') |
12 | (% class="steps vertical" %) |
13 | #foreach($step in $awmSteps) |
14 | * (% class="number" %)$mathtool.add($foreach.index, 1)(%%) (% class="name" %)$services.localization.render("appWithinMinutes.wizardStep.${step}.name")(%%) |
15 | (% class="description" %)$services.localization.render("appWithinMinutes.wizardStep.${step}.description") |
16 | #end |
17 | ))) |
18 | <form action="$doc.getURL()" method="post" class="xform wizard-body"> |
19 | #locationPicker({ |
20 | 'id': 'app', |
21 | 'title': { |
22 | 'label': 'platform.appwithinminutes.appNameLabel', |
23 | 'hint': 'platform.appwithinminutes.appNameHint', |
24 | 'name': 'appName' |
25 | }, |
26 | 'preview': { |
27 | 'label': 'appWithinMinutes.createApp.location.label', |
28 | 'hint': 'appWithinMinutes.createApp.location.hint' |
29 | }, |
30 | 'parent': { |
31 | 'label': 'appWithinMinutes.createApp.parent.label', |
32 | 'hint': 'appWithinMinutes.createApp.parent.hint', |
33 | 'name': 'appParentReference', |
34 | 'reference': $doc.documentReference.wikiReference, |
35 | 'placeholder': 'appWithinMinutes.createApp.parent.placeholder' |
36 | } |
37 | }) |
38 | <div class="appName-preview"></div> |
39 | #appWizardFooter(1) |
40 | </form> |
41 | {{/html}} |
42 | #end |
43 | |
44 | #macro (processStep) |
45 | ## Check if the application already exists. |
46 | #getAppReference |
47 | #getAppDescriptor($appReference) |
48 | #if ($appDescriptor) |
49 | ## Edit an existing application. Use the configured class name. |
50 | #set ($appClassRef = $appDescriptor.getObject($appDescriptorClassName).getValue('class')) |
51 | ## The class reference is relative to the document holding the application descriptor. |
52 | #set ($appClassRef = $services.model.resolveDocument($appClassRef, 'explicit', $appDescriptor.documentReference)) |
53 | #else |
54 | ## Create a new application. Use the default class name. |
55 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) |
56 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) |
57 | #end |
58 | #set ($queryString = {'wizard': true}) |
59 | #if (!$xwiki.exists($appClassRef)) |
60 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) |
61 | #set ($discard = $queryString.putAll({ |
62 | 'template': 'AppWithinMinutes.ClassTemplate', |
63 | 'parent': $services.model.serialize($appHomeRef), |
64 | 'title': "$appReference.name Class" |
65 | })) |
66 | #end |
67 | $response.sendRedirect($xwiki.getURL($appClassRef, 'edit', $escapetool.url($queryString))) |
68 | #end |
69 | |
70 | #macro (validateAppName) |
71 | #getAppReference |
72 | #if (!$appReference) |
73 | (% class="xErrorMsg" %)$services.localization.render('platform.appwithinminutes.appNameEmptyError') |
74 | #else |
75 | #getAppDescriptor($appReference) |
76 | #if ($appDescriptor) |
77 | ## Edit an existing application. |
78 | #set ($appDescriptorObj = $appDescriptor.getObject($appDescriptorClassName)) |
79 | #set ($appClassRef = $appDescriptorObj.getValue('class')) |
80 | ## The class reference is relative to the document holding the application descriptor. |
81 | #set ($appClassRef = $services.model.resolveDocument($appClassRef, 'explicit', $appDescriptor.documentReference)) |
82 | #else |
83 | ## Create a new application. |
84 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) |
85 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) |
86 | #end |
87 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewHomePageUrlLabel') |
88 | : {{{$!xwiki.getDocument($appReference).externalURL}}} |
89 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewCodeSpaceLabel') |
90 | : {{html clean="false"}}#hierarchy($appClassRef.parent){{/html}} |
91 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) |
92 | #if ($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef)) |
93 | |
94 | {{warning}}$services.localization.render('platform.appwithinminutes.appNameIsUsedWarning'){{/warning}} |
95 | #end |
96 | #end |
97 | #end |
98 | |
99 | #macro (getAppReference) |
100 | #if ($request.resolve == 'true') |
101 | #set ($appReference = $services.model.resolveSpace($request.appName)) |
102 | #elseif ("$!request.appName" != '') |
103 | #set ($parentReference = $doc.documentReference.wikiReference) |
104 | #if ("$!request.appParentReference" != '') |
105 | #set ($parentReference = $services.model.resolveSpace($request.appParentReference)) |
106 | #end |
107 | #set ($appReference = $services.model.createSpaceReference($request.appName, $parentReference)) |
108 | #else |
109 | #set ($appReference = $NULL) |
110 | #end |
111 | #end |
112 | |
113 | #macro (getAppDescriptor $appReference) |
114 | #set ($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass') |
115 | #set ($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space") |
116 | #set ($localSpaceReference = $services.model.serialize($appReference, 'local')) |
117 | #set ($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $localSpaceReference).execute()) |
118 | #if ($appDescriptors.size() > 0) |
119 | #set ($appDescriptor = $xwiki.getDocument($appDescriptors.get(0))) |
120 | #end |
121 | #end |
122 | {{/velocity}} |
123 | |
124 | {{velocity}} |
125 | #if ("$!request.appName" != '') |
126 | #if ($xcontext.action == 'get') |
127 | #validateAppName |
128 | #else |
129 | ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string. |
130 | #processStep |
131 | #end |
132 | #else |
133 | #showStep |
134 | #end |
135 | #set ($displayDocExtra = false) |
136 | {{/velocity}} |