- Change forEach for each interator

- Fix issue deleting nodes with intermediate relationships
This commit is contained in:
Paulo Gustavo Veiga 2012-07-08 19:31:21 -03:00
parent 8175eea928
commit 39c2b37a1f
24 changed files with 521 additions and 508 deletions

View File

@ -73,7 +73,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeFontSizeToTopic : function(topicsIds, size) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontSize(size, true);
@ -81,7 +81,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeFontColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontColor(color, true);
@ -89,7 +89,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeFontFamilyToTopic : function(topicsIds, family) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontFamily(family, true);
@ -97,7 +97,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeFontStyleToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
var style = ( topic.getFontStyle() == "italic") ? "normal" : "italic";
@ -106,7 +106,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeShapeTypeToTopic : function(topicsIds, shapeType) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setShapeType(shapeType);
@ -114,7 +114,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeFontWeightToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
var weight = (topic.getFontWeight() == "bold") ? "normal" : "bold";
@ -123,7 +123,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeBackgroundColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setBackgroundColor(color, true);
@ -132,7 +132,7 @@ mindplot.BrixActionDispatcher = new Class({
},
changeBorderColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setBorderColor(color);
@ -144,7 +144,7 @@ mindplot.BrixActionDispatcher = new Class({
var framework = this._getFramework();
var mindmap = framework.getModel();
topicsIds.forEach(function(topicId) {
topicsIds.each(function(topicId) {
var topic = framework.getTopic(topicId);
topic.deleteNode();
});

View File

@ -109,7 +109,7 @@ mindplot.Designer = new Class({
screenManager.addEvent('update', function () {
// Topic must be set to his original state. All editors must be closed.
var topics = this.getModel().getTopics();
topics.forEach(function (object) {
topics.each(function (object) {
object.closeEditors();
});
@ -271,13 +271,13 @@ mindplot.Designer = new Class({
onObjectFocusEvent:function (currentObject, event) {
// Close node editors ..
var topics = this.getModel().getTopics();
topics.forEach(function (topic) {
topics.each(function (topic) {
topic.closeEditors();
});
var model = this.getModel();
var objects = model.getEntities();
objects.forEach(function (object) {
objects.each(function (object) {
// Disable all nodes on focus but not the current if Ctrl key isn't being pressed
if (!$defined(event) || (!event.control && !event.meta)) {
if (object.isOnFocus() && object != currentObject) {
@ -291,14 +291,14 @@ mindplot.Designer = new Class({
selectAll:function () {
var model = this.getModel();
var objects = model.getEntities();
objects.forEach(function (object) {
objects.each(function (object) {
object.setOnFocus(true);
});
},
deselectAll:function () {
var objects = this.getModel().getEntities();
objects.forEach(function (object) {
objects.each(function (object) {
object.setOnFocus(false);
});
},

View File

@ -103,7 +103,7 @@ mindplot.IconGroup = new Class({
this._resize(this._icons.length);
// Add all again ...
this._icons.forEach(function(elem, i) {
this._icons.each(function(elem, i) {
this._positionIcon(elem, i);
}.bind(this));
},

View File

@ -103,7 +103,7 @@ mindplot.MultilineTextEditor = new Class({
var lines = textElem.value.split('\n');
var maxLineLength = 1;
lines.forEach(function(line) {
lines.each(function(line) {
if (maxLineLength < line.length)
maxLineLength = line.length;
});

View File

@ -53,7 +53,7 @@ mindplot.RelationshipPivot = new Class({
// Register focus events on all topics ...
var model = this._designer.getModel();
var topics = model.getTopics();
topics.forEach(function (topic) {
topics.each(function (topic) {
topic.addEvent('ontfocus', this._onTopicClick);
}.bind(this));
}
@ -69,7 +69,7 @@ mindplot.RelationshipPivot = new Class({
var model = this._designer.getModel();
var topics = model.getTopics();
topics.forEach(function (topic) {
topics.each(function (topic) {
topic.removeEvent('ontfocus', this._onTopicClick);
}.bind(this));

View File

@ -55,7 +55,7 @@ mindplot.ScreenManager = new Class({
fireEvent : function(type, event) {
if (type == 'click') {
this._clickEvents.forEach(function(listener) {
this._clickEvents.each(function(listener) {
listener(type, event);
});
}

View File

@ -875,7 +875,7 @@ mindplot.Topic = new Class({
},
_setRelationshipLinesVisibility:function (value) {
this._relationships.forEach(function (relationship) {
this._relationships.each(function (relationship) {
relationship.setVisibility(value);
});
},

View File

@ -29,7 +29,7 @@ mindplot.commands.AddTopicCommand = new Class({
execute:function (commandContext) {
this._models.forEach(function (model, index) {
this._models.each(function (model, index) {
// Add a new topic ...
var topic = commandContext.createTopic(model, false);
@ -56,7 +56,7 @@ mindplot.commands.AddTopicCommand = new Class({
undoExecute:function (commandContext) {
// Finally, delete the topic from the workspace ...
this._models.forEach(function (model) {
this._models.each(function (model) {
var topicId = model.getId();
var topic = commandContext.findTopics(topicId)[0];

View File

@ -36,18 +36,18 @@ mindplot.commands.DeleteCommand = new Class({
if (topics.length > 0) {
topics.forEach(
function (topic) {
topics.each(function (topic) {
var model = topic.getModel();
// Delete relationships
var relationships = topic.getRelationships();
while (relationships.length > 0) {
var relationship = relationships[0];
var relationships = this._collectInDepthRelationships(topic);
this._deletedRelModel.append(relationships.map(function (rel) {
return rel.getModel().clone();
}));
this._deletedRelModel.push(relationship.getModel().clone());
relationships.each(function (relationship) {
commandContext.deleteRelationship(relationship);
}
});
// Store information for undo ...
var clonedModel = model.clone();
@ -62,23 +62,22 @@ mindplot.commands.DeleteCommand = new Class({
// Finally, delete the topic from the workspace...
commandContext.deleteTopic(topic);
}.bind(this)
);
}, this);
}
var rels = commandContext.findRelationships(this._relIds);
if (rels.length > 0) {
rels.forEach(function (rel) {
rels.each(function (rel) {
this._deletedRelModel.push(rel.getModel().clone());
commandContext.deleteRelationship(rel);
}.bind(this));
}, this);
}
},
undoExecute:function (commandContext) {
var parent = commandContext.findTopics(this._parentTopicIds);
this._deletedTopicModels.forEach(
function (model, index) {
this._deletedTopicModels.each(function (model, index) {
var topic = commandContext.createTopic(model);
// Was the topic connected?
@ -88,11 +87,10 @@ mindplot.commands.DeleteCommand = new Class({
topic.setOnFocus(true);
}
}.bind(this)
);
}, this);
this._deletedRelModel.forEach(function (model) {
this._deletedRelModel.each(function (model) {
commandContext.addRelationship(model);
}.bind(this));
@ -105,7 +103,7 @@ mindplot.commands.DeleteCommand = new Class({
var topics = commandContext.findTopics(topicIds);
var result = [];
topics.forEach(function (topic) {
topics.each(function (topic) {
var parent = topic.getParent();
var found = false;
while (parent != null && !found) {
@ -122,5 +120,20 @@ mindplot.commands.DeleteCommand = new Class({
});
return result;
},
_collectInDepthRelationships:function (topic) {
var result = [];
var children = topic.getChildren();
if (children.length > 0) {
var rels = children.map(function (topic) {
return this._collectInDepthRelationships(topic);
}, this);
result.append(rels.flatten());
} else {
result.append(topic.getRelationships());
}
return result;
}
});

View File

@ -32,7 +32,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
execute: function(commandContext) {
if (!this.applied) {
var topics = commandContext.findTopics(this._topicsIds);
topics.forEach(function(topic) {
topics.each(function(topic) {
var oldValue = this._commandFunc(topic, this._value);
this._oldValues.push(oldValue);
}.bind(this));
@ -46,7 +46,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
undoExecute: function(commandContext) {
if (this.applied) {
var topics = commandContext.findTopics(this._topicsIds);
topics.forEach(function(topic, index) {
topics.each(function(topic, index) {
this._commandFunc(topic, this._oldValues[index]);
}.bind(this));

View File

@ -38,7 +38,7 @@ mindplot.layout.AbstractBasicSorter = new Class({
result = height;
} else {
var childrenHeight = 0;
children.forEach(function(child) {
children.each(function(child) {
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
}, this);

View File

@ -154,7 +154,7 @@ mindplot.layout.BalancedSorter = new Class({
var totalPHeight = 0;
var totalNHeight = 0;
heights.forEach(function (elem) {
heights.each(function (elem) {
if (elem.order % 2 == 0) {
totalPHeight += elem.height;
} else {

View File

@ -143,7 +143,7 @@ mindplot.layout.LayoutManager = new Class({
},
_flushEvents: function() {
this._events.forEach(function(event) {
this._events.each(function(event) {
this.fireEvent('change', event);
}, this);
this._events = [];
@ -153,7 +153,7 @@ mindplot.layout.LayoutManager = new Class({
if (!nodes)
nodes = this._treeSet.getTreeRoots();
nodes.forEach(function(node) {
nodes.each(function(node) {
if (node.hasOrderChanged() || node.hasPositionChanged()) {
// Find or create a event ...

View File

@ -70,7 +70,7 @@ mindplot.layout.OriginalLayout = new Class({
layout:function () {
var roots = this._treeSet.getTreeRoots();
roots.forEach(function (node) {
roots.each(function (node) {
// Calculate all node heights ...
var sorter = node.getSorter();
@ -108,7 +108,7 @@ mindplot.layout.OriginalLayout = new Class({
var offsetById = sorter.computeOffsets(this._treeSet, node);
var parentPosition = node.getPosition();
children.forEach(function (child) {
children.each(function (child) {
var offset = offsetById[child.getId()];
var childFreeDisplacement = child.getFreeDisplacement();
@ -133,7 +133,7 @@ mindplot.layout.OriginalLayout = new Class({
}
// Continue reordering the children nodes ...
children.forEach(function (child) {
children.each(function (child) {
this._layoutChildren(child, heightById);
}, this);
},
@ -183,7 +183,7 @@ mindplot.layout.OriginalLayout = new Class({
this._shiftBranches(node, heightById);
}
children.forEach(function (child) {
children.each(function (child) {
this._fixOverlapping(child, heightById);
}, this);
},
@ -193,7 +193,7 @@ mindplot.layout.OriginalLayout = new Class({
var siblingsToShift = this._treeSet.getSiblingsInVerticalDirection(node, node.getFreeDisplacement().y);
var last = node;
siblingsToShift.forEach(function (sibling) {
siblingsToShift.each(function (sibling) {
var overlappingOccurs = shiftedBranches.some(function (shiftedBranch) {
return this._branchesOverlap(shiftedBranch, sibling, heightById);
}, this);
@ -209,7 +209,7 @@ mindplot.layout.OriginalLayout = new Class({
return !shiftedBranches.contains(branch);
});
branchesToShift.forEach(function (branch) {
branchesToShift.each(function (branch) {
var bAmount = node.getFreeDisplacement().y;
this._treeSet.shiftBranchPosition(branch, 0, bAmount);
shiftedBranches.push(branch);

View File

@ -240,7 +240,7 @@ mindplot.layout.RootedTreeSet = new Class({
var yOffset = oldPos.y - position.y;
var children = this.getChildren(node);
children.forEach(function (child) {
children.each(function (child) {
this.shiftBranchPosition(child, xOffset, yOffset);
}.bind(this));
@ -251,7 +251,7 @@ mindplot.layout.RootedTreeSet = new Class({
node.setPosition({x:position.x + xOffset, y:position.y + yOffset});
var children = this.getChildren(node);
children.forEach(function (child) {
children.each(function (child) {
this.shiftBranchPosition(child, xOffset, yOffset);
}.bind(this));
},

View File

@ -133,7 +133,7 @@ mindplot.layout.SymmetricSorter = new Class({
// Compute the center of the branch ...
var totalHeight = 0;
heights.forEach(function(elem) {
heights.each(function(elem) {
totalHeight += elem.height;
});
var ysum = totalHeight / 2;

View File

@ -135,7 +135,7 @@ mindplot.model.IMindmap = new Class({
// Then the rest of the branches ...
var sbranchs = source.getBranches();
sbranchs.forEach(function(snode) {
sbranchs.each(function(snode) {
var tnode = target.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode);
target.addBranch(tnode);

View File

@ -213,7 +213,7 @@ mindplot.model.INodeModel = new Class({
var source = this;
// Copy properties ...
var keys = source.getPropertiesKeys();
keys.forEach(function(key) {
keys.each(function(key) {
var value = source.getProperty(key);
target.putProperty(key, value);
});
@ -222,7 +222,7 @@ mindplot.model.INodeModel = new Class({
var children = this.getChildren();
var tmindmap = target.getMindmap();
children.forEach(function(snode) {
children.each(function(snode) {
var tnode = tmindmap.createNode(snode.getType(), snode.getId());
snode.copyTo(tnode);
target.appendChild(tnode);
@ -278,10 +278,10 @@ mindplot.model.INodeModel = new Class({
var children = this.getChildren();
if (children.length > 0) {
result = result + ", children: {(size:" + children.length;
children.forEach(function(node) {
children.each(function(node) {
result = result + "=> (";
var keys = node.getPropertiesKeys();
keys.forEach(function(key) {
keys.each(function(key) {
var value = node.getProperty(key);
result = result + key + ":" + value + ",";
});

View File

@ -25,7 +25,7 @@ mindplot.util.FadeEffect = new Class({
this.addEvent('complete', function() {
this._element.forEach(function(elem) {
this._element.each(function(elem) {
if(elem){
elem.setVisibility(isVisible);
}
@ -39,7 +39,7 @@ mindplot.util.FadeEffect = new Class({
},
set: function(now) {
this._element.forEach(function(elem) {
this._element.each(function(elem) {
if(elem){
elem.setOpacity(now);
}

View File

@ -63,7 +63,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Register on toolbar elements ...
var colorCells = content.getElements('div[class=palette-colorswatch]');
var model = this.getModel();
colorCells.forEach(function(elem) {
colorCells.each(function(elem) {
elem.addEvent('click', function() {
var color = elem.getStyle("background-color");
model.setValue(color);
@ -79,7 +79,7 @@ mindplot.widget.ColorPalettePanel = new Class({
// Clear selected cell based on the color ...
var tdCells = panelElem.getElements("td[class='palette-cell palette-cell-selected']");
tdCells.forEach(function(elem) {
tdCells.each(function(elem) {
elem.className = 'palette-cell';
});
@ -87,7 +87,7 @@ mindplot.widget.ColorPalettePanel = new Class({
var colorCells = panelElem.getElements('div[class=palette-colorswatch]');
var model = this.getModel();
var modelValue = model.getValue();
colorCells.forEach(function(elem) {
colorCells.each(function(elem) {
var color = elem.getStyle("background-color");
if (modelValue == color) {
elem.parentNode.className = 'palette-cell palette-cell-selected';

View File

@ -29,7 +29,7 @@ mindplot.widget.IMenu = new Class({
},
clear:function () {
this._toolbarElems.forEach(function (item) {
this._toolbarElems.each(function (item) {
item.hide();
});
},

View File

@ -26,7 +26,7 @@ mindplot.widget.ListToolbarPanel = new Class({
_initPanel: function () {
// Register on toolbar elements ...
var menuElems = this.getPanelElem().getElements('div');
menuElems.forEach(function(elem) {
menuElems.each(function(elem) {
elem.addEvent('click', function(event) {
event.stopPropagation();
this.hide();
@ -41,7 +41,7 @@ mindplot.widget.ListToolbarPanel = new Class({
var panelElem = this.getPanelElem();
var menuElems = panelElem.getElements('div');
var value = this.getModel().getValue();
menuElems.forEach(function(elem) {
menuElems.each(function(elem) {
var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id;
$assert(elemValue,"elemValue can not be null");
if (elemValue == value)

View File

@ -438,7 +438,7 @@ mindplot.widget.Menu = new Class({
_registerEvents:function (designer) {
// Register on close events ...
this._toolbarElems.forEach(function (elem) {
this._toolbarElems.each(function (elem) {
elem.addEvent('show', function () {
this.clear()
}.bind(this));
@ -448,7 +448,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.forEach(function (button) {
this._toolbarElems.each(function (button) {
var disable = false;
if (button.isTopicAction() && button.isRelAction()) {
disable = rels.length == 0 && topics.length == 0;
@ -474,7 +474,7 @@ mindplot.widget.Menu = new Class({
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.forEach(function (button) {
this._toolbarElems.each(function (button) {
if (button.isTopicAction() && topics.length > 0) {
button.enable();
}

View File

@ -443,7 +443,7 @@ mindplot.layout.FreeTestSuite = new Class({
}
var treeSet = manager._treeSet;
treeSet._rootNodes.forEach(function(rootNode) {
treeSet._rootNodes.each(function(rootNode) {
var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
this._assertBranchCollision(treeSet, rootNode, heightById);
}, this);
@ -453,7 +453,7 @@ mindplot.layout.FreeTestSuite = new Class({
var children = treeSet.getChildren(node);
var childOfRootNode = treeSet._rootNodes.contains(node);
children.forEach(function(child) {
children.each(function(child) {
var height = heightById[child.getId()];
var siblings = treeSet.getSiblings(child);
if (childOfRootNode) {
@ -461,12 +461,12 @@ mindplot.layout.FreeTestSuite = new Class({
return (child.getOrder() % 2) == (sibling.getOrder() % 2);
})
}
siblings.forEach(function(sibling) {
siblings.each(function(sibling) {
this._branchesOverlap(child, sibling, heightById);
}, this);
}, this);
children.forEach(function(child) {
children.each(function(child) {
this._assertBranchCollision(treeSet, child, heightById);
}, this)
},