Изменения документа Document Tree Macros

Редактировал(а) Давид Гавриков 2024/10/22 15:18

От версии 2.1
отредактировано Андрей Ганьков
на 2022/08/01 10:37
Изменить комментарий: Install extension [org.xwiki.platform:xwiki-platform-index-tree-macro/14.6]
К версии 5.1
отредактировано Давид Гавриков
на 2024/10/22 15:18
Изменить комментарий: Install extension [org.xwiki.platform:xwiki-platform-index-tree-macro/16.8.0]

Сводка

Подробности

Свойства страницы
Автор документа
... ... @@ -1,1 +1,1 @@
1 -XWiki.gav
1 +XWiki.gavrikof
Содержимое
... ... @@ -76,7 +76,11 @@
76 76  #macro (handleDocumentTreeRequest)
77 77   #if ($request.action)
78 78   #if ($services.csrf.isTokenValid($request.form_token))
79 - $response.sendError(400, 'The specified action is not supported.')
79 + #if ($request.action == 'create' && $request.type == 'addDocument')
80 + #handleNewNodeCreationRequest()
81 + #else
82 + $response.sendError(400, 'The specified action is not supported.')
83 + #end
80 80   #elseif ($isAjaxRequest)
81 81   $response.sendError(403, 'The CSRF token is missing.')
82 82   #else
... ... @@ -102,6 +102,22 @@
102 102   #end
103 103  #end
104 104  
109 +#macro (handleNewNodeCreationRequest)
110 + #set ($cleanId = $stringtool.substring($request.id, $stringtool.length('document:')))
111 + #set ($parentReference = $services.model.resolveDocument($cleanId))
112 + #set ($requestedName = $request.name)
113 + #set ($transformedName = $services.modelvalidation.transformName($requestedName))
114 + #set ($spaceReference = $services.model.createSpaceReference($transformedName, $parentReference.lastSpaceReference))
115 + #set ($documentReference = $services.model.createDocumentReference('WebHome', $spaceReference))
116 + #set ($data = [])
117 + #addDocumentNode($documentReference, $data)
118 + ## We want to allow opening the node to add another hierarchy.
119 + #set ($data[0].children = true)
120 + ## We want to display the actual requested name as node name.
121 + #set ($data[0].text = $requestedName)
122 + #jsonResponse($data)
123 +#end
124 +
105 105  #macro (postProcessDocumentTreeData $data)
106 106   ## This is just a hook to allow post processing the document tree data.
107 107  #end
... ... @@ -316,10 +316,6 @@
316 316   #if ($canViewDoc && $docTreeConfig.showDocumentTitle)
317 317   ## Display the translated title.
318 318   #set ($translatedDocument = $xwiki.getDocument($documentReference).translatedDocument)
319 - ## Make sure the displayed title is not affected by the sheet request parameter (e.g. when $translatedDocument is
320 - ## the current document). By setting the title (even if we don't change it) the internal document instance is cloned
321 - ## so it's going to be different than the current document instance (which is the target of the sheet parameter).
322 - #set ($discard = $translatedDocument.setTitle($translatedDocument.title))
323 323   #set ($plainTitle = $translatedDocument.plainTitle)
324 324   #if (!$stringtool.isBlank($plainTitle))
325 325   #set ($label = $plainTitle)
... ... @@ -356,14 +356,18 @@
356 356  #end
357 357  
358 358  #macro (addAddDocumentNode $documentReference $siblings)
375 + ## FIXME: This URL is wrong, it should use the $documentReference as the parent for creation of the node:
376 + ## the reference is already an existing doc, so it shouldn't be the one used for creation.
359 359   #set ($discard = $siblings.add({
360 360   'id': "addDocument:$services.model.serialize($documentReference, 'default')",
361 - 'text': 'New page...',
379 + 'text': $services.localization.render('index.documentTree.addDocument'),
362 362   'icon': 'fa fa-plus-circle',
363 363   'children': false,
364 364   'data': {
365 365   'type': 'addDocument',
366 - 'validChildren': []
384 + 'validChildren': [],
385 + 'hasContextMenu': true,
386 + 'canRename': true
367 367   },
368 368   'a_attr': {
369 369   'href': $xwiki.getURL($documentReference, 'create')
... ... @@ -1126,6 +1126,7 @@
1126 1126  #macro (searchAttachmentsSolr $text $limit $return)
1127 1127   #set ($params = [
1128 1128   'fq=type:ATTACHMENT',
1149 + 'fq=locale:*',
1129 1129   'qf=filename^4 attcontent',
1130 1130   'fl=type wiki spaces name filename'
1131 1131   ])