Changes for page Tree Macro

Last modified by Ludovic Dubost on 2024/07/22 15:50

From version 4.1
edited by Ludovic Dubost
on 2016/04/01 11:48
Change comment: Install extension [org.xwiki.platform:xwiki-platform-tree-macro-8.0]
To version 3.1
edited by Ludovic Dubost
on 2015/11/28 14:58
Change comment: Install extension [org.xwiki.platform:xwiki-platform-tree-macro-7.3]

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,15 +3,65 @@
1 -{{template name="tree_macros.vm" /}}
2 -
3 3  {{velocity output="false"}}
4 -#set ($options = {})
5 -#foreach ($parameterName in $xcontext.macro.params.parameterNames)
6 - #set ($discard = $options.put($parameterName, $xcontext.macro.params.get($parameterName)))
2 +#set ($discard = $xwiki.linkx.use($services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'tree.min.css',
3 + {'evaluate': true}), {'type': 'text/css', 'rel': 'stylesheet'}))
4 +#set ($discard = $xwiki.jsx.use($xcontext.macro.doc))
5 +#set ($classes = ['xtree', "$!xcontext.macro.params.get('class')"])
6 +#set ($noLinks = $xcontext.macro.params.links != 'true')
7 +#if ($noLinks)
8 + #set ($discard = $classes.add('jstree-no-links'))
7 7  #end
10 +#set ($attributes = [
11 + "class='$!escapetool.xml($stringtool.join($classes, ' '))'",
12 + 'data-responsive="true"'
13 +])
14 +#if ("$!xcontext.macro.params.reference" != '')
15 + #set ($defaultResourceParams = {
16 + 'root': '',
17 + 'showRoot': false
18 + })
19 + #set ($resourceParams = {})
20 + #foreach ($entry in $defaultResourceParams.entrySet())
21 + #set ($value = $xcontext.macro.params.get($entry.key))
22 + #if ("$!value" != '' && $value != "$!entry.value")
23 + #set ($discard = $resourceParams.put($entry.key, $value))
24 + #end
25 + #end
26 + #set ($reference = $xcontext.macro.params.reference)
27 + #if ($reference.startsWith('path:'))
28 + ## URL/Path reference
29 + #set ($resourceURL = $reference.substring(5))
30 + #set ($resourceURL = "$resourceURL#if ($resourceURL.indexOf('?') < 0)?#else&#end$escapetool.url($resourceParams)")
31 + #else
32 + ## Document reference
33 + #if ($reference.startsWith('doc:'))
34 + #set ($reference = $reference.substring(4))
35 + #end
36 + #set ($resourceParams.outputSyntax = 'plain')
37 + #set ($resourceURL = $xwiki.getURL($reference, 'get', $escapetool.url($resourceParams)))
38 + #end
39 + #set ($discard = $attributes.add("data-url='$resourceURL'"))
40 +#end
41 +#set ($dragAndDrop = $xcontext.macro.params.dragAndDrop == 'true')
42 +#set ($discard = $attributes.add("data-dragAndDrop='$dragAndDrop'"))
43 +#set ($contextMenu = $xcontext.macro.params.contextMenu == 'true')
44 +#set ($discard = $attributes.add("data-contextMenu='$contextMenu'"))
45 +#set ($icons = $xcontext.macro.params.icons == 'true')
46 +#set ($discard = $attributes.add("data-icons='$icons'"))
47 +#set ($edges = $xcontext.macro.params.edges == 'true')
48 +#set ($discard = $attributes.add("data-edges='$edges'"))
49 +#set ($checkboxes = $xcontext.macro.params.checkboxes == 'true')
50 +#set ($discard = $attributes.add("data-checkboxes='$checkboxes'"))
51 +#set ($discard = $attributes.add("data-openTo='$!escapetool.xml($xcontext.macro.params.openTo)'"))
52 +#set ($finder = $xcontext.macro.params.finder == 'true')
53 +#if ($finder)
54 + #set ($discard = $xwiki.linkx.use($services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar',
55 + 'finder.min.css', {'evaluate': true}), {'type': 'text/css', 'rel': 'stylesheet'}))
56 +#end
57 +#set ($discard = $attributes.add("data-finder='$finder'"))
8 8  #set ($content = $xcontext.macro.content)
9 9  #if ("$!content" == '' && $xcontext.action == 'edit' && $editor == 'wysiwyg')
10 10   #set ($content = "$services.icon.render('chart_organisation') $services.localization.render('tree.macro.editModeWarning')")
11 11  #end
12 -#set ($output = "(% #treeAttributes($options true) %)((($!content)))")
62 +#set ($output = "(% $stringtool.join($attributes, ' ') %)((($!content)))")
13 13  ## Parse the output and return the resulting XDOM blocks.
14 14  #set ($xcontext.macro.result = $services.rendering.parse($output, $xwiki.currentContentSyntaxId).children)
15 15  {{/velocity}}
XWiki.JavaScriptExtension[0]
Caching policy
... ... @@ -1,0 +1,1 @@
1 +long
Code
... ... @@ -1,0 +1,10 @@
1 +require(["$!services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'require-config.min.js', {'evaluate': true})"], function() {
2 + require(['tree'], function($) {
3 + $('.xtree').xtree().one('ready.jstree', function(event, data) {
4 + var tree = data.instance;
5 + var openToNodeId = tree.element.attr('data-openTo');
6 + // Open the tree to the specified node and select it.
7 + openToNodeId && data.instance.openTo(openToNodeId);
8 + });
9 + });
10 +});
Name
... ... @@ -1,0 +1,1 @@
1 +Initialization Code
Parse content
... ... @@ -1,0 +1,1 @@
1 +Yes
Use this extension
... ... @@ -1,0 +1,1 @@
1 +onDemand