Wiki source code of Create Application
Version 4.1 by Administrator on 2016/12/01 12:43
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{include reference="AppWithinMinutes.WizardStep"/}} |
| 2 | |||
| |
3.1 | 3 | {{template name="locationPicker_macros.vm" /}} |
| 4 | |||
| |
1.1 | 5 | {{velocity output="false"}} |
| 6 | #macro(showStep) | ||
| 7 | {{html wiki="true"}} | ||
| |
4.1 | 8 | #appWizardHeader('name') |
| |
1.1 | 9 | (% class="wizard-help" %) |
| 10 | ((( | ||
| 11 | **$services.localization.render('platform.appwithinminutes.wizardStepHelpTitle')** $services.localization.render('platform.appwithinminutes.wizardStepHelpDescription') | ||
| 12 | (% class="steps vertical" %) | ||
| |
4.1 | 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") | ||
| |
1.1 | 16 | #end |
| 17 | ))) | ||
| 18 | <form action="$doc.getURL()" method="post" class="xform wizard-body"> | ||
| |
3.1 | 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> | ||
| |
1.1 | 39 | #appWizardFooter(1) |
| 40 | </form> | ||
| 41 | {{/html}} | ||
| 42 | #end | ||
| 43 | |||
| |
2.1 | 44 | #macro (processStep) |
| |
1.1 | 45 | ## Check if the application already exists. |
| |
3.1 | 46 | #getAppReference |
| |
2.1 | 47 | #getAppDescriptor($appReference) |
| |
3.1 | 48 | #if ($appDescriptor) |
| |
1.1 | 49 | ## Edit an existing application. Use the configured class name. |
| |
3.1 | 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)) | ||
| |
1.1 | 53 | #else |
| 54 | ## Create a new application. Use the default class name. | ||
| |
3.1 | 55 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) |
| 56 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) | ||
| |
1.1 | 57 | #end |
| |
3.1 | 58 | #set ($queryString = {'wizard': true}) |
| 59 | #if (!$xwiki.exists($appClassRef)) | ||
| 60 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) | ||
| 61 | #set ($discard = $queryString.putAll({ | ||
| |
2.1 | 62 | 'template': 'AppWithinMinutes.ClassTemplate', |
| 63 | 'parent': $services.model.serialize($appHomeRef), | ||
| |
3.1 | 64 | 'title': "$appReference.name Class" |
| |
2.1 | 65 | })) |
| |
1.1 | 66 | #end |
| |
3.1 | 67 | $response.sendRedirect($xwiki.getURL($appClassRef, 'edit', $escapetool.url($queryString))) |
| |
1.1 | 68 | #end |
| 69 | |||
| |
3.1 | 70 | #macro (validateAppName) |
| 71 | #getAppReference | ||
| 72 | #if (!$appReference) | ||
| 73 | (% class="xErrorMsg" %)$services.localization.render('platform.appwithinminutes.appNameEmptyError') | ||
| |
1.1 | 74 | #else |
| |
3.1 | 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)) | ||
| |
1.1 | 86 | #end |
| |
3.1 | 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 | ||
| |
1.1 | 96 | #end |
| |
3.1 | 97 | #end |
| |
1.1 | 98 | |
| |
3.1 | 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) | ||
| |
1.1 | 110 | #end |
| 111 | #end | ||
| |
3.1 | 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 | ||
| |
1.1 | 122 | {{/velocity}} |
| 123 | |||
| 124 | {{velocity}} | ||
| |
3.1 | 125 | #if ("$!request.appName" != '') |
| 126 | #if ($xcontext.action == 'get') | ||
| 127 | #validateAppName | ||
| |
1.1 | 128 | #else |
| 129 | ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string. | ||
| |
3.1 | 130 | #processStep |
| |
1.1 | 131 | #end |
| 132 | #else | ||
| |
3.1 | 133 | #showStep |
| |
1.1 | 134 | #end |
| |
4.1 | 135 | #set ($displayDocExtra = false) |
| |
1.1 | 136 | {{/velocity}} |