Wiki source code of Create Application
Version 3.1 by Barry Bishop on 2016/03/23 19:40
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 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(1) | ||
| 9 | (% class="wizard-help" %) | ||
| 10 | ((( | ||
| 11 | **$services.localization.render('platform.appwithinminutes.wizardStepHelpTitle')** $services.localization.render('platform.appwithinminutes.wizardStepHelpDescription') | ||
| 12 | (% class="steps vertical" %) | ||
| 13 | #foreach($index in [1, 2, 3]) | ||
| 14 | * (% class="number" %)$index(%%) (% class="name" %)$services.localization.render("platform.appwithinminutes.wizardStep${index}Name")(%%) | ||
| 15 | (% class="description" %)$services.localization.render("platform.appwithinminutes.wizardStep${index}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 | 'editor': 'inline', | ||
| 63 | 'template': 'AppWithinMinutes.ClassTemplate', | ||
| 64 | 'parent': $services.model.serialize($appHomeRef), | ||
| 65 | 'title': "$appReference.name Class" | ||
| 66 | })) | ||
| 67 | #end | ||
| 68 | $response.sendRedirect($xwiki.getURL($appClassRef, 'edit', $escapetool.url($queryString))) | ||
| 69 | #end | ||
| 70 | |||
| 71 | #macro (validateAppName) | ||
| 72 | #getAppReference | ||
| 73 | #if (!$appReference) | ||
| 74 | (% class="xErrorMsg" %)$services.localization.render('platform.appwithinminutes.appNameEmptyError') | ||
| 75 | #else | ||
| 76 | #getAppDescriptor($appReference) | ||
| 77 | #if ($appDescriptor) | ||
| 78 | ## Edit an existing application. | ||
| 79 | #set ($appDescriptorObj = $appDescriptor.getObject($appDescriptorClassName)) | ||
| 80 | #set ($appClassRef = $appDescriptorObj.getValue('class')) | ||
| 81 | ## The class reference is relative to the document holding the application descriptor. | ||
| 82 | #set ($appClassRef = $services.model.resolveDocument($appClassRef, 'explicit', $appDescriptor.documentReference)) | ||
| 83 | #set ($appDataRef = $appDescriptorObj.getValue('dataSpace')) | ||
| 84 | ## The data space reference is relative to the document holding the application descriptor. | ||
| 85 | #set ($appDataRef = $services.model.resolveSpace($appDataRef, 'explicit', $appDescriptor.documentReference)) | ||
| 86 | #else | ||
| 87 | ## Create a new application. | ||
| 88 | #set ($appDataRef = $services.model.createSpaceReference('Data', $appReference)) | ||
| 89 | #set ($appCodeRef = $services.model.createSpaceReference('Code', $appReference)) | ||
| 90 | #set ($appClassRef = $services.model.createDocumentReference("$!{appReference.name}Class", $appCodeRef)) | ||
| 91 | #end | ||
| 92 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewHomePageUrlLabel') | ||
| 93 | : {{{$!xwiki.getDocument($appReference).externalURL}}} | ||
| 94 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewDataSpaceLabel') | ||
| 95 | : {{html clean="false"}}#hierarchy($appDataRef){{/html}} | ||
| 96 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewCodeSpaceLabel') | ||
| 97 | : {{html clean="false"}}#hierarchy($appClassRef.parent){{/html}} | ||
| 98 | ; $services.localization.render('platform.appwithinminutes.appNamePreviewClassReferenceLabel') | ||
| 99 | : {{html clean="false"}}#hierarchy($appClassRef){{/html}} | ||
| 100 | #set ($appHomeRef = $services.model.resolveDocument('', 'default', $appReference)) | ||
| 101 | #if ($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef)) | ||
| 102 | |||
| 103 | {{warning}}$services.localization.render('platform.appwithinminutes.appNameIsUsedWarning'){{/warning}} | ||
| 104 | #end | ||
| 105 | #end | ||
| 106 | #end | ||
| 107 | |||
| 108 | #macro (getAppReference) | ||
| 109 | #if ($request.resolve == 'true') | ||
| 110 | #set ($appReference = $services.model.resolveSpace($request.appName)) | ||
| 111 | #elseif ("$!request.appName" != '') | ||
| 112 | #set ($parentReference = $doc.documentReference.wikiReference) | ||
| 113 | #if ("$!request.appParentReference" != '') | ||
| 114 | #set ($parentReference = $services.model.resolveSpace($request.appParentReference)) | ||
| 115 | #end | ||
| 116 | #set ($appReference = $services.model.createSpaceReference($request.appName, $parentReference)) | ||
| 117 | #else | ||
| 118 | #set ($appReference = $NULL) | ||
| 119 | #end | ||
| 120 | #end | ||
| 121 | |||
| 122 | #macro (getAppDescriptor $appReference) | ||
| 123 | #set ($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass') | ||
| 124 | #set ($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space") | ||
| 125 | #set ($localSpaceReference = $services.model.serialize($appReference, 'local')) | ||
| 126 | #set ($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $localSpaceReference).execute()) | ||
| 127 | #if ($appDescriptors.size() > 0) | ||
| 128 | #set ($appDescriptor = $xwiki.getDocument($appDescriptors.get(0))) | ||
| 129 | #end | ||
| 130 | #end | ||
| 131 | {{/velocity}} | ||
| 132 | |||
| 133 | {{velocity}} | ||
| 134 | #if ("$!request.appName" != '') | ||
| 135 | #if ($xcontext.action == 'get') | ||
| 136 | #validateAppName | ||
| 137 | #else | ||
| 138 | ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string. | ||
| 139 | #processStep | ||
| 140 | #end | ||
| 141 | #else | ||
| 142 | #showStep | ||
| 143 | #end | ||
| 144 | #set ($docextras = []) | ||
| 145 | {{/velocity}} |