Changes for page Tree Macro

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

From 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]
To version 1.1
edited by Ludovic Dubost
on 2014/11/18 12:31
Change comment: Install extension [org.xwiki.platform:xwiki-platform-tree-macro-6.3]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,10 +1,34 @@
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 - });
1 +/*
2 +#set ($jsTreeVersion = '3.0.8')
3 +*/
4 +require.config({
5 + paths: {
6 + jsTree: [
7 + '//cdnjs.cloudflare.com/ajax/libs/jstree/$jsTreeVersion/jstree.min',
8 + "$!services.webjars.url('jstree', 'jstree.min.js')"
9 + ],
10 + JobRunner: "$!services.webjars.url('org.xwiki.platform:xwiki-platform-job-webjar', 'jobRunner.min.js')",
11 + tree: "$!services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'tree.min.js')"
12 + },
13 + shim: {
14 + jsTree: {
15 + deps: ['jquery']
16 + }
17 + }
10 10  });
19 +
20 +(function loadCss(urls) {
21 + for (var i = 0; i < urls.length; i++) {
22 + var link = document.createElement("link");
23 + link.type = "text/css";
24 + link.rel = "stylesheet";
25 + link.href = urls[i];
26 + document.getElementsByTagName("head")[0].appendChild(link);
27 + }
28 +})([
29 + "$!services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'tree.min.css', {'evaluate': true})"
30 +]);
31 +
32 +require(['tree'], function($) {
33 + $('.xtree').xtree();
34 +});
Name
... ... @@ -1,1 +1,1 @@
1 -Initialization Code
1 +Require Configuration
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,6 +1,4 @@
1 1  {{velocity output="false"}}
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 4  #set ($discard = $xwiki.jsx.use($xcontext.macro.doc))
5 5  #set ($classes = ['xtree', "$!xcontext.macro.params.get('class')"])
6 6  #set ($noLinks = $xcontext.macro.params.links != 'true')
... ... @@ -12,31 +12,19 @@
12 12   'data-responsive="true"'
13 13  ])
14 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 26   #set ($reference = $xcontext.macro.params.reference)
27 27   #if ($reference.startsWith('path:'))
28 28   ## URL/Path reference
29 29   #set ($resourceURL = $reference.substring(5))
30 - #set ($resourceURL = "$resourceURL#if ($resourceURL.indexOf('?') < 0)?#else&#end$escapetool.url($resourceParams)")
31 31   #else
32 32   ## Document reference
33 33   #if ($reference.startsWith('doc:'))
34 34   #set ($reference = $reference.substring(4))
35 35   #end
36 - #set ($resourceParams.outputSyntax = 'plain')
37 - #set ($resourceURL = $xwiki.getURL($reference, 'get', $escapetool.url($resourceParams)))
22 + #set ($resourceURL = $xwiki.getURL($reference, 'get', 'outputSyntax=plain'))
38 38   #end
39 39   #set ($discard = $attributes.add("data-url='$resourceURL'"))
25 + #set ($discard = $attributes.add("data-root='$!escapetool.xml($xcontext.macro.params.root)'"))
40 40  #end
41 41  #set ($dragAndDrop = $xcontext.macro.params.dragAndDrop == 'true')
42 42  #set ($discard = $attributes.add("data-dragAndDrop='$dragAndDrop'"))
... ... @@ -48,18 +48,7 @@
48 48  #set ($discard = $attributes.add("data-edges='$edges'"))
49 49  #set ($checkboxes = $xcontext.macro.params.checkboxes == 'true')
50 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'"))
58 -#set ($content = $xcontext.macro.content)
59 -#if ("$!content" == '' && $xcontext.action == 'edit' && $editor == 'wysiwyg')
60 - #set ($content = "$services.icon.render('chart_organisation') $services.localization.render('tree.macro.editModeWarning')")
61 -#end
62 -#set ($output = "(% $stringtool.join($attributes, ' ') %)((($!content)))")
37 +#set ($output = "(% $stringtool.join($attributes, ' ') %)((($!xcontext.macro.content)))")
63 63  ## Parse the output and return the resulting XDOM blocks.
64 64  #set ($xcontext.macro.result = $services.rendering.parse($output, $xwiki.currentContentSyntaxId).children)
65 65  {{/velocity}}
XWiki.WikiMacroParameterClass[9]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -The id of the node to open the tree to. All the ancestors of the specified node, up to the root of the tree, will be opened also.
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No
Parameter name
... ... @@ -1,1 +1,0 @@
1 -openTo
XWiki.WikiMacroParameterClass[10]
Parameter default value
... ... @@ -1,1 +1,0 @@
1 -false
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Show a text input that can be used to find tree nodes. The input is displayed above the tree and offers suggestions as you type based on the content of the tree. When a suggestion is selected the tree is expanded up to the corresponding node.
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No
Parameter name
... ... @@ -1,1 +1,0 @@
1 -finder
XWiki.WikiMacroParameterClass[11]
Parameter default value
... ... @@ -1,1 +1,0 @@
1 -false
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Whether to show the root node or not. The root node is not shown by default because it is usually implied from the context where the tree is displayed (e.g. a label before the tree). There are some cases though when you may want to display the root node: to be able to create a new node under the root.
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No
Parameter name
... ... @@ -1,1 +1,0 @@
1 -showRoot