Skip to content

Commit 65b11c3

Browse files
committed
Improve preselected folders to parse pathId and open it recursively
1 parent e8e654f commit 65b11c3

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/* global Base64 */
67
define([
78
'jquery',
89
'jquery/ui',
@@ -79,6 +80,7 @@ define([
7980
tree = this.element,
8081
lastExistentFolderEl,
8182
pathId,
83+
encodedPath,
8284

8385
/**
8486
* Recursively open folders specified in path array.
@@ -102,14 +104,43 @@ define([
102104
tree.jstree('select_node', folderEl);
103105
});
104106
}
107+
},
108+
109+
/**
110+
* Get currentPath decode it returns new path array
111+
*/
112+
_parseCurrentPath = function () {
113+
var paths = [];
114+
115+
$.each(encodedPath, function (i, val) {
116+
var isLastElement = i === encodedPath.length - 1;
117+
118+
if (isLastElement) {
119+
paths[i] = window.MediabrowserUtility.pathId.replace(',,', '--');
120+
} else {
121+
paths[i] = Base64.encode(val).replace('==', '--');
122+
}
123+
});
124+
paths.unshift('root');
125+
paths.reverse();
126+
127+
return paths;
105128
};
106129

107130
$(window).on('reload.MediaGallery', function () {
131+
encodedPath = Base64.decode(window.MediabrowserUtility.pathId.replace(/--|,,/, '==')).split('/');
108132
pathId = window.MediabrowserUtility.pathId.replace(',,', '--');
133+
109134
tree.jstree('deselect_all');
110-
tree.jstree('open_node', $('[data-id="' + pathId + '"]'), function () {
111-
tree.jstree('select_node', $('[data-id="' + pathId + '"]'));
112-
});
135+
136+
if (encodedPath.length > 1) {
137+
path = _parseCurrentPath(encodedPath);
138+
recursiveOpen();
139+
} else {
140+
tree.jstree('open_node', $('[data-id="' + pathId + '"]'), function () {
141+
tree.jstree('select_node', $('[data-id="' + pathId + '"]'));
142+
});
143+
}
113144
});
114145

115146
recursiveOpen();

0 commit comments

Comments
 (0)