- Features are not created inside topic. This helps on revert action.
parent
dbf8b0e28c
commit
dfe07e2da0
|
@ -274,19 +274,16 @@ mindplot.Topic = new Class({
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
addFeature:function (type, attributes, featureId) {
|
addFeature:function (featureModel) {
|
||||||
var iconGroup = this.getOrBuildIconGroup();
|
var iconGroup = this.getOrBuildIconGroup();
|
||||||
this.closeEditors();
|
this.closeEditors();
|
||||||
|
|
||||||
var model = this.getModel();
|
|
||||||
|
|
||||||
// Update model ...
|
// Update model ...
|
||||||
var feature = model.createFeature(type, attributes, featureId);
|
var model = this.getModel();
|
||||||
model.addFeature(feature);
|
model.addFeature(featureModel);
|
||||||
|
|
||||||
|
var result = mindplot.TopicFeature.createIcon(this, featureModel, this.isReadOnly());
|
||||||
var result = mindplot.TopicFeature.createIcon(this, feature, this.isReadOnly());
|
iconGroup.addIcon(result, featureModel.getType() == mindplot.TopicFeature.Icon.id && !this.isReadOnly());
|
||||||
iconGroup.addIcon(result, type == mindplot.TopicFeature.Icon.id && !this.isReadOnly());
|
|
||||||
|
|
||||||
this._adjustShapes();
|
this._adjustShapes();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -41,14 +41,14 @@ mindplot.TopicFeature = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
createModel:function (type, attributes, id) {
|
createModel:function (type, attributes) {
|
||||||
$assert(type, 'type can not be null');
|
$assert(type, 'type can not be null');
|
||||||
$assert(attributes, 'attributes can not be null');
|
$assert(attributes, 'attributes can not be null');
|
||||||
|
|
||||||
var model = mindplot.TopicFeature._featuresMetadataById.filter(function (elem) {
|
var model = mindplot.TopicFeature._featuresMetadataById.filter(function (elem) {
|
||||||
return elem.id == type;
|
return elem.id == type;
|
||||||
})[0].model;
|
})[0].model;
|
||||||
return new model(attributes, id);
|
return new model(attributes);
|
||||||
},
|
},
|
||||||
|
|
||||||
createIcon:function (topic, model, readOnly) {
|
createIcon:function (topic, model, readOnly) {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
mindplot.commands.AddFeatureToTopicCommand = new Class({
|
mindplot.commands.AddFeatureToTopicCommand = new Class({
|
||||||
Extends:mindplot.Command,
|
Extends:mindplot.Command,
|
||||||
initialize: function(topicId, featureType, attributes) {
|
initialize:function (topicId, featureType, attributes) {
|
||||||
|
|
||||||
$assert($defined(topicId), 'topicId can not be null');
|
$assert($defined(topicId), 'topicId can not be null');
|
||||||
$assert(featureType, 'featureType can not be null');
|
$assert(featureType, 'featureType can not be null');
|
||||||
|
@ -28,15 +28,21 @@ mindplot.commands.AddFeatureToTopicCommand = new Class({
|
||||||
this._topicId = topicId;
|
this._topicId = topicId;
|
||||||
this._featureType = featureType;
|
this._featureType = featureType;
|
||||||
this._attributes = attributes;
|
this._attributes = attributes;
|
||||||
|
this._featureModel = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
execute: function(commandContext) {
|
execute:function (commandContext) {
|
||||||
var topic = commandContext.findTopics(this._topicId)[0];
|
var topic = commandContext.findTopics(this._topicId)[0];
|
||||||
var icon = topic.addFeature(this._featureType, this._attributes);
|
|
||||||
this._featureModel = icon.getModel();
|
// Feature must be created only one time.
|
||||||
|
if (!this._featureModel) {
|
||||||
|
var model = topic.getModel();
|
||||||
|
this._featureModel = model.createFeature(this._featureType, this._attributes);
|
||||||
|
}
|
||||||
|
topic.addFeature(this._featureModel);
|
||||||
},
|
},
|
||||||
|
|
||||||
undoExecute: function(commandContext) {
|
undoExecute:function (commandContext) {
|
||||||
var topic = commandContext.findTopics(this._topicId)[0];
|
var topic = commandContext.findTopics(this._topicId)[0];
|
||||||
topic.removeFeature(this._featureModel);
|
topic.removeFeature(this._featureModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ mindplot.commands.RemoveFeatureFromTopicCommand = new Class({
|
||||||
|
|
||||||
undoExecute:function (commandContext) {
|
undoExecute:function (commandContext) {
|
||||||
var topic = commandContext.findTopics(this._topicId)[0];
|
var topic = commandContext.findTopics(this._topicId)[0];
|
||||||
var feature = this._oldFeature;
|
topic.addFeature(this._oldFeature);
|
||||||
topic.addFeature(feature.getType(), feature.getAttributes(), this._featureId);
|
|
||||||
this._oldFeature = null;
|
this._oldFeature = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -28,9 +28,9 @@ mindplot.model.FeatureModel = new Class({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize:function (type, id) {
|
initialize:function (type) {
|
||||||
$assert(type, 'type can not be null');
|
$assert(type, 'type can not be null');
|
||||||
this._id = $defined(id) ? id : mindplot.model.FeatureModel._nextUUID();
|
this._id = mindplot.model.FeatureModel._nextUUID();
|
||||||
|
|
||||||
this._type = type;
|
this._type = type;
|
||||||
this._attributes = {};
|
this._attributes = {};
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
mindplot.model.IconModel = new Class({
|
mindplot.model.IconModel = new Class({
|
||||||
Extends:mindplot.model.FeatureModel,
|
Extends:mindplot.model.FeatureModel,
|
||||||
initialize:function (attributes, id) {
|
initialize:function (attributes) {
|
||||||
this.parent(mindplot.model.IconModel.FEATURE_TYPE, id);
|
this.parent(mindplot.model.IconModel.FEATURE_TYPE);
|
||||||
this.setIconType(attributes.id);
|
this.setIconType(attributes.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
mindplot.model.LinkModel = new Class({
|
mindplot.model.LinkModel = new Class({
|
||||||
Extends:mindplot.model.FeatureModel,
|
Extends:mindplot.model.FeatureModel,
|
||||||
initialize:function (attributes,id) {
|
initialize:function (attributes) {
|
||||||
this.parent(mindplot.model.LinkModel.FEATURE_TYPE,id);
|
this.parent(mindplot.model.LinkModel.FEATURE_TYPE);
|
||||||
this.setUrl(attributes.url);
|
this.setUrl(attributes.url);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ mindplot.model.NodeModel = new Class({
|
||||||
this._feature = [];
|
this._feature = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
createFeature:function (type, attributes, featureId) {
|
createFeature:function (type, attributes) {
|
||||||
return mindplot.TopicFeature.createModel(type, attributes, featureId);
|
return mindplot.TopicFeature.createModel(type, attributes);
|
||||||
},
|
},
|
||||||
|
|
||||||
addFeature:function (feature) {
|
addFeature:function (feature) {
|
||||||
|
@ -47,9 +47,12 @@ mindplot.model.NodeModel = new Class({
|
||||||
|
|
||||||
removeFeature:function (feature) {
|
removeFeature:function (feature) {
|
||||||
$assert(feature, 'feature can not be null');
|
$assert(feature, 'feature can not be null');
|
||||||
|
var size = this._feature.length;
|
||||||
this._feature = this._feature.filter(function (f) {
|
this._feature = this._feature.filter(function (f) {
|
||||||
return feature.getId() != f.getId();
|
return feature.getId() != f.getId();
|
||||||
});
|
});
|
||||||
|
$assert(size - 1 == this._feature.length, 'Could not be removed ...');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
findFeatureByType:function (type) {
|
findFeatureByType:function (type) {
|
||||||
|
@ -61,9 +64,11 @@ mindplot.model.NodeModel = new Class({
|
||||||
|
|
||||||
findFeatureById:function (id) {
|
findFeatureById:function (id) {
|
||||||
$assert($defined(id), 'id can not be null');
|
$assert($defined(id), 'id can not be null');
|
||||||
return this._feature.filter(function (feature) {
|
var result = this._feature.filter(function (feature) {
|
||||||
return feature.getId() == id;
|
return feature.getId() == id;
|
||||||
})[0];
|
});
|
||||||
|
$assert(result.length == 1, "Feature could not be found:" + id);
|
||||||
|
return result[0]
|
||||||
},
|
},
|
||||||
|
|
||||||
getPropertiesKeys:function () {
|
getPropertiesKeys:function () {
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
mindplot.model.NoteModel = new Class({
|
mindplot.model.NoteModel = new Class({
|
||||||
Extends:mindplot.model.FeatureModel,
|
Extends:mindplot.model.FeatureModel,
|
||||||
initialize:function (attributes, id) {
|
initialize:function (attributes) {
|
||||||
this.parent(mindplot.model.NoteModel.FEATURE_TYPE, id);
|
this.parent(mindplot.model.NoteModel.FEATURE_TYPE);
|
||||||
var noteText = attributes.text ? attributes.text : " ";
|
var noteText = attributes.text ? attributes.text : " ";
|
||||||
this.setText(noteText);
|
this.setText(noteText);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue