Wiki源代码LiveTableEditSheet
在2022-05-25 17:59上被ybq sz修改
Show last authors
| 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.jsfx.use('js/scriptaculous/dragdrop.js')) |
| 174 | #set ($discard = $xwiki.ssx.use('AppWithinMinutes.LiveTableEditSheet')) |
| 175 | #set ($discard = $xwiki.jsx.use('AppWithinMinutes.LiveTableEditSheet')) |
| 176 | #if ("$!request.wizard" == 'true') |
| 177 | #appWizardHeader('presentation') |
| 178 | #end |
| 179 | #displayHelpPanel() |
| 180 | <div class="form-body"> |
| 181 | #displayFormFields() |
| 182 | #displayIcon() |
| 183 | #if ("$!request.wizard" == 'true') |
| 184 | #appWizardFooter('presentation') |
| 185 | #end |
| 186 | </div> |
| 187 | <div class="clearfloats"></div> |
| 188 | {{/html}} |
| 189 | |
| 190 | {{iconPicker id="applicationIcon" prefix="icon:" /}} |
| 191 | #end |
| 192 | |
| 193 | #macro (maybeGrantSpaceAdminRight $spaceRef) |
| 194 | ## Grant space administration rights only if the space is new. Don't overwrite existing space preferences. |
| 195 | #set ($spaceHomeRef = $services.model.resolveDocument('', 'default', $spaceRef)) |
| 196 | #set ($spacePrefsRef = $services.model.resolveDocument('WebPreferences', 'explicit', $spaceRef)) |
| 197 | #if (!$xwiki.exists($spaceHomeRef) && !$xwiki.exists($spacePrefsRef)) |
| 198 | #set ($spacePrefsDoc = $xwiki.getDocument($spacePrefsRef)) |
| 199 | #set ($discard = $spacePrefsDoc.use($spacePrefsDoc.getObject('XWiki.XWikiGlobalRights', true))) |
| 200 | #set ($discard = $spacePrefsDoc.set('allow', 1)) |
| 201 | #set ($discard = $spacePrefsDoc.set('levels', 'admin')) |
| 202 | #set ($discard = $spacePrefsDoc.set('users', $services.model.serialize($xcontext.userReference, 'default'))) |
| 203 | #set ($discard = $spacePrefsDoc.setTitle('$services.localization.render(''admin.preferences.title'')')) |
| 204 | #set ($discard = $spacePrefsDoc.setParent($services.model.serialize($spaceHomeRef, 'default'))) |
| 205 | #set ($discard = $spacePrefsDoc.setHidden(true)) |
| 206 | #set ($discard = $spacePrefsDoc.saveWithProgrammingRights($services.localization.render( |
| 207 | 'platform.appwithinminutes.grantSpaceAdminRightsSaveComment'))) |
| 208 | #end |
| 209 | #end |
| 210 | |
| 211 | #macro (maybeGrantSpaceAdminRights) |
| 212 | ## Application space |
| 213 | #set ($appReference = $doc.documentReference.parent) |
| 214 | #maybeGrantSpaceAdminRight($appReference) |
| 215 | ## Code space (if it's not nested inside the application space) |
| 216 | #set ($className = $request.get('AppWithinMinutes.LiveTableClass_0_class')) |
| 217 | #set ($classReference = $services.model.resolveDocument($className)) |
| 218 | #if (!$classReference.hasParent($appReference)) |
| 219 | #maybeGrantSpaceAdminRight($classReference.parent) |
| 220 | #end |
| 221 | #end |
| 222 | |
| 223 | #macro (updateAndSaveLiveTable) |
| 224 | #set ($discard = $doc.updateObjectFromRequest('AppWithinMinutes.LiveTableClass')) |
| 225 | #set ($liveTableGeneratorDoc = $xwiki.getDocument('AppWithinMinutes.LiveTableGenerator')) |
| 226 | |
| 227 | ## Generate the LiveTable by displaying the LiveTableGenerator document in the context of the current document. |
| 228 | #set ($displayParameters = $services.display.createDocumentDisplayerParameters()) |
| 229 | #set ($discard = $displayParameters.setExecutionContextIsolated(false)) |
| 230 | #set ($discard = $displayParameters.setContentTranslated(true)) |
| 231 | #set ($generatedLiveTableContent = $services.display.content($liveTableGeneratorDoc, { 'outputSyntaxId' : 'plain/1.0', 'displayerParameters' : $displayParameters })) |
| 232 | |
| 233 | ## Use the generated LiveTable content for the data home page. |
| 234 | #set ($dataSpaceReference = $services.model.resolveSpace($doc.getValue('dataSpace'))) |
| 235 | #set ($dataSpaceHomeReference = $services.model.resolveDocument('', 'default', $dataSpaceReference)) |
| 236 | #if ($dataSpaceHomeReference.equals($doc.documentReference) || !$xwiki.exists($dataSpaceHomeReference)) |
| 237 | ## Either the application space and the data space are one and the same or this is a new application and we don't |
| 238 | ## want to promote the data space anymore. |
| 239 | #set ($dataHomePage = $doc) |
| 240 | #else |
| 241 | ## The application data is stored in a different space. |
| 242 | #set ($dataHomePage = $xwiki.getDocument($dataSpaceHomeReference)) |
| 243 | #set ($discard = $dataHomePage.setHidden(true)) |
| 244 | #set ($escapedAppName = $doc.documentReference.parent.name.toLowerCase().replace("'", "''")) |
| 245 | #set ($discard = $dataHomePage.setTitle("${escapetool.d}services.localization.render('${escapedAppName}.dataSpace.title')")) |
| 246 | |
| 247 | ## Update the home page content. |
| 248 | #set ($homePageContent = '') |
| 249 | #if ("$!generatedLiveTableContent" != '') |
| 250 | ## Include the entries live table in the application home page. |
| 251 | #set ($escapedReference = $services.model.serialize($dataSpaceHomeReference).replaceAll('([~"])', '~$1')) |
| 252 | #set ($homePageContent = "{{include reference=""$escapedReference"" /}}") |
| 253 | #end |
| 254 | #set ($discard = $doc.setContent($homePageContent)) |
| 255 | #end |
| 256 | #set ($discard = $dataHomePage.setContent($generatedLiveTableContent)) |
| 257 | |
| 258 | #set ($minorEdit = "$!request.minorEdit" != '') |
| 259 | #set ($comment = $request.comment) |
| 260 | #if ("$!comment" == '') |
| 261 | #set ($comment = $services.localization.render('platform.appwithinminutes.liveTableEditorSaveComment')) |
| 262 | #end |
| 263 | |
| 264 | #if ($dataHomePage != $doc) |
| 265 | ## Save the data home page. |
| 266 | #set ($discard = $dataHomePage.save($comment, $minorEdit)) |
| 267 | #end |
| 268 | |
| 269 | ## Save the application home page. |
| 270 | #set ($discard = $doc.save($comment, $minorEdit)) |
| 271 | #end |
| 272 | |
| 273 | #macro (updateAndSaveIcon) |
| 274 | #set ($uix = $doc.getObject('XWiki.UIExtensionClass', true)) |
| 275 | #set ($discard = $uix.set('name', "platform.panels.${doc.space}Application")) |
| 276 | #set ($discard = $uix.set('extensionPointId', 'org.xwiki.platform.panels.Applications')) |
| 277 | #set ($uixParams = [ |
| 278 | "label=$doc.plainTitle", |
| 279 | "target=$doc.fullName", |
| 280 | "icon=$request.applicationIcon" |
| 281 | ]) |
| 282 | #set ($discard = $uix.set('parameters', $stringtool.join($uixParams, $util.newline))) |
| 283 | #set ($hasWikiAdminRights = $services.security.authorization.hasAccess('admin', $doc.documentReference.wikiReference)) |
| 284 | #set ($discard = $uix.set('scope', "#if ($hasWikiAdminRights)wiki#{else}user#end")) |
| 285 | #set ($discard = $doc.save('Updated application icon', true)) |
| 286 | #end |
| 287 | |
| 288 | #macro (excludeFromNavigationPanel) |
| 289 | #set ($navigationPanelConfig = $xwiki.getDocument($navigationPanelConfigReference)) |
| 290 | #set ($exclusions = $navigationPanelConfig.getValue('exclusions')) |
| 291 | #if ($exclusions.add($doc.fullName)) |
| 292 | #set ($discard = $navigationPanelConfig.set('exclusions', $exclusions)) |
| 293 | #set ($discard = $navigationPanelConfig.save("Exclude the $doc.pageReference.name application")) |
| 294 | #end |
| 295 | #end |
| 296 | |
| 297 | #macro (doSave) |
| 298 | ## Exclude the application home page from the Navigation panel if the application is created at the top level by an |
| 299 | ## user that has edit right on the Navigation panel configuration. |
| 300 | #set ($navigationPanelConfigReference = 'PanelsCode.NavigationConfiguration') |
| 301 | #set ($shouldExcludeFromNavigationPanel = $doc.isNew() && $doc.pageReference.parent.type == 'WIKI' |
| 302 | && $services.security.authorization.hasAccess('edit', $navigationPanelConfigReference)) |
| 303 | #maybeGrantSpaceAdminRights() |
| 304 | #updateAndSaveLiveTable() |
| 305 | #updateAndSaveIcon() |
| 306 | #if ($shouldExcludeFromNavigationPanel) |
| 307 | #excludeFromNavigationPanel |
| 308 | #end |
| 309 | #if ($action == 'save') |
| 310 | #if ($errorMessage) |
| 311 | {{html clean="false"}} |
| 312 | <div class="box errormessage">$errorMessage</div> |
| 313 | {{/html}} |
| 314 | #else |
| 315 | ## Redirect to view mode. |
| 316 | $response.sendRedirect($doc.getURL()) |
| 317 | #end |
| 318 | #else |
| 319 | #if ($errorMessage) |
| 320 | $response.sendError(400, $errorMessage) |
| 321 | #else |
| 322 | $response.setStatus(204) |
| 323 | #end |
| 324 | #end |
| 325 | #end |
| 326 | {{/velocity}} |
| 327 | |
| 328 | {{velocity}} |
| 329 | #if ("$!request.wizard" == 'true') |
| 330 | {{include reference="AppWithinMinutes.WizardStep" /}} |
| 331 | #end |
| 332 | {{/velocity}} |
| 333 | |
| 334 | {{velocity}} |
| 335 | ## Determine the action button that triggered the request |
| 336 | #set ($action = $xcontext.action) |
| 337 | #foreach ($paramName in $request.getParameterMap().keySet()) |
| 338 | #if ($paramName.startsWith('xaction_')) |
| 339 | #set ($action = $paramName.substring(8)) |
| 340 | #break |
| 341 | #end |
| 342 | #end |
| 343 | #if ($action == 'edit') |
| 344 | #doEdit() |
| 345 | #elseif ($action == 'save' || $action == 'saveandcontinue') |
| 346 | #if ($services.csrf.isTokenValid($request.form_token)) |
| 347 | #doSave() |
| 348 | #else |
| 349 | $response.sendRedirect($services.csrf.getResubmissionURL()) |
| 350 | #end |
| 351 | #end |
| 352 | {{/velocity}} |