# Wiki source code of LiveTableEditSheet

Last modified by Jean Franco on 2022/06/19 21:14
Export
Office Formats
Export as PDF Export as ODT Export as RTF
Other Formats
Export as HTML

Show last authors

author | version | line-number | content
--- | --- | --- | ---
|  | 1 | {{include reference="XWiki.TemplateProviderMacros" /}}
|  | 2 |
|  | 3 | {{include reference="AppWithinMinutes.VelocityMacros" /}}
|  | 4 |
|  | 5 | {{velocity output="false"}}
|  | 6 | #macro (listAvailableColumns $classReference)
|  | 7 | <select id="availableColumns">
|  | 8 | #set ($classFields = $xwiki.getDocument($classReference).getxWikiClass().properties)
|  | 9 | #if ($classFields.size() > 0)
|  | 10 | <optgroup label="$escapetool.xml($services.localization.render(
|  | 11 | 'platform.appwithinminutes.liveTableEditorClassFieldColumnGroupLabel'))" id="classFields">
|  | 12 | #foreach ($field in $classFields)
|  | 13 | <option value="$field.name">$escapetool.xml($field.translatedPrettyName)</option>
|  | 14 | #end
|  | 15 | </optgroup>
|  | 16 | #end
|  | 17 | <optgroup label="$escapetool.xml($services.localization.render(
|  | 18 | 'platform.appwithinminutes.liveTableEditorGenericColumnGroupLabel'))">
|  | 19 | #foreach ($entry in $genericColumns.entrySet())
|  | 20 | <option value="$entry.key" title="$escapetool.xml($entry.value.get(1))">
|  | 21 | $escapetool.xml($entry.value.get(0))
|  | 22 | </option>
|  | 23 | #end
|  | 24 | </optgroup>
|  | 25 | </select>
|  | 26 | <a href="#addColumn" class="addColumn" title="$services.localization.render(
|  | 27 | 'platform.appwithinminutes.liveTableEditorAddColumnHint')">$services.icon.renderHTML('add')</a>
|  | 28 | #end
|  | 29 |
|  | 30 | #macro (displayHelpPanel)
|  | 31 | #set ($genericColumns = {
|  | 32 | 'doc.title': [
|  | 33 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocTitleColumnName'),
|  | 34 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocTitleColumnDescription')
|  | 35 | ],
|  | 36 | 'doc.name': [
|  | 37 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocNameColumnName'),
|  | 38 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocNameColumnDescription')
|  | 39 | ],
|  | 40 | 'doc.location': [
|  | 41 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocLocationColumnName'),
|  | 42 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocLocationColumnDescription')
|  | 43 | ],
|  | 44 | 'doc.author': [
|  | 45 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocAuthorColumnName'),
|  | 46 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocAuthorColumnDescription')
|  | 47 | ],
|  | 48 | 'doc.creator': [
|  | 49 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreatorColumnName'),
|  | 50 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreatorColumnDescription')
|  | 51 | ],
|  | 52 | 'doc.date': [
|  | 53 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocDateColumnName'),
|  | 54 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocDateColumnDescription')
|  | 55 | ],
|  | 56 | 'doc.creationDate': [
|  | 57 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreationDateColumnName'),
|  | 58 | $services.localization.render('platform.appwithinminutes.liveTableEditorDocCreationDateColumnDescription')
|  | 59 | ],
|  | 60 | '_actions': [
|  | 61 | $services.localization.render('platform.appwithinminutes.liveTableEditorActionsColumnName'),
|  | 62 | $services.localization.render('platform.appwithinminutes.liveTableEditorActionsColumnDescription')
|  | 63 | ],
|  | 64 | '_attachments': [
|  | 65 | $services.localization.render('platform.appwithinminutes.liveTableEditorAttachmentsColumnName'),
|  | 66 | $services.localization.render('platform.appwithinminutes.liveTableEditorAttachmentsColumnDescription')
|  | 67 | ],
|  | 68 | '_images': [
|  | 69 | $services.localization.render('platform.appwithinminutes.liveTableEditorImagesColumnName'),
|  | 70 | $services.localization.render('platform.appwithinminutes.liveTableEditorImagesColumnDescription')
|  | 71 | ]
|  | 72 | })
|  | 73 | <div class="wizard-help">
|  | 74 | <p>
|  | 75 | <strong>$services.localization.render('platform.appwithinminutes.liveTableEditorHelpTitle')</strong>
|  | 76 | $services.localization.render('platform.appwithinminutes.liveTableEditorHelpDescription')
|  | 77 | </p>
|  | 78 | <dl>
|  | 79 | #foreach ($columnId in ['doc.title', 'doc.location', 'doc.date', 'doc.author', '_actions'])
|  | 80 | <dt>$genericColumns.get($columnId).get(0)</dt>
|  | 81 | <dd>$genericColumns.get($columnId).get(1)</dd>
|  | 82 | #end
|  | 83 | </dl>
|  | 84 | </div>
|  | 85 | #end
|  | 86 |
|  | 87 | #macro (displayFormFields)
|  | 88 | <div class="hidden">
|  | 89 | ## Make sure that only the sheet content is rendered when the class is saved using AJAX.
|  | 90 | <input type="hidden" name="xpage" value="plain" />
|  | 91 | ## We prevent the class name and the data space from being edited directly. They can be specified in the URL.
|  | 92 | #getAppClassReference($doc)
|  | 93 | <input type="hidden" name="AppWithinMinutes.LiveTableClass_0_class"
|  | 94 | value="$escapetool.xml($services.model.serialize($classReference, 'local'))" />
|  | 95 | #displayPropertyValue('dataSpace', 'hidden')
|  | 96 | ## We have to pass the list of available columns to the JavaScript code.
|  | 97 | #listAvailableColumns($classReference)
|  | 98 | </div>
|  | 99 | <dl>
|  | 100 | <dt>
|  | 101 | <label for="xwikidoctitleinput">$services.localization.render('core.editors.content.titleField.label')</label>
|  | 102 | <span class="xHint">$services.localization.render('platform.appwithinminutes.liveTableEditorTitleHint')</span>
|  | 103 | </dt>
|  | 104 | <dd><input id="xwikidoctitleinput" type="text" name="title" value="$escapetool.xml($doc.title)"/></dd>
|  | 105 | <dt>
|  | 106 | <label for="AppWithinMinutes.LiveTableClass_0_description">
|  | 107 | $doc.displayPrettyName('description', false, false)
|  | 108 | </label>
|  | 109 | <span class="xHint">
|  | 110 | $services.localization.render('platform.appwithinminutes.liveTableEditorDescriptionHint')
|  | 111 | </span>
|  | 112 | </dt>
|  | 113 | <dd>#displayPropertyValue('description')</dd>
|  | 114 | <dt>
|  | 115 | <label for="AppWithinMinutes.LiveTableClass_0_columns">$doc.displayPrettyName('columns', false, false)</label>
|  | 116 | <span class="xHint">$services.localization.render('platform.appwithinminutes.liveTableEditorColumnsHint')</span>
|  | 117 | </dt>
|  | 118 | <dd>#displayPropertyValue('columns')</dd>
|  | 119 | </dl>
|  | 120 | #end
|  | 121 |
|  | 122 | #macro (getApplicationIcon $classReference)
|  | 123 | #set ($applicationIcon = '')
|  | 124 | ## Look for the corresponding UI extension.
|  | 125 | #set ($uixPointId = 'org.xwiki.platform.panels.Applications')
|  | 126 | #set ($uixObject = $doc.getObject('XWiki.UIExtensionClass', 'extensionPointId', $uixPointId))
|  | 127 | #set ($uixId = $uixObject.getValue('name'))
|  | 128 | #foreach ($uix in $services.uix.getExtensions($uixPointId))
|  | 129 | #if ($uix.id == $uixId)
|  | 130 | #set ($applicationIcon = $uix.parameters.icon)
|  | 131 | #end
|  | 132 | #end
|  | 133 | #if ("$!applicationIcon" == '')
|  | 134 | ## Fallback on the entry icon.
|  | 135 | #set ($templateProviderReference = $services.model.createDocumentReference(
|  | 136 | "$stringtool.removeEnd($classReference.name, 'Class')TemplateProvider",
|  | 137 | $classReference.parent
|  | 138 | ))
|  | 139 | #set ($entryIcon = $xwiki.getDocument($templateProviderReference).getValue('icon'))
|  | 140 | #if ("$!entryIcon" != '')
|  | 141 | #set ($applicationIcon = "icon:$entryIcon")
|  | 142 | #else
|  | 143 | #set ($applicationIcon = 'icon:application')
|  | 144 | #end
|  | 145 | #end
|  | 146 | #end
|  | 147 |
|  | 148 | #macro (displayIcon)
|  | 149 | #if ($services.uix)
|  | 150 | #getApplicationIcon($classReference)
|  | 151 | <dl>
|  | 152 | <dt>
|  | 153 | <label for="applicationIcon">
|  | 154 | $services.localization.render('platform.appwithinminutes.liveTableEditorIcon')
|  | 155 | </label>
|  | 156 | <span class="xHint">
|  | 157 | $services.localization.render('platform.appwithinminutes.liveTableEditorIconHintWithPicker',
|  | 158 | [$xwiki.getSkinFile('icons/silk/index_abc.png')])
|  | 159 | </span>
|  | 160 | </dt>
|  | 161 | <dd>
|  | 162 | <input id="applicationIcon" name="applicationIcon" type="text" size="10"
|  | 163 | value="$!escapetool.xml($applicationIcon)" />
|  | 164 | </dd>
|  | 165 | </dl>
|  | 166 | #end
|  | 167 | #end
|  | 168 |
|  | 169 | #macro (doEdit)
|  | 170 | {{html clean="false"}}
|  | 171 | #set ($liveTableObj = $doc.getObject('AppWithinMinutes.LiveTableClass', true))
|  | 172 | #set ($discard = $doc.use($liveTableObj))
|  | 173 | #set ($discard = $xwiki.ssx.use('AppWithinMinutes.LiveTableEditSheet'))
|  | 174 | #set ($discard = $xwiki.jsx.use('AppWithinMinutes.LiveTableEditSheet'))
|  | 175 | #if ("$!request.wizard" == 'true')
|  | 176 | #appWizardHeader('presentation')
|  | 177 | #end
|  | 178 | #displayHelpPanel()
|  | 179 | <div class="form-body">
|  | 180 | #displayFormFields()
|  | 181 | #displayIcon()
|  | 182 | #if ("$!request.wizard" == 'true')
|  | 183 | #appWizardFooter('presentation')
|  | 184 | #end
|  | 185 | </div>
|  | 186 | <div class="clearfloats"></div>
|  | 187 | {{/html}}
|  | 188 |
|  | 189 | {{iconPicker id="applicationIcon" prefix="icon:" /}}
|  | 190 | #end
|  | 191 |
|  | 192 | #macro (maybeGrantSpaceAdminRight $spaceRef)
|  | 193 | ## Grant space administration rights only if the space is new. Don't overwrite existing space preferences.
|  | 194 | #set ($spaceHomeRef = $services.model.resolveDocument('', 'default', $spaceRef))
|  | 195 | #set ($spacePrefsRef = $services.model.resolveDocument('WebPreferences', 'explicit', $spaceRef))
|  | 196 | #if (!$xwiki.exists($spaceHomeRef) && !$xwiki.exists($spacePrefsRef))
|  | 197 | #set ($spacePrefsDoc = $xwiki.getDocument($spacePrefsRef))
|  | 198 | #set ($discard = $spacePrefsDoc.use($spacePrefsDoc.getObject('XWiki.XWikiGlobalRights', true)))
|  | 199 | #set ($discard = $spacePrefsDoc.set('allow', 1))
|  | 200 | #set ($discard = $spacePrefsDoc.set('levels', 'admin'))
|  | 201 | #set ($discard = $spacePrefsDoc.set('users', $services.model.serialize($xcontext.userReference, 'default')))
|  | 202 | #set ($discard = $spacePrefsDoc.setTitle('$services.localization.render(''admin.preferences.title'')'))
|  | 203 | #set ($discard = $spacePrefsDoc.setParent($services.model.serialize($spaceHomeRef, 'default')))
|  | 204 | #set ($discard = $spacePrefsDoc.setHidden(true))
|  | 205 | #set ($discard = $spacePrefsDoc.saveWithProgrammingRights($services.localization.render(
|  | 206 | 'platform.appwithinminutes.grantSpaceAdminRightsSaveComment')))
|  | 207 | #end
|  | 208 | #end
|  | 209 |
|  | 210 | #macro (maybeGrantSpaceAdminRights)
|  | 211 | ## Application space
|  | 212 | #set ($appReference = $doc.documentReference.parent)
|  | 213 | #maybeGrantSpaceAdminRight($appReference)
|  | 214 | ## Code space (if it's not nested inside the application space)
|  | 215 | #set ($className = $request.get('AppWithinMinutes.LiveTableClass_0_class'))
|  | 216 | #set ($classReference = $services.model.resolveDocument($className))
|  | 217 | #if (!$classReference.hasParent($appReference))
|  | 218 | #maybeGrantSpaceAdminRight($classReference.parent)
|  | 219 | #end
|  | 220 | #end
|  | 221 |
|  | 222 | #macro (updateAndSaveLiveTable)
|  | 223 | #set ($discard = $doc.updateObjectFromRequest('AppWithinMinutes.LiveTableClass'))
|  | 224 | #set ($liveTableGeneratorDoc = $xwiki.getDocument('AppWithinMinutes.LiveTableGenerator'))
|  | 225 |
|  | 226 | ## Generate the LiveTable by displaying the LiveTableGenerator document in the context of the current document.
|  | 227 | #set ($displayParameters = $services.display.createDocumentDisplayerParameters())
|  | 228 | #set ($discard = $displayParameters.setExecutionContextIsolated(false))
|  | 229 | #set ($discard = $displayParameters.setContentTranslated(true))
|  | 230 | #set ($generatedLiveTableContent = $services.display.content($liveTableGeneratorDoc, {
|  | 231 | 'outputSyntaxId': 'plain/1.0',
|  | 232 | 'displayerParameters': $displayParameters
|  | 233 | }))
|  | 234 |
|  | 235 | ## Use the generated LiveTable content for the data home page.
|  | 236 | #set ($dataSpaceReference = $services.model.resolveSpace($doc.getValue('dataSpace')))
|  | 237 | #set ($dataSpaceHomeReference = $services.model.resolveDocument('', 'default', $dataSpaceReference))
|  | 238 | #if ($dataSpaceHomeReference.equals($doc.documentReference) || !$xwiki.exists($dataSpaceHomeReference))
|  | 239 | ## Either the application space and the data space are one and the same or this is a new application and we don't
|  | 240 | ## want to promote the data space anymore.
|  | 241 | #set ($dataHomePage = $doc)
|  | 242 | #else
|  | 243 | ## The application data is stored in a different space.
|  | 244 | #set ($dataHomePage = $xwiki.getDocument($dataSpaceHomeReference))
|  | 245 | #set ($discard = $dataHomePage.setHidden(true))
|  | 246 | #set ($escapedAppName = $doc.documentReference.parent.name.toLowerCase().replace("'", "''"))
|  | 247 | #set ($discard = $dataHomePage.setTitle("${escapetool.d}services.localization.render('${escapedAppName}.dataSpace.title')"))
|  | 248 |
|  | 249 | ## Update the home page content.
|  | 250 | #set ($homePageContent = '')
|  | 251 | #if ("$!generatedLiveTableContent" != '')
|  | 252 | ## Include the entries live table in the application home page.
|  | 253 | #set ($escapedReference = $services.model.serialize($dataSpaceHomeReference).replaceAll('([~"])', '~$1'))
|  | 254 | #set ($homePageContent = "{{include reference=""$escapedReference"" /}}")
|  | 255 | #end
|  | 256 | #set ($discard = $doc.setContent($homePageContent))
|  | 257 | #end
|  | 258 | #set ($discard = $dataHomePage.setContent($generatedLiveTableContent))
|  | 259 | ## We assume for now that the output produced by the live table generator uses the same syntax as the code of the live
|  | 260 | ## table generator. We have to set the syntax because the default wiki syntax (used when creating new wiki pages)
|  | 261 | ## could be different than the one used by the live table generator.
|  | 262 | #set ($discard = $dataHomePage.setSyntax($liveTableGeneratorDoc.syntax))
|  | 263 |
|  | 264 | #set ($minorEdit = "$!request.minorEdit" != '')
|  | 265 | #set ($comment = $request.comment)
|  | 266 | #if ("$!comment" == '')
|  | 267 | #set ($comment = $services.localization.render('platform.appwithinminutes.liveTableEditorSaveComment'))
|  | 268 | #end
|  | 269 |
|  | 270 | #if ($dataHomePage != $doc)
|  | 271 | ## Save the data home page.
|  | 272 | #set ($discard = $dataHomePage.save($comment, $minorEdit))
|  | 273 | #end
|  | 274 |
|  | 275 | ## Save the application home page.
|  | 276 | #set ($discard = $doc.save($comment, $minorEdit))
|  | 277 | #end
|  | 278 |
|  | 279 | #macro (updateAndSaveIcon)
|  | 280 | #set ($uix = $doc.getObject('XWiki.UIExtensionClass', true))
|  | 281 | #set ($discard = $uix.set('name', "platform.panels.${doc.space}Application"))
|  | 282 | #set ($discard = $uix.set('extensionPointId', 'org.xwiki.platform.panels.Applications'))
|  | 283 | #set ($uixParams = [
|  | 284 | "label=$doc.plainTitle",
|  | 285 | "target=$doc.fullName",
|  | 286 | "icon=$request.applicationIcon"
|  | 287 | ])
|  | 288 | #set ($discard = $uix.set('parameters', $stringtool.join($uixParams, $util.newline)))
|  | 289 | #set ($hasWikiAdminRights = $services.security.authorization.hasAccess('admin', $doc.documentReference.wikiReference))
|  | 290 | #set ($discard = $uix.set('scope', "#if ($hasWikiAdminRights)wiki#{else}user#end"))
|  | 291 | #set ($discard = $doc.save('Updated application icon', true))
|  | 292 | #end
|  | 293 |
|  | 294 | #macro (doSave)
|  | 295 | #maybeGrantSpaceAdminRights()
|  | 296 | #updateAndSaveLiveTable()
|  | 297 | #updateAndSaveIcon()
|  | 298 | #if ($action == 'save')
|  | 299 | #if ($errorMessage)
|  | 300 | {{html clean="false"}}
|  | 301 | <div class="box errormessage">$errorMessage</div>
|  | 302 | {{/html}}
|  | 303 | #else
|  | 304 | ## Redirect to view mode.
|  | 305 | $response.sendRedirect($doc.getURL())
|  | 306 | #end
|  | 307 | #else
|  | 308 | #if ($errorMessage)
|  | 309 | $response.sendError(400, $errorMessage)
|  | 310 | #else
|  | 311 | $response.setStatus(204)
|  | 312 | #end
|  | 313 | #end
|  | 314 | #end
|  | 315 | {{/velocity}}
|  | 316 |
|  | 317 | {{velocity}}
|  | 318 | #if ("$!request.wizard" == 'true')
|  | 319 | {{include reference="AppWithinMinutes.WizardStep" /}}
|  | 320 | #end
|  | 321 | {{/velocity}}
|  | 322 |
|  | 323 | {{velocity}}
|  | 324 | ## Determine the action button that triggered the request
|  | 325 | #set ($action = $xcontext.action)
|  | 326 | #foreach ($paramName in $request.getParameterMap().keySet())
|  | 327 | #if ($paramName.startsWith('xaction_'))
|  | 328 | #set ($action = $paramName.substring(8))
|  | 329 | #break
|  | 330 | #end
|  | 331 | #end
|  | 332 | #if ($action == 'edit')
|  | 333 | #doEdit()
|  | 334 | #elseif ($action == 'save' || $action == 'saveandcontinue')
|  | 335 | #if ($services.csrf.isTokenValid($request.form_token))
|  | 336 | #doSave()
|  | 337 | #else
|  | 338 | $response.sendRedirect($services.csrf.getResubmissionURL())
|  | 339 | #end
|  | 340 | #end
|  | 341 | {{/velocity}}

# Applications

# Tips

If you're a new XWiki user, check out the Getting Started Guide.

Maila Networks
XWiki Debian 14.4.1