Skip to content

Commit a862f5e

Browse files
committed
update the demo edit-chart
1 parent e099c95 commit a862f5e

4 files changed

Lines changed: 41 additions & 20 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orgchart",
3-
"version": "1.2.5",
3+
"version": "1.2.6",
44
"homepage": "https://github.com/dabeng/OrgChart",
55
"authors": [
66
"dabeng <[email protected]>"

dist/js/jquery.orgchart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@
10981098
var $sibs = $parent.parent().siblings();
10991099
if ($parent.is('td')) {
11001100
if (getNodeState($node, 'siblings').exist) {
1101-
$sibs.eq(2).children('.top:lt(2)').remove();
1101+
$sibs.eq(2).children('.topLine:lt(2)').remove();
11021102
$sibs.eq(':lt(2)').children().attr('colspan', $sibs.eq(2).children().length);
11031103
$parent.remove();
11041104
} else {

examples/edit-orgchart/scripts.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
var datascource = {
88
'name': 'Ball game',
9-
'relationship': '001',
109
'children': [
11-
{ 'name': 'Football', 'relationship': '110' },
12-
{ 'name': 'Basketball', 'relationship': '110' },
13-
{ 'name': 'Volleyball', 'relationship': '110' }
10+
{ 'name': 'Football' },
11+
{ 'name': 'Basketball' },
12+
{ 'name': 'Volleyball' }
1413
]
1514
};
1615

@@ -25,21 +24,21 @@
2524
'parentNodeSymbol': 'fa-th-large',
2625
'createNode': function($node, data) {
2726
$node[0].id = getId();
28-
$node.on('click', function(event) {
29-
if (!$(event.target).is('.edge')) {
30-
$('#selected-node').val(data.name).data('node', $node);
31-
}
32-
});
3327
}
3428
})
29+
.on('click', '.node', function() {
30+
var $this = $(this);
31+
$('#selected-node').val($this.find('.title').text()).data('node', $this);
32+
})
3533
.on('click', '.orgchart', function(event) {
3634
if (!$(event.target).closest('.node').length) {
3735
$('#selected-node').val('');
3836
}
3937
});
4038

4139
$('input[name="chart-state"]').on('click', function() {
42-
$('#edit-panel, .orgchart').toggleClass('view-state');
40+
$('.orgchart').toggleClass('view-state', this.value !== 'view');
41+
$('#edit-panel').toggleClass('view-state', this.value === 'view');
4342
if ($(this).val() === 'edit') {
4443
$('.orgchart').find('tr').removeClass('hidden')
4544
.find('td').removeClass('hidden')
@@ -85,16 +84,33 @@
8584
return;
8685
}
8786
var nodeType = $('input[name="node-type"]:checked');
88-
if (nodeType.val() !== 'parent' && !$node) {
89-
alert('Please select one node in orgchart');
90-
return;
91-
}
9287
if (!nodeType.length) {
9388
alert('Please select a node type');
9489
return;
9590
}
91+
if (nodeType.val() !== 'parent' && !$('.orgchart').length) {
92+
alert('Please creat the root node firstly when you want to build up the orgchart from the scratch');
93+
return;
94+
}
95+
if (nodeType.val() !== 'parent' && !$node) {
96+
alert('Please select one node in orgchart');
97+
return;
98+
}
9699
if (nodeType.val() === 'parent') {
97-
$chartContainer.orgchart('addParent', $chartContainer.find('.node:first'), { 'name': nodeVals[0], 'Id': getId() });
100+
if (!$chartContainer.children().length) {// if the original chart has been deleted
101+
$chartContainer.orgchart({
102+
'data' : { 'name': nodeVals[0] },
103+
'exportButton': true,
104+
'exportFilename': 'SportsChart',
105+
'parentNodeSymbol': 'fa-th-large',
106+
'createNode': function($node, data) {
107+
$node[0].id = getId();
108+
}
109+
})
110+
.find('.orgchart').addClass('view-state');
111+
} else {
112+
$chartContainer.orgchart('addParent', $chartContainer.find('.node:first'), { 'name': nodeVals[0], 'Id': getId() });
113+
}
98114
} else if (nodeType.val() === 'siblings') {
99115
$chartContainer.orgchart('addSiblings', $node,
100116
{ 'siblings': nodeVals.map(function(item) { return { 'name': item, 'relationship': '110', 'Id': getId() }; })
@@ -121,13 +137,18 @@
121137
if (!$node) {
122138
alert('Please select one node in orgchart');
123139
return;
140+
} else if ($node[0] === $('.orgchart').find('.node:first')[0]) {
141+
if (!window.confirm('Are you sure you want to delete the whole chart?')) {
142+
return;
143+
}
124144
}
125145
$('#chart-container').orgchart('removeNodes', $node);
126-
$('#selected-node').data('node', null);
146+
$('#selected-node').val('').data('node', null);
127147
});
128148

129149
$('#btn-reset').on('click', function() {
130-
$('.orgchart').trigger('click');
150+
$('.orgchart').find('.focused').removeClass('focused');
151+
$('#selected-node').val('');
131152
$('#new-nodelist').find('input:first').val('').parent().siblings().remove();
132153
$('#node-type-panel').find('input').prop('checked', false);
133154
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orgchart",
3-
"version": "1.2.5",
3+
"version": "1.2.6",
44
"description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
55
"main": "./dist/js/jquery.orgchart.js",
66
"style": [

0 commit comments

Comments
 (0)