I need to extend a function defined in my DrawCommandHandler and that works fine if I’m overriding it but how can I actually extend it. Now being forced to duplicate.
mainDiagram.commandHandler._getGroupNodes = function(group) {
//this next line doesn't work
var allParts = DrawCommandHandler.prototype._getGroupNodes.call(this, group);
var linkIt = group.findLinksConnected();
while (linkIt.next()) {
... add some links as grouped nodes
}
return allParts;
};
So you want to replace the standard Diagram.commandHandler with a custom DrawCommandHandler? Just subclass DrawCommandHandler and replace the Diagram.commandHandler with an instance of the new class.
I have a custom DrawCommandHandler. But in some diagrams I need to provide custom handling. In the example the groupNodes are both the normal ones (as defined in my DrawCommandHandler) but should also include some link attached nodes for navigation purpose.
Like I said, right now I duplicate the getGroupNodes from my DrawCommandHandler at the var allParts line, but that doesn’t sound like the right way to do things.
Oh, so your question isn’t where to put the code, but how to write the code? I don’t understand what you want to do, so I am unable to help you with the latter. I have no idea of how your _getGroupNodes method should behave or how it is called.
If I am trying to call a function in my customized DrawCommandHandler, it does exist. And when it is invoked from within DrawCommandHandler, it will correctly trigger the diagram version that I showed.
The question is, what is the syntax to call an inherited function in this case, similar to what I would do if I wanted to extend CommandHandler as shown in my previous post.
So that method does exist in your copy of DrawCommandHandler.js? That’s confusing, but OK. Then that should work, if that is actually what you have done and have loaded.
Having a bit of a hard time being on the same page
Ok, in DrawCommandHandler I have this function:
DrawCommandHandler.prototype._getGroupNodes = function(group) {
var allParts = new Array();
group.memberParts.each(function(member) {
if (member instanceof go.Node) {
allParts.push(member);
}
});
// note that this ignores Links
return allParts;
};
and it gets call like this:
var grpTopLeft = getHandler().topLeftPart(originalPart, this._getGroupNodes(originalPart));
this._processSelection(diagram, grpTopLeft, e);
in one specific diagram I need to extend the normal behavior. So I implemented this version:
mainDiagram.commandHandler._getGroupNodes = function(group) {
var allParts = new Array();
group.memberParts.each(function(member) {
if (member instanceof go.Node) {
allParts.push(member);
}
});
// var allParts = DrawCommandHandler.prototype._getGroupNodes.call(this, group);
var linkIt = group.findLinksConnected();
while (linkIt.next()) { // for each link get the link text and toNode text
var link = linkIt.value;
if (link.category == ENTRY_CRITERIA_LINK_CATEGORY || link.category == EXIT_CRITERIA_LINK_CATEGORY) {
if (link.fromNode != group) {
allParts.push(link.fromNode);
}
else {
allParts.push(link.toNode);
}
}
}
return allParts;
};
which works, but notice that I had to replicate the code from DrawCommandHandler.
My attempt to invoke the parent/base/inherited, call it what you want, version of the method as shown in the commented line, doesn’t work. It actually seems to completely ignore this extended method.
OK. It appears to me that your code calling the super method is correct. I hope you set mainDiagram.commandHandler = new DrawCommandHandler() before you set its _getGroupNodes method.