Skip to content

Commit 817ec4f

Browse files
committed
Provide pathId parameter to media browser
1 parent eab0af9 commit 817ec4f

File tree

7 files changed

+23
-163
lines changed

7 files changed

+23
-163
lines changed

app/code/Magento/Cms/Model/Wysiwyg/Gallery/DefaultConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
7777

7878
if (is_string($this->currentTreePath)) {
7979
$fileBrowserUrlParams = [
80-
'current_tree_path' => $this->imagesHelper->idEncode($this->currentTreePath)
80+
'current_tree_path' => $this->imagesHelper->idEncode($this->currentTreePath),
8181
];
8282
}
8383

app/code/Magento/Cms/Test/Mftf/ActionGroup/AdminCloseMediaGalleryActionGroup.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/code/Magento/Cms/Test/Mftf/ActionGroup/AdminOpenMediaGalleryTinyMce4ActionGroup.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/MediaGallerySection.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<element name="WysiwygArrow" type="button" selector="#d3lzaXd5Zw-- &gt; .jstree-icon"/>
3535
<element name="checkIfWysiwygArrowExpand" type="button" selector="//li[@id='d3lzaXd5Zw--' and contains(@class,'jstree-closed')]"/>
3636
<element name="confirmDelete" type="button" selector=".action-primary.action-accept"/>
37-
<element name="highlightedFolder" type="block" selector="//li[@id='{{folderId}}']/a[@class='jstree-clicked']" parameterized="true"/>
3837
<element name="imageBlockByName" type="block" selector="//div[@data-row='file'][contains(., '{{imageName}}')]" parameterized="true"/>
3938
</section>
4039
</sections>

app/code/Magento/Cms/Test/Mftf/Test/AdminVerifyDefaultCurrentTreePathTest.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

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

6-
/* global Base64 */
76
define([
87
'jquery',
98
'jquery/ui',
@@ -79,92 +78,30 @@ define([
7978
var path = this.options.currentPath,
8079
tree = this.element,
8180
lastExistentFolderEl,
82-
pathId,
8381

84-
/**
85-
* Recursively open folders specified in path array.
86-
*/
87-
recursiveOpen = function () {
88-
var folderEl = $('[data-id="' + path.pop() + '"]');
82+
/**
83+
* Recursively open folders specified in path array.
84+
*/
85+
recursiveOpen = function () {
86+
var folderEl = $('[data-id="' + path.pop() + '"]');
8987

90-
// if folder doesn't exist, select the last opened folder
91-
if (!folderEl.length) {
92-
tree.jstree('select_node', lastExistentFolderEl);
88+
// if folder doesn't exist, select the last opened folder
89+
if (!folderEl.length) {
90+
tree.jstree('select_node', lastExistentFolderEl);
9391

94-
return;
95-
}
96-
97-
lastExistentFolderEl = folderEl;
98-
99-
if (path.length) {
100-
tree.jstree('open_node', folderEl, recursiveOpen);
101-
} else {
102-
tree.jstree('open_node', folderEl, function () {
103-
tree.jstree('select_node', folderEl);
104-
});
105-
}
106-
},
107-
108-
/**
109-
* Encode path value
110-
*
111-
* @param {String} val
112-
*/
113-
_encodePathId = function (val) {
114-
return Base64.encode(val)
115-
.replace(/\+/g, ':')
116-
.replace(/\//g, '_')
117-
.replace(/=/g, '-');
118-
},
119-
120-
/**
121-
* Decode path value
122-
*
123-
* @param {String} val
124-
*/
125-
_decodePathId = function (val) {
126-
return Base64.decode(val)
127-
.replace(/\:/g, '+')
128-
.replace(/\_/g, '/')
129-
.replace(/-/g, '=');
130-
},
131-
132-
/**
133-
* Get currentPath decode it returns new path array
134-
*/
135-
_parseCurrentPath = function () {
136-
var paths = [],
137-
decodedPath = _decodePathId(window.MediabrowserUtility.pathId.replace(/--|,,/, '==')).split('/');
92+
return;
93+
}
13894

139-
$.each(decodedPath, function (i, val) {
140-
var isLastElement = i === decodedPath.length - 1;
95+
lastExistentFolderEl = folderEl;
14196

142-
if (isLastElement) {
143-
paths[i] = window.MediabrowserUtility.pathId.replace(',,', '--');
97+
if (path.length) {
98+
tree.jstree('open_node', folderEl, recursiveOpen);
14499
} else {
145-
paths[i] = _encodePathId(val);
100+
tree.jstree('open_node', folderEl, function () {
101+
tree.jstree('select_node', folderEl);
102+
});
146103
}
147-
});
148-
paths.unshift('root');
149-
paths.reverse();
150-
151-
return paths;
152-
};
153-
154-
$(window).on('reload.MediaGallery', function () {
155-
pathId = window.MediabrowserUtility.pathId.replace(',,', '--');
156-
path = _parseCurrentPath();
157-
158-
tree.jstree('deselect_all');
159-
160-
if (path.length > 1) {
161-
recursiveOpen();
162-
} else {
163-
tree.jstree('open_node', $('[data-id="' + pathId + '"]'), function () {
164-
tree.jstree('select_node', $('[data-id="' + pathId + '"]'));
165-
});
166-
}
167-
});
104+
};
168105

169106
recursiveOpen();
170107
},

dev/tests/js/jasmine/tests/lib/mage/browser.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ define([
99
], function (browser, $) {
1010
'use strict';
1111

12-
var obj,
13-
openUrl = 'http://example.com/target_element_id/theTargetId/tree_path/wysiwyg&current_tree_path=d3lzaXd5Zw,';
12+
var obj;
1413

1514
beforeEach(function () {
1615
/**
@@ -42,8 +41,8 @@ define([
4241
}
4342
};
4443
});
45-
obj.openDialog(openUrl, 100, 100, 'title', options);
46-
obj.openDialog(openUrl, 100, 100, 'title', options);
44+
obj.openDialog('instance/url', 100, 100, 'title', options);
45+
obj.openDialog('instance/url', 100, 100, 'title', options);
4746
expect($.ajax.calls.count()).toBe(1);
4847
});
4948

@@ -60,8 +59,8 @@ define([
6059
}
6160
};
6261
});
63-
obj.openDialog(openUrl, 100, 100, 'title', undefined);
64-
obj.openDialog(openUrl, 100, 100, 'title', undefined);
62+
obj.openDialog('instance/url/target_element_id/YDW2424/', 100, 100, 'title', undefined);
63+
obj.openDialog('instance/target_element_id/Y45GDRg/', 100, 100, 'title', undefined);
6564
expect($.ajax.calls.count()).toBe(1);
6665
});
6766
});

0 commit comments

Comments
 (0)