Modifications pour le document DocumentTree

Modifié par Florent Charton le 2024/08/08 18:44

Depuis la version 3.1
modifié par Florent Charton
sur 2024/08/08 18:44
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-ckeditor-ui/15.10.11]
À la version 2.1
modifié par Florent Charton
sur 2022/06/28 18:01
Commentaire de modification : Install extension [org.xwiki.contrib:application-ckeditor-ui/1.64.2]

Résumé

Détails

XWiki.JavaScriptExtension[0]
Code
... ... @@ -8,33 +8,24 @@
8 8   return selected && selected.startsWith("attachment:");
9 9   }
10 10  
11 - function init(element) {
12 - element.find('.attachments-tree').xtree()
13 - .one('ready.jstree', function (event, data) {
14 - const documentReference = element.find('input[name="documentReference"]').val()
15 - data.instance.openTo(documentReference);
16 - })
17 - .on('changed.jstree', function (event, data) {
18 - if (validateSelection(data.instance)) {
19 - imageSelector.updateSelectedImageReferences([getSelected(data.instance)], $(this));
20 - } else {
21 - imageSelector.updateSelectedImageReferences([], $(this));
11 + $('.attachments-tree').xtree()
12 + .one('ready.jstree', function (event, data) {
13 + data.instance.openTo("document:" + XWiki.Model.serialize(XWiki.currentDocument.getDocumentReference()));
14 + })
15 + .on('changed.jstree', function (event, data) {
16 + if (validateSelection(data.instance)) {
17 + imageSelector.updateSelectedImageReferences([getSelected(data.instance)]);
18 + } else {
19 + imageSelector.updateSelectedImageReferences([]);
20 + }
21 + })
22 + .on('load_node.jstree', function (node, status) {
23 + for (var child of status.node.children) {
24 + var childNode = status.instance.get_node(child);
25 + if (childNode.data.mimetype && !childNode.data.mimetype.startsWith('image/')) {
26 + // Disable the nodes instead of hiding them because they still can be search in the search field.
27 + status.instance.disable_node(childNode);
22 22   }
23 - })
24 - .on('load_node.jstree', function (node, status) {
25 - for (var child of status.node.children) {
26 - var childNode = status.instance.get_node(child);
27 - if (childNode.data.mimetype && !childNode.data.mimetype.startsWith('image/')) {
28 - // Disable the nodes instead of hiding them because they still can be search in the search field.
29 - status.instance.disable_node(childNode);
30 - }
31 - }
32 - });
33 - }
34 -
35 - init($(document).find('.image-selector'));
36 -
37 - $(document).on('xwiki:dom:updated', (event, data) => {
38 - data.elements.forEach(element => init($(element)));
39 - });
29 + }
30 + });
40 40  });
XWiki.UIExtensionClass[0]
Executed Content
... ... @@ -1,11 +1,11 @@
1 1  {{velocity}}
2 2  #set ($discard = $xwiki.jsx.use('CKEditor.ImageSelectorServiceUIX.DocumentTree'))
3 -{{html clean="false" wiki="false"}}
4 - <input type='hidden' name='documentReference' value='$escapetool.xml("document:$services.model.serialize($request.documentReference, 'default')")' />
3 +{{html clean="false"}}
5 5   #template('documentTree_macros.vm')
6 6   #documentTree({
7 7   'class': 'attachments-tree',
8 8   'finder': true,
8 + 'openTo': "document:$services.model.serialize($doc.documentReference, 'default')",
9 9   'showWikis': true,
10 10   'showTranslations': false
11 11   })
Extension Parameters
... ... @@ -1,3 +1,3 @@
1 1  priority=200
2 -title=ckeditor.plugin.image.imageSelector.treeTab.title
2 +title=ckeditor.plugin.image.imageSelector.documentTreeTab.title
3 3  id=documentTree