Total Complexity | 12 |
Complexity/F | 1.5 |
Lines of Code | 56 |
Function Count | 8 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export class Tree { |
||
2 | constructor() { |
||
3 | this.initJsTree(); |
||
4 | } |
||
5 | |||
6 | initJsTree() { |
||
7 | let moduleTree = $('#treeview') |
||
8 | moduleTree.jstree({ |
||
9 | "core" : { |
||
10 | "themes" : { |
||
11 | "icons": false |
||
12 | }, |
||
13 | "data" : { |
||
14 | "url" : function (node) { |
||
15 | return node.id === '#' ? |
||
16 | $("meta[name='module-tree-default-url']").attr('content') : |
||
17 | $("meta[name='module-tree-children-url']").attr('content'); |
||
18 | }, |
||
19 | "data" : function (node) { |
||
20 | return { 'id' : node.id }; |
||
21 | } |
||
22 | } |
||
23 | }, |
||
24 | "plugins" : ['search', 'sort'], |
||
25 | "search" : { |
||
26 | "show_only_matches" : true |
||
27 | } |
||
28 | }) |
||
29 | |||
30 | // Open tree automatically |
||
31 | .on('ready.jstree', () => { |
||
32 | if ($("meta[name='module-tree-open-all']").attr('content')) { |
||
33 | moduleTree.jstree('open_all') |
||
34 | } |
||
35 | }) |
||
36 | |||
37 | // Switch on detail view on click |
||
38 | .on('changed.jstree', (e, data) => { |
||
39 | if (data.node.a_attr.href !== '#') { |
||
40 | document.location.href = data.node.a_attr.href |
||
41 | } |
||
42 | }) |
||
43 | |||
44 | let to = false |
||
45 | $('.treeview-search-bar #record-name').keyup(() => { |
||
46 | if(to) { |
||
47 | clearTimeout(to) |
||
48 | } |
||
49 | |||
50 | to = setTimeout(() => { |
||
51 | let v = $('#record-name').val() |
||
52 | moduleTree.jstree(true).search(v) |
||
53 | }, 250) |
||
54 | }) |
||
55 | } |
||
56 | } |