|
17 | 17 | $(function() { |
18 | 18 |
|
19 | 19 | $.mockjax({ |
20 | | - url: '/orgchart/children/n3', |
| 20 | + url: '/orgchart/ancestors/n1', |
21 | 21 | contentType: 'application/json', |
22 | 22 | responseTime: 1000, |
23 | | - responseText: { 'children': [ |
24 | | - { 'id': 'n4', 'name': 'Pang Pang', 'title': 'engineer', 'relationship': '110' }, |
25 | | - { 'id': 'n5', 'name': 'Xiang Xiang', 'title': 'UE engineer', 'relationship': '110'} |
26 | | - ]} |
27 | | - }); |
28 | | - |
29 | | - $.mockjax({ |
30 | | - url: '/orgchart/parent/n1', |
31 | | - contentType: 'application/json', |
32 | | - responseTime: 1000, |
33 | | - responseText: { 'id': 'n6','name': 'Lao Lao', 'title': 'general manager', 'relationship': '001' } |
| 23 | + responseText: { |
| 24 | + 'id': 'n0', |
| 25 | + 'name': 'Lao Lao', |
| 26 | + 'title': 'general manager', 'relationship': '001', |
| 27 | + 'children': [ |
| 28 | + { 'id': 'n10','name': 'Bo Miao', 'title': 'department engineer', 'relationship': '110' }, |
| 29 | + { 'id': 'n11', 'name': 'Yu Jie', 'title': 'department engineer', 'relationship': '110' }, |
| 30 | + { 'id': 'n12', 'name': 'Yu Li', 'title': 'department engineer', 'relationship': '110' }, |
| 31 | + { 'id': 'n13', 'name': 'Hong Miao', 'title': 'department engineer', 'relationship': '110' }, |
| 32 | + { 'id': 'n14', 'name': 'Yu Wei', 'title': 'department engineer', 'relationship': '110' }, |
| 33 | + { 'id': 'n15', 'name': 'Chun Miao', 'title': 'department engineer', 'relationship': '110' }, |
| 34 | + { 'id': 'n16', 'name': 'Yu Tie', 'title': 'department engineer', 'relationship': '110' } |
| 35 | + ] |
| 36 | + } |
34 | 37 | }); |
35 | 38 |
|
36 | 39 | $.mockjax({ |
37 | | - url: '/orgchart/siblings/n1', |
| 40 | + url: '/orgchart/descendants/n2', |
38 | 41 | contentType: 'application/json', |
39 | 42 | responseTime: 1000, |
40 | | - responseText: { 'siblings': [ |
41 | | - { 'id': '7','name': 'Bo Miao', 'title': 'department engineer', 'relationship': '110' }, |
42 | | - { 'id': '8', 'name': 'Yu Jie', 'title': 'department engineer', 'relationship': '110' }, |
43 | | - { 'id': '9', 'name': 'Yu Li', 'title': 'department engineer', 'relationship': '110' }, |
44 | | - { 'id': '10', 'name': 'Hong Miao', 'title': 'department engineer', 'relationship': '110' }, |
45 | | - { 'id': '11', 'name': 'Yu Wei', 'title': 'department engineer', 'relationship': '110' }, |
46 | | - { 'id': '12', 'name': 'Chun Miao', 'title': 'department engineer', 'relationship': '110' }, |
47 | | - { 'id': '13', 'name': 'Yu Tie', 'title': 'department engineer', 'relationship': '110' } |
48 | | - ]} |
| 43 | + responseText: [ |
| 44 | + { 'id': 'n4', 'name': 'Xiang Xiang', 'title': 'engineer', 'relationship': '110' } |
| 45 | + ] |
49 | 46 | }); |
50 | 47 |
|
51 | 48 | $.mockjax({ |
52 | | - url: '/orgchart/families/n1', |
| 49 | + url: '/orgchart/descendants/n3', |
53 | 50 | contentType: 'application/json', |
54 | 51 | responseTime: 1000, |
55 | | - responseText: { |
56 | | - 'id': 'n6', |
57 | | - 'name': 'Lao Lao', |
58 | | - 'title': 'general manager', |
59 | | - 'relationship': '001', |
60 | | - 'children': [ |
61 | | - { 'id': 'n7','name': 'Bo Miao', 'title': 'department engineer', 'relationship': '110' }, |
62 | | - { 'id': 'n8', 'name': 'Yu Jie', 'title': 'department engineer', 'relationship': '110' }, |
63 | | - { 'id': 'n9', 'name': 'Yu Li', 'title': 'department engineer', 'relationship': '110' }, |
64 | | - { 'id': 'n10', 'name': 'Hong Miao', 'title': 'department engineer', 'relationship': '110' }, |
65 | | - { 'id': 'n11', 'name': 'Yu Wei', 'title': 'department engineer', 'relationship': '110' }, |
66 | | - { 'id': 'n12', 'name': 'Chun Miao', 'title': 'department engineer', 'relationship': '110' }, |
67 | | - { 'id': 'n13', 'name': 'Yu Tie', 'title': 'department engineer', 'relationship': '110' } |
68 | | - ]} |
| 52 | + responseText: [ |
| 53 | + { 'id': 'n5', 'name': 'Pang Pang', 'title': 'engineer', 'relationship': '111', |
| 54 | + 'children': [ |
| 55 | + { 'id': 'n6', 'name': 'Er Dan', 'title': 'UE engineer', 'relationship': '110'} |
| 56 | + ] |
| 57 | + }, |
| 58 | + { 'id': 'n7', 'name': 'Dan Dan', 'title': 'engineer', 'relationship': '110' } |
| 59 | + ] |
69 | 60 | }); |
70 | 61 |
|
71 | 62 | var datascource = { |
|
74 | 65 | 'title': 'department manager', |
75 | 66 | 'relationship': '111', |
76 | 67 | 'children': [ |
77 | | - { 'id': 'n2','name': 'Tie Hua', 'title': 'senior engineer', 'relationship': '110' }, |
| 68 | + { 'id': 'n2','name': 'Tie Hua', 'title': 'senior engineer', 'relationship': '111' }, |
78 | 69 | { 'id': 'n3','name': 'Hei Hei', 'title': 'senior engineer', 'relationship': '111' } |
79 | 70 | ] |
80 | 71 | }; |
|
90 | 81 | } |
91 | 82 | }; |
92 | 83 |
|
93 | | - $('#chart-container').orgchart({ |
| 84 | + var oc = $('#chart-container').orgchart({ |
94 | 85 | 'data' : datascource, |
95 | | - 'ajaxURL': ajaxURLs, |
96 | 86 | 'nodeContent': 'title', |
97 | 87 | 'nodeId': 'id' |
98 | 88 | }); |
99 | 89 |
|
| 90 | + oc.$chart.on('click', '.topEdge, .horizontalEdge', function(e) { |
| 91 | + var $chart = oc.$chart; |
| 92 | + var $topEdge = $(e.target); |
| 93 | + var $node = $topEdge.parent(); |
| 94 | + var parentState = oc.getNodeState($node, 'parent'); |
| 95 | + if (!parentState.exist) { |
| 96 | + if (!($chart.data('inAjax') === true)) { |
| 97 | + $topEdge.addClass('hidden'); |
| 98 | + $node.append(`<i class="oci oci-spinner spinner"></i>`) |
| 99 | + $node.children().not('.spinner').css('opacity', 0.2); |
| 100 | + $chart.data('inAjax', true); |
| 101 | + |
| 102 | + $.ajax({ |
| 103 | + 'url': '/orgchart/ancestors/' + $node.data('nodeData').id, |
| 104 | + 'dataType': 'json' |
| 105 | + }) |
| 106 | + .done(function(data, textStatus, jqXHR) { |
| 107 | + oc.addAncestors(data, 'n0'); |
| 108 | + }) |
| 109 | + .always(function() { |
| 110 | + $topEdge.removeClass('hidden'); |
| 111 | + $node.children('.spinner').remove(); |
| 112 | + $node.children().removeAttr('style'); |
| 113 | + $chart.data('inAjax', false); |
| 114 | + }); |
| 115 | + } |
| 116 | + } |
| 117 | + }); |
| 118 | + |
| 119 | + oc.$chart.on('click', '.bottomEdge', function(e) { |
| 120 | + var $chart = oc.$chart; |
| 121 | + var $bottomEdge = $(e.target); |
| 122 | + var $node = $bottomEdge.parent(); |
| 123 | + var childrenState = oc.getNodeState($node, 'children'); |
| 124 | + if (!childrenState.exist) { |
| 125 | + if (!($chart.data('inAjax') === true)) { |
| 126 | + $bottomEdge.addClass('hidden'); |
| 127 | + $node.append(`<i class="oci oci-spinner spinner"></i>`) |
| 128 | + $node.children().not('.spinner').css('opacity', 0.2); |
| 129 | + $chart.data('inAjax', true); |
| 130 | + |
| 131 | + $.ajax({ |
| 132 | + 'url': '/orgchart/descendants/' + $node.data('nodeData').id, |
| 133 | + 'dataType': 'json' |
| 134 | + }) |
| 135 | + .done(function(data, textStatus, jqXHR) { |
| 136 | + oc.addDescendants(data, $node); |
| 137 | + }) |
| 138 | + .always(function() { |
| 139 | + $bottomEdge.removeClass('hidden'); |
| 140 | + $node.children('.spinner').remove(); |
| 141 | + $node.children().removeAttr('style'); |
| 142 | + $chart.data('inAjax', false); |
| 143 | + }); |
| 144 | + } |
| 145 | + } |
| 146 | + }); |
| 147 | + |
100 | 148 | }); |
101 | 149 | </script> |
102 | 150 | </body> |
|
0 commit comments