Изменения документа Document Tree Macros
Редактировал(а) Давид Гавриков 2024/10/22 15:18
От версии 4.1
отредактировано Давид Гавриков
на 2024/05/29 15:58
на 2024/05/29 15:58
Изменить комментарий:
Install extension [org.xwiki.platform:xwiki-platform-index-tree-macro/16.3.1]
К версии 5.1
отредактировано Давид Гавриков
на 2024/10/22 15:18
на 2024/10/22 15:18
Изменить комментарий:
Install extension [org.xwiki.platform:xwiki-platform-index-tree-macro/16.8.0]
Сводка
-
Свойства страницы (1 изменено, 0 добавлено, 0 удалено)
Подробности
- Свойства страницы
-
- Содержимое
-
... ... @@ -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 ... ... @@ -352,14 +352,18 @@ 352 352 #end 353 353 354 354 #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. 355 355 #set ($discard = $siblings.add({ 356 356 'id': "addDocument:$services.model.serialize($documentReference, 'default')", 357 - 'text': 'New page...',379 + 'text': $services.localization.render('index.documentTree.addDocument'), 358 358 'icon': 'fa fa-plus-circle', 359 359 'children': false, 360 360 'data': { 361 361 'type': 'addDocument', 362 - 'validChildren': [] 384 + 'validChildren': [], 385 + 'hasContextMenu': true, 386 + 'canRename': true 363 363 }, 364 364 'a_attr': { 365 365 'href': $xwiki.getURL($documentReference, 'create')