-
Notifications
You must be signed in to change notification settings - Fork 1
/
customScript.js
60 lines (53 loc) · 1.54 KB
/
customScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//ajax call to controller
$.ajax({
url: 'controller.php',
type: 'get',
data: { "getFilePaths": ''},
beforeSend: function(){
},
complete: function(){
},
success: function(response) {
//create file array
var files = Array();
//fetch each paths from json
$.each(JSON.parse(response), function (i, p) {
files.push({webkitRelativePath: p});
});
var idcount = 0;
var treeJSON = [];
var idmap = {};
//fetching paths by seperating '/'
//more documentation - https://www.jstree.com/
function add(dirs) {
if (!dirs.length) return "#";
var name = dirs.join("/");
if (name in idmap) return idmap[name];
var dir = dirs.pop();
var parent = add(dirs);
var id = "ajson" + ++idcount;
treeJSON.push({
id: id,
parent: parent,
text: dir
});
return idmap[name] = id;
}
for (var i = 0; i < files.length; ++i) {
var name = files[i].webkitRelativePath;
add(name.split("/"));
}
//console.log(treeJSON);
$('#tree')
.jstree({
'core': {
'check_callback': true,
'data': function (node, cb) {
cb.call(this, treeJSON);
}
}
});
var tree = $('#tree').jstree(true);
tree.refresh();
}
});