Wiki source code of #sheetTitle('LiveTable View Sheet' $doc.fullName.equals('AppWithinMinutes.LiveTableViewSheet'))
Version 2.1 by Mark Kohlmann on 2020/04/03 03:53
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{template name="locationPicker_macros.vm" /}} | ||
2 | |||
3 | {{velocity output="false"}} | ||
4 | #macro (displayApp) | ||
5 | #set ($discard = $xwiki.ssx.use('AppWithinMinutes.LiveTableViewSheet')) | ||
6 | #set ($discard = $xwiki.jsx.use('AppWithinMinutes.LiveTableViewSheet', {'currentApp': $doc.getDocumentReference()})) | ||
7 | #if (!$isReadOnly) | ||
8 | #displayAppActions | ||
9 | #end | ||
10 | $doc.display('description') | ||
11 | ## Display the live table only if it was generated. | ||
12 | #if ($doc.content.length() > 0) | ||
13 | = $services.localization.render('platform.appwithinminutes.appLiveTableHeading') = | ||
14 | ## We don't use the Include macro (with empty reference) because we want the content to be executed with the rights | ||
15 | ## of the current document rather than the rights of the sheet. This is important because the user can modify the | ||
16 | ## content of the application home page which means we could execute untrusted content with the rights of the sheet. | ||
17 | ## Ideally we should use the Display macro with a parameter to disable the sheet, but we don't have this parameter. | ||
18 | ## We don't clean the HTML content because getRenderedContent() should produce clean HTML, unless the user has | ||
19 | ## disabled the HTML cleaning, in which case he will get what he asked for. Note that one good reason to disable | ||
20 | ## HTML cleaning is to preserve the whitespaces in the attribute values. | ||
21 | ## Escape {{ in the rendered content to be sure that the HTML macro is not closed unintentionally. | ||
22 | {{html clean="false"}}$doc.getRenderedContent($doc.content, | ||
23 | $doc.syntax.toIdString()).replace('{{', '{{'){{/html}} | ||
24 | #end | ||
25 | #end | ||
26 | |||
27 | #macro (displayAppActions) | ||
28 | ## Determine the user's rights | ||
29 | #set ($className = $stringtool.removeEnd($classFullName, 'Class')) | ||
30 | #set ($templateProviderReference = $services.model.resolveDocument("${className}TemplateProvider")) | ||
31 | #set ($templateProvider = $xwiki.getDocument($templateProviderReference)) | ||
32 | #set ($creationRestrictions = $templateProvider.getValue('creationRestrictions')) | ||
33 | #if ($creationRestrictions) | ||
34 | #if ($creationRestrictions.size() > 0) | ||
35 | #set ($dataSpaceRef = $services.model.resolveSpace($creationRestrictions.get(0))) | ||
36 | #else | ||
37 | ## There is no data space as the user can create application entries anywhere. Let's use the application space | ||
38 | ## when the user clicks on the Add New Entry link from the home page. | ||
39 | #set ($dataSpaceRef = $doc.documentReference.parent) | ||
40 | #end | ||
41 | #else | ||
42 | ## The template provider is missing. Fall-back on the old 'dataSpace' property. | ||
43 | #set ($dataSpaceRef = $services.model.resolveSpace($doc.getValue('dataSpace'), 'explicit', | ||
44 | $doc.documentReference)) | ||
45 | #end | ||
46 | #set ($hasCreateData = $services.security.authorization.hasAccess('edit', $dataSpaceRef)) | ||
47 | #set ($hasDeleteData = $services.security.authorization.hasAccess('admin', $dataSpaceRef)) | ||
48 | #set ($translationsRef = $services.model.resolveDocument("${className}Translations")) | ||
49 | #set ($hasEditTranslations = $xwiki.isMultiLingual() && $xwiki.exists($translationsRef) | ||
50 | && $services.security.authorization.hasAccess('edit', $translationsRef)) | ||
51 | #set ($classRef = $services.model.resolveDocument($classFullName)) | ||
52 | #set ($hasEditApplication = $services.security.authorization.hasAccess('edit', $classRef)) | ||
53 | #set ($hasDeleteApplication = $hasDeleteData | ||
54 | && $services.security.authorization.hasAccess('admin', $doc.documentReference.parent) | ||
55 | && $services.security.authorization.hasAccess('admin', $classRef.parent)) | ||
56 | ## Display the application actions based on the user's rights | ||
57 | #if ($hasCreateData || $hasDeleteData || $hasEditApplication || $hasEditTranslations || $hasDeleteApplication) | ||
58 | (% id="actionBox" class="floatinginfobox" %) | ||
59 | ((( | ||
60 | = $services.localization.render('platform.appwithinminutes.appHomePageActionsHeading') = | ||
61 | #if ($hasCreateData) | ||
62 | * [[$services.localization.render('platform.appwithinminutes.appHomePageAddEntryHint')>>||anchor="AddNewEntry" class="action add"]]## | ||
63 | #if ("$!templateProvider.getValue('terminal')" == '1') | ||
64 | #set ($entryReference = $services.model.createDocumentReference('__entryName__', $dataSpaceRef)) | ||
65 | #else | ||
66 | #set ($entryReference = $services.model.resolveDocument('', 'default', | ||
67 | $services.model.createSpaceReference('__entryName__', $dataSpaceRef))) | ||
68 | #end | ||
69 | ## We need to set the title if we want to be able to sort or filter the doc.title live table column. | ||
70 | #set ($params = { | ||
71 | 'template': "${className}Template", | ||
72 | 'title': '__entryName__', | ||
73 | 'parent': $services.model.serialize($doc.documentReference, 'local') | ||
74 | }) | ||
75 | #if ($xwiki.getDocument($classRef).xWikiClass.properties.size() > 0) | ||
76 | ## The entry has properties so go in edit mode to edit them. | ||
77 | #set ($action = 'edit') | ||
78 | #set ($params.editor = 'inline') | ||
79 | #else | ||
80 | ## There are no properties to edit so create the new entry and get back to the home page. | ||
81 | #set ($action = 'save') | ||
82 | #set ($discard = $params.putAll({ | ||
83 | 'xredirect': $doc.getURL(), | ||
84 | 'form_token': $services.csrf.token | ||
85 | })) | ||
86 | #end | ||
87 | {{html}}<input type="hidden" value="$xwiki.getURL($entryReference, $action, $escapetool.url($params))" />{{/html}} | ||
88 | #end | ||
89 | #if ($hasEditApplication) | ||
90 | #set ($queryString = $escapetool.url({ | ||
91 | 'appName': $doc.space, | ||
92 | 'resolve': true | ||
93 | })) | ||
94 | * [[$services.localization.render('platform.appwithinminutes.appHomePageEditAppLabel')>>AppWithinMinutes.CreateApplication||queryString="$queryString" class="action edit"]] | ||
95 | #end | ||
96 | #if ($hasEditTranslations) | ||
97 | * [[$services.localization.render('platform.appwithinminutes.appHomePageTranslateAppLabel')>>path:${xwiki.getURL($translationsRef, 'edit', 'editor=wiki')}||class="action translate"]] | ||
98 | #end | ||
99 | #if ($hasDeleteData) | ||
100 | #set ($deleteDataURL = $xwiki.getURL('AppWithinMinutes.DeleteApplication', 'view', $escapetool.url({ | ||
101 | 'appName': $doc.space, | ||
102 | 'resolve': true, | ||
103 | 'scope': 'entries', | ||
104 | 'xredirect': $doc.getURL() | ||
105 | }))) | ||
106 | * [[$services.localization.render('platform.appwithinminutes.appHomePageDeleteEntriesLabel')>>path:${deleteDataURL}||class="action deleteData"]] | ||
107 | #end | ||
108 | #if ($hasDeleteApplication) | ||
109 | #set ($deleteAppURL = $xwiki.getURL('AppWithinMinutes.DeleteApplication', 'view', $escapetool.url({ | ||
110 | 'appName': $doc.space, | ||
111 | 'resolve': true, | ||
112 | 'xredirect': $doc.getURL() | ||
113 | }))) | ||
114 | * [[$services.localization.render('platform.appwithinminutes.appHomePageDeleteAppLabel')>>path:${deleteAppURL}||class="action delete"]] | ||
115 | #end | ||
116 | ))) | ||
117 | #end | ||
118 | #end | ||
119 | |||
120 | #macro (renameAppModal) | ||
121 | <div class="modal" id="renameAppModal" tabindex="-1" role="dialog" aria-labelledby="renameAppModal-label" | ||
122 | data-backdrop="static" data-keyboard="false"> | ||
123 | <div class="modal-dialog" role="document"> | ||
124 | <form class="modal-content xform"> | ||
125 | <div class="modal-header"> | ||
126 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
127 | <span aria-hidden="true">×</span> | ||
128 | </button> | ||
129 | <span class="modal-title" id="renameAppModal-label">Rename Application</span> | ||
130 | </div> | ||
131 | <div class="modal-body"> | ||
132 | #renameAppModalBody | ||
133 | </div> | ||
134 | <div class="modal-footer"> | ||
135 | <button type="button" class="btn btn-default" data-dismiss="modal"> | ||
136 | $escapetool.xml($services.localization.render('cancel')) | ||
137 | </button> | ||
138 | <button type="submit" class="btn btn-primary" disabled="disabled"> | ||
139 | $escapetool.xml($services.localization.render('core.rename.submit')) | ||
140 | </button> | ||
141 | </div> | ||
142 | </form> | ||
143 | </div> | ||
144 | </div> | ||
145 | #end | ||
146 | |||
147 | #macro (renameAppModalBody) | ||
148 | <div class="box infomessage"> | ||
149 | $services.icon.renderHTML('info') | ||
150 | $services.localization.render('appWithinMinutes.renameApp.changeAppTitleInfo') | ||
151 | </div> | ||
152 | <div class="box warningmessage"> | ||
153 | $services.icon.renderHTML('warning') | ||
154 | $services.localization.render('appWithinMinutes.renameApp.regenerateAppCodeWarning') | ||
155 | </div> | ||
156 | <div class="hidden"> | ||
157 | <input type="hidden" name="form_token" value="$!escapetool.xml($services.csrf.token)" /> | ||
158 | <input type="hidden" name="oldAppReference" value="$escapetool.xml( | ||
159 | $services.model.serialize($doc.documentReference.parent, 'local'))"/> | ||
160 | <span class="appNameEmptyError xErrorMsg"> | ||
161 | $services.localization.render("platform.appwithinminutes.appNameEmptyError") | ||
162 | </span> | ||
163 | <span class="pageExistsError xErrorMsg"> | ||
164 | $services.localization.render("appWithinMinutes.renameApp.pageExistsError") | ||
165 | </span> | ||
166 | <span class="locationForbiddenError xErrorMsg"> | ||
167 | $services.localization.render("appWithinMinutes.renameApp.locationForbiddenError") | ||
168 | </span> | ||
169 | </div> | ||
170 | #set ($appName = $doc.pageReference.name) | ||
171 | #set ($isNestedPage = $doc.documentReference.name == $services.model.getEntityReference('DOCUMENT', 'default').name) | ||
172 | #set ($parentReference = $doc.documentReference.parent) | ||
173 | #if ($isNestedPage) | ||
174 | #set ($parentReference = $parentReference.parent) | ||
175 | #end | ||
176 | #locationPicker({ | ||
177 | 'id': 'renameApp', | ||
178 | 'title': { | ||
179 | 'label': 'appWithinMinutes.renameApp.newName.label', | ||
180 | 'hint': 'platform.appwithinminutes.appNameHint', | ||
181 | 'name': 'newAppName', | ||
182 | 'value': $appName, | ||
183 | 'placeholder': 'appWithinMinutes.renameApp.newName.label' | ||
184 | }, | ||
185 | 'preview': { | ||
186 | 'label': 'appWithinMinutes.renameApp.location.label', | ||
187 | 'hint': 'appWithinMinutes.renameApp.location.hint' | ||
188 | }, | ||
189 | 'parent': { | ||
190 | 'label': 'appWithinMinutes.renameApp.parent.label', | ||
191 | 'hint': 'appWithinMinutes.renameApp.parent.hint', | ||
192 | 'name': 'newAppParentReference', | ||
193 | 'reference': $parentReference, | ||
194 | 'placeholder': 'appWithinMinutes.createApp.parent.placeholder' | ||
195 | } | ||
196 | }) | ||
197 | #end | ||
198 | {{/velocity}} | ||
199 | |||
200 | {{velocity}} | ||
201 | #set ($liveTableObj = $doc.getObject('AppWithinMinutes.LiveTableClass')) | ||
202 | #if ($liveTableObj) | ||
203 | #set ($discard = $doc.use($liveTableObj)) | ||
204 | #set ($classFullName = $doc.getValue('class')) | ||
205 | #if ("$!classFullName" == '' || !$xwiki.exists($classFullName)) | ||
206 | {{warning}} | ||
207 | $services.icon.render('warning') {{translation key="platform.appwithinminutes.appHomePageMovedWarning"/}} | ||
208 | {{/warning}} | ||
209 | |||
210 | #end | ||
211 | #displayApp() | ||
212 | |||
213 | {{html clean="false"}} | ||
214 | #renameAppModal() | ||
215 | {{/html}} | ||
216 | #end | ||
217 | {{/velocity}} |