Hello I created a SelectionDeleting Event, which is working. However when I double click on a link it says g is null. The double clicking on a link it totally seperate from the selectiondeleting function. Its as if when I call the following
var newnode = createNodeAndLink(link._dragData, fromnode, linkDataFrom, linkDataTo );
it errors out to g is null in the console. This function was working properly before I added my SelectionDeleting function. The code for the SelectionDeleting function is below: Just to reiterate SelectionDeleting function works. The createNodeAndLink works if the SelectionDeleting function is commented out.
myDiagram.selection.each(function(node) {
//general deletion of a node
if (node instanceof go.Node) {
data = node.data;
myDiagram.model.setDataProperty(data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(data, ‘visible’, false);
console.log(myDiagram.selection.first().part);
checkGroupNode = myDiagram.selection.first().part.findNodesConnected();
console.log(checkGroupNode)
while (checkGroupNode.next()) {
if (checkGroupNode.value.data.type === “group_parent”){
myDiagram.model.setDataProperty(checkGroupNode.value.data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(checkGroupNode.value.data, ‘visible’, false);
var partsGroup = checkGroupNode.value.memberParts;
while (partsGroup.next()){
myDiagram.model.setDataProperty(partsGroup.value.data, ‘status’, ‘deleted’);
myDiagram.model.setDataProperty(partsGroup.value.data, ‘visible’, false);
}
var linksConnectedGroup = checkGroupNode.value.findLinksConnected();
while (linksConnectedGroup.next()){
console.log(linksConnectedGroup.value.data)
savedLink = linksConnectedGroup.value;
}
}
}
}
//deletion of a group and its children
if (myDiagram.selection.first().part.data.type === 'group_parent') {
for (var it = myDiagram.nodes; it.next(); ) {
var n = it.value; // n is now a Node or a Group
if (n.data.type === "link_item" && n.data.group === data.key ) {
myDiagram.model.setDataProperty(n.data, 'status', 'deleted');
myDiagram.model.setDataProperty(data, 'visible', false);
var it = myDiagram.selection.first().part.findLinksConnected(), i= 0;
while (it.next()) {
i++
var item = it.value, fromNode, toNode;
if (i === 1){
fromNode = item.data['to'];
} else if (i === 2){
toNode = item.data['from'];
}
}
myDiagram.startTransaction("create Links");
myDiagram.model.addLinkData({ from: fromNode, to: toNode });
myDiagram.commitTransaction("create Links");
}
}
}
//deletion of links
if (myDiagram.selection.first().part.data.points){
//console.log(myDiagram.findLinkForData(myDiagram.selection.first().part.data).data)
var data = myDiagram.findLinkForData(myDiagram.selection.first().part.data).data,
fromNode = data['from'],
toNodeOld = data['to'],
nodeOld, finalToNode;
if (data['group_id'] !== 'undefined'){
nodeOld = myDiagram.findNodeForKey(fromNode);
//console.log(nodeOld.data['key'])
}else{
nodeOld = myDiagram.findNodeForKey(toNodeOld);
//console.log(nodeOld.data['key'])
}
var it = nodeOld.findLinksOutOf(), group, toNodeNew;
while (it.next()){
toNodeNew = it.value.data['to'];
if (it.value.data['group_id']){
group = myDiagram.findNodeForKey(it.value.data['from']);
}else if (it.value.data['group_id'] !== 'undefined') {
group = myDiagram.findNodeForKey(it.value.data['to']);
}
}
if (group.data.type === 'group_parent'){
//group status to deleted and visible to false
myDiagram.model.setDataProperty(group.data, 'status', 'deleted');
myDiagram.model.setDataProperty(group.data, 'visible', false);
//nodes within group status to deleted and visible to false
for (var it = myDiagram.nodes; it.next(); ) {
var n = it.value;
if (n.data.type === "link_item" && n.data.group === group.data.key ) {
myDiagram.model.setDataProperty(n.data, 'status', 'deleted');
myDiagram.model.setDataProperty(n.data, 'visible', false);
}
}
myDiagram.startTransaction("create Links");
myDiagram.model.addLinkData({ from: fromNode, to: toNodeNew });
myDiagram.commitTransaction("create Links");
}
var keyGroup = group.data['key'];
}
if (keyGroup){
//console.log(group.data['key'])
var itGroupInto = group.findNodesInto(),
itGroupOut = group.findNodesOutOf(),
fromGroupNode,
toGroupNode;
while (itGroupInto.next()){
fromGroupNode = itGroupInto.value.data['key']
//console.log(itGroupInto.value.data['key'])
}
while (itGroupOut.next()){
toGroupNode = itGroupOut.value.data['key']
// console.log(itGroupOut.value.data['key'])
}
myDiagram.startTransaction("create Links");
myDiagram.model.addLinkData({ from: fromGroupNode, to: toGroupNode });
myDiagram.commitTransaction("create Links");
myDiagram.model.setDataProperty(group.data, 'status', 'deleted');
myDiagram.model.setDataProperty(group.data, 'visible', false);
for (var it = myDiagram.nodes.iterator; it.next(); ) {
// console.log(it.value)
if (it.value instanceof go.Node ) {
if (it.value === group){
savedNode = it.value;
}
}
}
}
});
if (typeof savedNode !== 'undefined'){
myDiagram.remove(savedNode)
}
if (typeof savedLink !== 'undefined'){
myDiagram.remove(savedLink)
}
// console.log(myDiagram.model.toJson())
e.cancel = false;
myDiagram.commitTransaction('change status');
e.cancel = false;
myDiagram.commitTransaction("delete");
}