Version 2.1 by Thomas Mortagne on 2014/09/29 12:41

Hide last authors
Thomas Mortagne 2.1 1 {{include reference="AppWithinMinutes.WizardStep"/}}
Ludovic Dubost 1.1 2
3 {{velocity output="false"}}
4 #macro(showStep)
5 {{html wiki="true"}}
6 #appWizardHeader(1)
7 (% class="wizard-help" %)
8 (((
9 **$services.localization.render('platform.appwithinminutes.wizardStepHelpTitle')** $services.localization.render('platform.appwithinminutes.wizardStepHelpDescription')
10 (% class="steps vertical" %)
11 #foreach($index in [1, 2, 3])
12 * (% class="number" %)$index(%%) (% class="name" %)$services.localization.render("platform.appwithinminutes.wizardStep${index}Name")(%%)
13 (% class="description" %)$services.localization.render("platform.appwithinminutes.wizardStep${index}Description")
14 #end
15 )))
16 <form action="" method="post" class="xform wizard-body">
17 ; <label for="appName">$services.localization.render('platform.appwithinminutes.appNameLabel')</label>
18 (% class="xHint" %)$services.localization.render('platform.appwithinminutes.appNameHint')
19 : <input type="text" id="appName" name="appName" />
20 #appWizardFooter(1)
21 </form>
22 {{/html}}
23 #end
24
25 #macro(getAppDescriptor $appName)
26 #set($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass')
27 #set($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space")
28 #set($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $appName).execute())
29 #if($appDescriptors.size() > 0)
30 #set($appDescriptor = $xwiki.getDocument($appDescriptors.get(0)))
31 #end
32 #end
33
34 #macro(processStep)
35 ## Check if the application already exists.
36 #getAppDescriptor($request.appName)
37 #if($appDescriptor)
38 ## Edit an existing application. Use the configured class name.
39 #set($classStringRef = $appDescriptor.getObject($appDescriptorClassName).getProperty('class').value)
40 ## The class string reference is relative to the document holding the application descriptor.
41 #set($classRef = $services.model.resolveDocument($classStringRef, 'explicit', $appDescriptor.documentReference))
42 #else
43 ## Create a new application. Use the default class name.
Thomas Mortagne 2.1 44 #set($classRef = $services.model.createDocumentReference($doc.wiki, "${request.appName}Code", "#toXMLName($request.appName)Class"))
Ludovic Dubost 1.1 45 #end
46 #set($queryString = 'wizard=true')
47 #if(!$xwiki.exists($classRef))
48 #set($classTitle = "$request.appName Class")
Thomas Mortagne 2.1 49 #set($queryString = "$queryString&editor=inline&template=AppWithinMinutes.ClassTemplate&parent=${request.appName}.WebHome&title=$escapetool.url($classTitle)")
Ludovic Dubost 1.1 50 #end
51 $response.sendRedirect($xwiki.getURL($classRef, 'edit', $queryString))
52 #end
53
54 #macro(validateAppName $appName)
55 #getAppDescriptor("$!appName")
56 #if($appDescriptor)
57 ## Edit an existing application.
58 #set($appHomeRef = $appDescriptor.documentReference)
59 #set($classStringRef = $appDescriptor.getObject($appDescriptorClassName).getProperty('class').value)
60 ## The class string reference is relative to the document holding the application descriptor.
61 #set($appClassRef = $services.model.resolveDocument($classStringRef, 'explicit', $appDescriptor.documentReference))
62 #else
63 ## Create a new application.
64 #set($className = "#toXMLName($appName)")
65 #if($className == '')
66 (% class="xErrorMsg" %)$services.localization.render('platform.appwithinminutes.appNameInvalidClassNameError')
67 #end
68 #set($appHomeRef = $services.model.createDocumentReference($doc.wiki, $appName, 'WebHome'))
Thomas Mortagne 2.1 69 #set($appClassRef = $services.model.createDocumentReference($doc.wiki, "$!{appName}Code", "$!{className}Class"))
Ludovic Dubost 1.1 70 #end
71 #set($appHomeURL = $stringtool.removeEnd($xwiki.getDocument($appHomeRef).getExternalURL(), 'WebHome'))
72 ; $services.localization.render('platform.appwithinminutes.appNamePreviewHomePageUrlLabel')
73 : {{{$!appHomeURL}}}
74 ; $services.localization.render('platform.appwithinminutes.appNamePreviewDataSpaceLabel')
75 : {{{$doc.wiki}}} » {{{$appName}}}
Thomas Mortagne 2.1 76 ; $services.localization.render('platform.appwithinminutes.appNamePreviewCodeSpaceLabel')
77 : {{{$doc.wiki}}} » {{{${appName}Code}}}
Ludovic Dubost 1.1 78 ; $services.localization.render('platform.appwithinminutes.appNamePreviewClassReferenceLabel')
79 : {{{$appClassRef.wikiReference.name}}} » {{{$appClassRef.lastSpaceReference.name}}} » {{{$appClassRef.name}}}
80 #if($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef))
81
82 {{warning}}$services.localization.render('platform.appwithinminutes.appNameIsUsedWarning'){{/warning}}
83 #end
84 #end
85 {{/velocity}}
86
87 {{velocity}}
88 #if("$!request.appName" != '')
89 #if($xcontext.action == 'get')
90 #validateAppName($request.appName)
91 #else
92 ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string.
93 #processStep()
94 #end
95 #else
96 #showStep()
97 #end
98 {{/velocity}}