Wiki source code of LiveTable View Sheet

Last modified by Andrey Che on 2018/12/10 14:08

Show last authors
1 {{velocity}}
2 #set($liveTableObj = $doc.getObject('AppWithinMinutes.LiveTableClass'))
3 #if($liveTableObj)
4 #set($discard = $doc.use($liveTableObj))
5 #set($discard = $xwiki.ssx.use('AppWithinMinutes.LiveTableViewSheet'))
6 #set($discard = $xwiki.jsx.use('AppWithinMinutes.LiveTableViewSheet'))
7 #if (!$isReadOnly)
8 ## Determine the user's rights
9 #set($classFullName = $liveTableObj.getProperty('class').value)
10 #set($className = $stringtool.removeEnd($classFullName, 'Class'))
11 #set ($templateProviderReference = $services.model.resolveDocument("${className}TemplateProvider"))
12 #set ($templateProvider = $xwiki.getDocument($templateProviderReference))
13 #set ($creationRestrictions = $templateProvider.getValue('creationRestrictions'))
14 #if ($creationRestrictions)
15 #if ($creationRestrictions.size() > 0)
16 #set ($dataSpaceRef = $services.model.resolveSpace($creationRestrictions.get(0)))
17 #else
18 ## There is no data space as the user can create application entries anywhere. Let's use the application space
19 ## when the user clicks on the Add New Entry link from the home page.
20 #set ($dataSpaceRef = $doc.documentReference.parent)
21 #end
22 #else
23 ## The template provider is missing. Fall-back on the old 'dataSpace' property.
24 #set ($dataSpaceRef = $services.model.resolveSpace($liveTableObj.getValue('dataSpace'), 'explicit',
25 $doc.documentReference))
26 #end
27 #set($hasCreateData = $services.security.authorization.hasAccess('edit', $dataSpaceRef))
28 #set($hasDeleteData = $services.security.authorization.hasAccess('admin', $dataSpaceRef))
29 #set($classRef = $services.model.resolveDocument($classFullName))
30 #set($hasEditApplication = $services.security.authorization.hasAccess('edit', $classRef))
31 #set($translationsRef = $services.model.resolveDocument("${className}Translations"))
32 #set($hasEditTranslations = $xwiki.isMultiLingual() && $xwiki.exists($translationsRef)
33 && $services.security.authorization.hasAccess('edit', $translationsRef))
34 #set($hasDeleteApplication = $hasDeleteData
35 && $services.security.authorization.hasAccess('admin', $doc.documentReference.parent)
36 && $services.security.authorization.hasAccess('admin', $classRef.parent))
37 ## Display the application actions based on the user's rights
38 #if($hasCreateData || $hasDeleteData || $hasEditApplication || $hasEditTranslations || $hasDeleteApplication)
39 (% id="actionBox" class="floatinginfobox" %)
40 (((
41 = $services.localization.render('platform.appwithinminutes.appHomePageActionsHeading') =
42 #if($hasCreateData)
43 * [[$services.localization.render('platform.appwithinminutes.appHomePageAddEntryHint')>>||anchor="AddNewEntry" class="action add"]]##
44 #if ("$!templateProvider.getValue('terminal')" == '1')
45 #set ($entryReference = $services.model.createDocumentReference('__entryName__', $dataSpaceRef))
46 #else
47 #set ($entryReference = $services.model.resolveDocument('', 'default',
48 $services.model.createSpaceReference('__entryName__', $dataSpaceRef)))
49 #end
50 ## We need to set the title if we want to be able to sort or filter the doc.title live table column.
51 #set ($params = {
52 'template': "${className}Template",
53 'title': '__entryName__',
54 'parent': $services.model.serialize($doc.documentReference, 'local')
55 })
56 #if ($xwiki.getDocument($classRef).xWikiClass.properties.size() > 0)
57 ## The entry has properties so go in edit mode to edit them.
58 #set ($action = 'edit')
59 #set ($params.editor = 'inline')
60 #else
61 ## There are no properties to edit so create the new entry and get back to the home page.
62 #set ($action = 'save')
63 #set ($discard = $params.putAll({
64 'xredirect': $doc.getURL(),
65 'form_token': $services.csrf.token
66 }))
67 #end
68 {{html}}<input type="hidden" value="$xwiki.getURL($entryReference, $action, $escapetool.url($params))" />{{/html}}
69 #end
70 #if($hasEditApplication)
71 #set ($queryString = $escapetool.url({
72 'appName': $doc.space,
73 'resolve': true
74 }))
75 * [[$services.localization.render('platform.appwithinminutes.appHomePageEditAppLabel')>>AppWithinMinutes.CreateApplication||queryString="$queryString" class="action edit"]]
76 #end
77 #if($hasEditTranslations)
78 * [[$services.localization.render('platform.appwithinminutes.appHomePageTranslateAppLabel')>>path:$xwiki.getURL($translationsRef, 'edit', 'editor=wiki')||class="action translate"]]
79 #end
80 #if($hasDeleteData)
81 #set ($deleteDataURL = $xwiki.getURL('AppWithinMinutes.DeleteApplication', 'view', $escapetool.url({
82 'appName': $doc.space,
83 'resolve': true,
84 'scope': 'entries',
85 'xredirect': $doc.getURL()
86 })))
87 * [[$services.localization.render('platform.appwithinminutes.appHomePageDeleteEntriesLabel')>>path:$deleteDataURL||class="action deleteData"]]
88 #end
89 #if($hasDeleteApplication)
90 #set ($deleteAppURL = $xwiki.getURL('AppWithinMinutes.DeleteApplication', 'view', $escapetool.url({
91 'appName': $doc.space,
92 'resolve': true,
93 'xredirect': $doc.getURL()
94 })))
95 * [[$services.localization.render('platform.appwithinminutes.appHomePageDeleteAppLabel')>>path:$deleteAppURL||class="action delete"]]
96 #end
97 )))
98 #end
99 #end
100 $doc.display('description')
101 ## Display the live table only if it was generated.
102 #if($doc.content.length() > 0)
103 = $services.localization.render('platform.appwithinminutes.appLiveTableHeading') =
104 ## We don't use the Include macro (with empty reference) because we want the content to be executed with the rights
105 ## of the current document rather than the rights of the sheet. This is important because the user can modify the
106 ## content of the application home page which means we could execute untrusted content with the rights of the sheet.
107 ## Ideally we should use the Display macro with a parameter to disable the sheet, but we don't have this parameter.
108 ## We don't clean the HTML content because getRenderedContent() should produce clean HTML, unless the user has
109 ## disabled the HTML cleaning, in which case he will get what he asked for. Note that one good reason to disable
110 ## HTML cleaning is to preserve the whitespaces in the attribute values.
111 ## Escape {{ in the rendered content to be sure that the HTML macro is not closed unintentionally.
112 {{html clean="false"}}$doc.getRenderedContent($doc.content,
113 $doc.syntax.toIdString()).replace('{{', '&amp;#123;&amp;#123;'){{/html}}
114 #end
115 #end
116 {{/velocity}}