mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-05 07:03:24 +01:00
Relationships works with commands ...
This commit is contained in:
parent
8da65a9102
commit
82dc1fc3d4
@ -23,7 +23,7 @@ mindplot.ActionDispatcher = new Class({
|
||||
$assert(commandContext, "commandContext can not be null");
|
||||
},
|
||||
|
||||
connectByRelation: function(model, mindmap) {
|
||||
addRelationship: function(model, mindmap) {
|
||||
throw "method must be implemented.";
|
||||
},
|
||||
|
||||
|
@ -491,15 +491,6 @@ mindplot.Designer = new Class({
|
||||
this._relPivot.start(nodes[0], pos);
|
||||
},
|
||||
|
||||
connectByRelation:function (sourceTopic, targetTopic) {
|
||||
$assert(sourceTopic, "sourceTopic can not be null");
|
||||
$assert(targetTopic, "targetTopic can not be null");
|
||||
|
||||
// Create a new topic model ...
|
||||
var mindmap = this.getMindmap();
|
||||
var model = mindmap.createRelationship(sourceTopic.getModel().getId(), targetTopic.getModel().getId());
|
||||
this._actionDispatcher.connectByRelation(model);
|
||||
},
|
||||
|
||||
needsSave:function () {
|
||||
//@Todo: Review all this ...
|
||||
@ -600,21 +591,22 @@ mindplot.Designer = new Class({
|
||||
_relationshipModelToRelationship:function (model) {
|
||||
$assert(model, "Node model can not be null");
|
||||
|
||||
var relationship = this._buildRelationship(model);
|
||||
var sourceTopic = relationship.getSourceTopic();
|
||||
sourceTopic.connectByRelation(relationship);
|
||||
var result = this._buildRelationship(model);
|
||||
|
||||
var targetTopic = relationship.getTargetTopic();
|
||||
targetTopic.connectByRelation(relationship);
|
||||
relationship.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
|
||||
var sourceTopic = result.getSourceTopic();
|
||||
sourceTopic.addRelationship(result);
|
||||
|
||||
var workspace = this._workspace;
|
||||
workspace.appendChild(relationship);
|
||||
relationship.redraw();
|
||||
return relationship;
|
||||
var targetTopic = result.getTargetTopic();
|
||||
targetTopic.addRelationship(result);
|
||||
|
||||
result.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
|
||||
|
||||
this._workspace.appendChild(result);
|
||||
result.redraw();
|
||||
return result;
|
||||
},
|
||||
|
||||
createRelationship:function (model) {
|
||||
_addRelationship:function (model) {
|
||||
this._mindmap.addRelationship(model);
|
||||
return this._relationshipModelToRelationship(model);
|
||||
},
|
||||
@ -641,14 +633,14 @@ mindplot.Designer = new Class({
|
||||
var targetTopic = dmodel.findTopicById(targetTopicId);
|
||||
|
||||
// Build relationship line ....
|
||||
var relationship = new mindplot.Relationship(sourceTopic, targetTopic, model);
|
||||
relationship.addEvent('onfocus', function (event) {
|
||||
this.onObjectFocusEvent(relationship, event);
|
||||
var result = new mindplot.Relationship(sourceTopic, targetTopic, model);
|
||||
result.addEvent('onfocus', function (event) {
|
||||
this.onObjectFocusEvent(result, event);
|
||||
}.bind(this));
|
||||
|
||||
// Append it to the workspace ...
|
||||
dmodel.addRelationship(relationship);
|
||||
return relationship;
|
||||
dmodel.addRelationship(result);
|
||||
return result;
|
||||
},
|
||||
|
||||
_removeTopic:function (node) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
mindplot.RelationshipPivot = new Class({
|
||||
initialize: function(workspace, designer) {
|
||||
initialize:function (workspace, designer) {
|
||||
$assert(workspace, "workspace can not be null");
|
||||
$assert(designer, "designer can not be null");
|
||||
this._workspace = workspace;
|
||||
@ -29,7 +29,7 @@ mindplot.RelationshipPivot = new Class({
|
||||
|
||||
},
|
||||
|
||||
start : function(sourceTopic, targetPos) {
|
||||
start:function (sourceTopic, targetPos) {
|
||||
$assert(sourceTopic, "sourceTopic can not be null");
|
||||
$assert(targetPos, "targetPos can not be null");
|
||||
|
||||
@ -53,14 +53,14 @@ mindplot.RelationshipPivot = new Class({
|
||||
// Register focus events on all topics ...
|
||||
var model = this._designer.getModel();
|
||||
var topics = model.getTopics();
|
||||
topics.forEach(function(topic) {
|
||||
topics.forEach(function (topic) {
|
||||
topic.addEvent('ontfocus', this._onTopicClick);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
dispose:function () {
|
||||
var workspace = this._workspace;
|
||||
|
||||
if (this._isActive()) {
|
||||
@ -69,7 +69,7 @@ mindplot.RelationshipPivot = new Class({
|
||||
|
||||
var model = this._designer.getModel();
|
||||
var topics = model.getTopics();
|
||||
topics.forEach(function(topic) {
|
||||
topics.forEach(function (topic) {
|
||||
topic.removeEvent('ontfocus', this._onTopicClick);
|
||||
}.bind(this));
|
||||
|
||||
@ -81,7 +81,7 @@ mindplot.RelationshipPivot = new Class({
|
||||
}
|
||||
},
|
||||
|
||||
_mouseMove : function(event) {
|
||||
_mouseMove:function (event) {
|
||||
var screen = this._workspace.getScreenManager();
|
||||
var pos = screen.getWorkspaceMousePosition(event);
|
||||
|
||||
@ -90,21 +90,22 @@ mindplot.RelationshipPivot = new Class({
|
||||
return false;
|
||||
},
|
||||
|
||||
_cleanOnMouseClick : function (event) {
|
||||
_cleanOnMouseClick:function (event) {
|
||||
|
||||
// The user clicks on a desktop on in other element that is not a node.
|
||||
this.dispose();
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
_connectOnFocus : function(topic) {
|
||||
_connectOnFocus:function (targetTopic) {
|
||||
var sourceTopic = this._sourceTopic;
|
||||
var mindmap = this._designer.getMindmap();
|
||||
var relModel = mindmap.createRelationship(targetTopic.getId(), sourceTopic.getId());
|
||||
this._designer._actionDispatcher.addRelationship(relModel);
|
||||
this.dispose();
|
||||
this._designer.connectByRelation(sourceTopic, topic);
|
||||
|
||||
},
|
||||
|
||||
_isActive : function() {
|
||||
_isActive:function () {
|
||||
return this._pivot != null;
|
||||
}
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ mindplot.StandaloneActionDispatcher = new Class({
|
||||
this.execute(command);
|
||||
},
|
||||
|
||||
connectByRelation:function (model) {
|
||||
addRelationship:function (model) {
|
||||
var command = new mindplot.commands.AddRelationshipCommand(model);
|
||||
this.execute(command);
|
||||
},
|
||||
@ -276,9 +276,9 @@ mindplot.CommandContext = new Class({
|
||||
topic.disconnect(this._designer._workspace);
|
||||
},
|
||||
|
||||
createRelationship:function (model) {
|
||||
addRelationship:function (model) {
|
||||
$assert(model, "model cannot be null");
|
||||
return this._designer.createRelationship(model);
|
||||
return this._designer._addRelationship(model);
|
||||
},
|
||||
|
||||
deleteRelationship:function (relationship) {
|
||||
|
@ -311,7 +311,7 @@ mindplot.Topic = new Class({
|
||||
this._adjustShapes();
|
||||
},
|
||||
|
||||
connectByRelation : function(relationship) {
|
||||
addRelationship : function(relationship) {
|
||||
this._relationships.push(relationship);
|
||||
},
|
||||
|
||||
|
@ -17,24 +17,19 @@
|
||||
*/
|
||||
mindplot.commands.AddRelationshipCommand = new Class({
|
||||
Extends:mindplot.Command,
|
||||
initialize: function(model) {
|
||||
initialize:function (model) {
|
||||
$assert(model, 'Relationship model can not be null');
|
||||
|
||||
this.parent();
|
||||
this._model = model;
|
||||
},
|
||||
execute: function(commandContext) {
|
||||
var relationship = commandContext.createRelationship(this._model);
|
||||
|
||||
// Finally, focus ...
|
||||
var designer = commandContext._designer;
|
||||
designer.onObjectFocusEvent.attempt(relationship, designer);
|
||||
execute:function (commandContext) {
|
||||
var relationship = commandContext.addRelationship(this._model);
|
||||
relationship.setOnFocus(true);
|
||||
},
|
||||
undoExecute: function(commandContext) {
|
||||
var relationship = commandContext.deleteRelationship(this._model);
|
||||
|
||||
// @Todo: Esto esta mal. Designer toca el mindmap ...
|
||||
// this._mindmap.removeRelationship(this._model);
|
||||
undoExecute:function (commandContext) {
|
||||
var rel = commandContext.findRelationships(this._model.getId());
|
||||
commandContext.deleteRelationship(rel[0]);
|
||||
}
|
||||
});
|
@ -19,15 +19,14 @@
|
||||
mindplot.commands.DeleteCommand = new Class({
|
||||
Extends:mindplot.Command,
|
||||
initialize:function (topicIds, relIds) {
|
||||
$assert($defined(topicIds), 'topicIds can not be null');
|
||||
$assert($defined(relIds), 'topicIds can not be null');
|
||||
|
||||
this.parent();
|
||||
this._relIds = relIds;
|
||||
this._topicIds = topicIds;
|
||||
this._deletedTopicModels = [];
|
||||
this._deletedRelModel = [];
|
||||
this._parentTopicIds = [];
|
||||
this._deletedRelationships = [];
|
||||
this._id = mindplot.Command._nextUUID();
|
||||
},
|
||||
|
||||
execute:function (commandContext) {
|
||||
@ -42,7 +41,7 @@ mindplot.commands.DeleteCommand = new Class({
|
||||
while (relationships.length > 0) {
|
||||
var relationship = relationships[0];
|
||||
|
||||
this._deletedRelationships.push(relationship);
|
||||
this._deletedRelModel.push(relationship);
|
||||
commandContext.deleteRelationship(relationship);
|
||||
}
|
||||
|
||||
@ -65,7 +64,7 @@ mindplot.commands.DeleteCommand = new Class({
|
||||
var rels = commandContext.findRelationships(this._relIds);
|
||||
if (rels.length > 0) {
|
||||
rels.forEach(function (rel) {
|
||||
this._deletedRelationships.push(rel.getModel().clone());
|
||||
this._deletedRelModel.push(rel.getModel().clone());
|
||||
commandContext.deleteRelationship(rel);
|
||||
}.bind(this));
|
||||
}
|
||||
@ -88,13 +87,12 @@ mindplot.commands.DeleteCommand = new Class({
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
this._deletedRelationships.forEach(
|
||||
function (rel) {
|
||||
commandContext.createRelationship(rel);
|
||||
this._deletedRelModel.forEach(function (model) {
|
||||
commandContext.addRelationship(model);
|
||||
}.bind(this));
|
||||
|
||||
this._deletedTopicModels = [];
|
||||
this._parentTopicIds = [];
|
||||
this._deletedRelationships = [];
|
||||
this._deletedRelModel = [];
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user