- Features are not created inside topic. This helps on revert action.

This commit is contained in:
Paulo Gustavo Veiga 2012-09-28 23:14:37 -03:00
parent dbf8b0e28c
commit dfe07e2da0
9 changed files with 36 additions and 29 deletions

View File

@ -274,19 +274,16 @@ mindplot.Topic = new Class({
return result;
},
addFeature:function (type, attributes, featureId) {
addFeature:function (featureModel) {
var iconGroup = this.getOrBuildIconGroup();
this.closeEditors();
var model = this.getModel();
// Update model ...
var feature = model.createFeature(type, attributes, featureId);
model.addFeature(feature);
var model = this.getModel();
model.addFeature(featureModel);
var result = mindplot.TopicFeature.createIcon(this, feature, this.isReadOnly());
iconGroup.addIcon(result, type == mindplot.TopicFeature.Icon.id && !this.isReadOnly());
var result = mindplot.TopicFeature.createIcon(this, featureModel, this.isReadOnly());
iconGroup.addIcon(result, featureModel.getType() == mindplot.TopicFeature.Icon.id && !this.isReadOnly());
this._adjustShapes();
return result;

View File

@ -41,14 +41,14 @@ mindplot.TopicFeature = {
});
},
createModel:function (type, attributes, id) {
createModel:function (type, attributes) {
$assert(type, 'type can not be null');
$assert(attributes, 'attributes can not be null');
var model = mindplot.TopicFeature._featuresMetadataById.filter(function (elem) {
return elem.id == type;
})[0].model;
return new model(attributes, id);
return new model(attributes);
},
createIcon:function (topic, model, readOnly) {

View File

@ -18,7 +18,7 @@
mindplot.commands.AddFeatureToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, featureType, attributes) {
initialize:function (topicId, featureType, attributes) {
$assert($defined(topicId), 'topicId can not be null');
$assert(featureType, 'featureType can not be null');
@ -28,15 +28,21 @@ mindplot.commands.AddFeatureToTopicCommand = new Class({
this._topicId = topicId;
this._featureType = featureType;
this._attributes = attributes;
this._featureModel = null;
},
execute: function(commandContext) {
execute:function (commandContext) {
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];
topic.removeFeature(this._featureModel);
}

View File

@ -37,8 +37,7 @@ mindplot.commands.RemoveFeatureFromTopicCommand = new Class({
undoExecute:function (commandContext) {
var topic = commandContext.findTopics(this._topicId)[0];
var feature = this._oldFeature;
topic.addFeature(feature.getType(), feature.getAttributes(), this._featureId);
topic.addFeature(this._oldFeature);
this._oldFeature = null;
}
});

View File

@ -28,9 +28,9 @@ mindplot.model.FeatureModel = new Class({
}
},
initialize:function (type, id) {
initialize:function (type) {
$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._attributes = {};

View File

@ -18,8 +18,8 @@
mindplot.model.IconModel = new Class({
Extends:mindplot.model.FeatureModel,
initialize:function (attributes, id) {
this.parent(mindplot.model.IconModel.FEATURE_TYPE, id);
initialize:function (attributes) {
this.parent(mindplot.model.IconModel.FEATURE_TYPE);
this.setIconType(attributes.id);
},

View File

@ -18,8 +18,8 @@
mindplot.model.LinkModel = new Class({
Extends:mindplot.model.FeatureModel,
initialize:function (attributes,id) {
this.parent(mindplot.model.LinkModel.FEATURE_TYPE,id);
initialize:function (attributes) {
this.parent(mindplot.model.LinkModel.FEATURE_TYPE);
this.setUrl(attributes.url);
},

View File

@ -32,8 +32,8 @@ mindplot.model.NodeModel = new Class({
this._feature = [];
},
createFeature:function (type, attributes, featureId) {
return mindplot.TopicFeature.createModel(type, attributes, featureId);
createFeature:function (type, attributes) {
return mindplot.TopicFeature.createModel(type, attributes);
},
addFeature:function (feature) {
@ -47,9 +47,12 @@ mindplot.model.NodeModel = new Class({
removeFeature:function (feature) {
$assert(feature, 'feature can not be null');
var size = this._feature.length;
this._feature = this._feature.filter(function (f) {
return feature.getId() != f.getId();
});
$assert(size - 1 == this._feature.length, 'Could not be removed ...');
},
findFeatureByType:function (type) {
@ -61,9 +64,11 @@ mindplot.model.NodeModel = new Class({
findFeatureById:function (id) {
$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;
})[0];
});
$assert(result.length == 1, "Feature could not be found:" + id);
return result[0]
},
getPropertiesKeys:function () {

View File

@ -18,8 +18,8 @@
mindplot.model.NoteModel = new Class({
Extends:mindplot.model.FeatureModel,
initialize:function (attributes, id) {
this.parent(mindplot.model.NoteModel.FEATURE_TYPE, id);
initialize:function (attributes) {
this.parent(mindplot.model.NoteModel.FEATURE_TYPE);
var noteText = attributes.text ? attributes.text : " ";
this.setText(noteText);
},