Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit c9221a4

Browse files
committed
Display root node when it's not /
1 parent ff6765e commit c9221a4

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

Resources/assets/js/adapter/fancytree.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,20 @@ export class FancytreeAdapter {
147147
// transform the JSON response into a data structure that's supported by FancyTree
148148
postProcess: function (event, data) {
149149
if (null == data.error) {
150-
data.result = requestNodeToFancytreeNode(data.response).children;
151-
if (data.result.length == 1) {
152-
data.result[0].expanded = true;
150+
var result = requestNodeToFancytreeNode(data.response);
151+
if ("" === result.key) {
152+
result = result.children;
153+
} else {
154+
result = [result];
155+
}
156+
157+
if (result.length == 1) {
158+
result[0].expanded = true;
153159
}
154160

161+
data.result = result;
155162
if (useCache) {
156-
cache.set(data.node.getKeyPath(), data.result);
163+
cache.set(data.node.getKeyPath(), result);
157164
}
158165
} else {
159166
data.result = {
@@ -182,14 +189,15 @@ export class FancytreeAdapter {
182189
}
183190

184191
bindToInput($input) {
192+
var root = this.rootNode;
193+
if (root.substr(-1) == '/') {
194+
var root = this.rootNode.substr(0, -1);
195+
}
196+
var rootParent = root.substr(0, root.lastIndexOf('/'));
197+
185198
// output active node to input field
186199
this.$tree.fancytree('option', 'activate', (event, data) => {
187-
root = this.rootNode;
188-
if (root.substr(-1) == '/') {
189-
var root = this.rootNode.substr(0, -1);
190-
}
191-
192-
$input.val(root + data.node.getKeyPath());
200+
$input.val(rootParent + data.node.getKeyPath());
193201
});
194202

195203
var showKey = (key) => {
@@ -201,8 +209,8 @@ export class FancytreeAdapter {
201209
});
202210
};
203211
var removeRoot = (path) => {
204-
if (0 === path.indexOf(this.rootNode)) {
205-
return path.substr(this.rootNode.length);
212+
if (0 === path.indexOf(rootParent + '/')) {
213+
return path.substr(rootParent.length + 1);
206214
}
207215

208216
return path;

0 commit comments

Comments
 (0)