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