2009-06-07 20:59:43 +02:00
|
|
|
/*
|
2011-07-30 23:55:32 +02:00
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
mindplot.commands.DeleteCommand = new Class({
|
2011-07-26 20:07:53 +02:00
|
|
|
Extends:mindplot.Command,
|
2012-07-07 02:21:56 +02:00
|
|
|
initialize:function (topicIds, relIds) {
|
2011-11-30 04:56:21 +01:00
|
|
|
$assert($defined(topicIds), 'topicIds can not be null');
|
|
|
|
|
2012-02-27 23:25:14 +01:00
|
|
|
this.parent();
|
2011-09-06 06:03:27 +02:00
|
|
|
this._relIds = relIds;
|
|
|
|
this._topicIds = topicIds;
|
2009-06-07 20:59:43 +02:00
|
|
|
this._deletedTopicModels = [];
|
|
|
|
this._parentTopicIds = [];
|
2010-12-13 15:07:20 +01:00
|
|
|
this._deletedRelationships = [];
|
2009-06-07 20:59:43 +02:00
|
|
|
this._id = mindplot.Command._nextUUID();
|
|
|
|
},
|
2011-08-25 04:41:39 +02:00
|
|
|
|
2012-07-07 02:21:56 +02:00
|
|
|
execute:function (commandContext) {
|
2011-09-06 06:03:27 +02:00
|
|
|
var topics = commandContext.findTopics(this._topicIds);
|
2011-07-30 23:55:32 +02:00
|
|
|
if (topics.length > 0) {
|
|
|
|
topics.forEach(
|
2012-07-07 02:21:56 +02:00
|
|
|
function (topic, index) {
|
2011-11-29 04:38:11 +01:00
|
|
|
var model = topic.getModel();
|
2010-12-13 15:07:20 +01:00
|
|
|
|
2011-11-29 04:38:11 +01:00
|
|
|
// Delete relationships
|
2010-12-13 15:07:20 +01:00
|
|
|
var relationships = topic.getRelationships();
|
2011-07-30 23:55:32 +02:00
|
|
|
while (relationships.length > 0) {
|
2010-12-13 15:07:20 +01:00
|
|
|
var relationship = relationships[0];
|
2012-07-07 02:21:56 +02:00
|
|
|
|
|
|
|
this._deletedRelationships.push(relationship);
|
|
|
|
commandContext.deleteRelationship(relationship);
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
|
|
|
|
2009-06-07 20:59:43 +02:00
|
|
|
this._deletedTopicModels.push(model);
|
|
|
|
|
|
|
|
// Is connected?.
|
|
|
|
var outTopic = topic.getOutgoingConnectedTopic();
|
|
|
|
var outTopicId = null;
|
2011-07-30 23:55:32 +02:00
|
|
|
if (outTopic != null) {
|
2009-06-07 20:59:43 +02:00
|
|
|
outTopicId = outTopic.getId();
|
|
|
|
}
|
|
|
|
this._parentTopicIds.push(outTopicId);
|
|
|
|
|
|
|
|
// Finally, delete the topic from the workspace...
|
|
|
|
commandContext.deleteTopic(topic);
|
|
|
|
|
|
|
|
}.bind(this)
|
2011-07-30 23:55:32 +02:00
|
|
|
);
|
|
|
|
}
|
2012-07-07 02:21:56 +02:00
|
|
|
var rels = commandContext.findRelationships(this._relIds);
|
|
|
|
if (rels.length > 0) {
|
|
|
|
rels.forEach(function (rel) {
|
|
|
|
this._deletedRelationships.push(rel.getModel().clone());
|
|
|
|
commandContext.deleteRelationship(rel);
|
2010-12-22 23:34:24 +01:00
|
|
|
}.bind(this));
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
},
|
2011-11-29 04:38:11 +01:00
|
|
|
|
2012-07-07 02:21:56 +02:00
|
|
|
undoExecute:function (commandContext) {
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-09-06 06:03:27 +02:00
|
|
|
var topics = commandContext.findTopics(this._topicIds);
|
2009-06-07 20:59:43 +02:00
|
|
|
var parent = commandContext.findTopics(this._parentTopicIds);
|
|
|
|
|
|
|
|
this._deletedTopicModels.forEach(
|
2012-07-07 02:21:56 +02:00
|
|
|
function (model, index) {
|
2011-07-30 23:55:32 +02:00
|
|
|
var topic = commandContext.createTopic(model);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-30 23:55:32 +02:00
|
|
|
// Was the topic connected?
|
|
|
|
var parentTopic = parent[index];
|
|
|
|
if (parentTopic != null) {
|
|
|
|
commandContext.connect(topic, parentTopic);
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-30 23:55:32 +02:00
|
|
|
}.bind(this)
|
|
|
|
);
|
2010-12-13 15:07:20 +01:00
|
|
|
this._deletedRelationships.forEach(
|
2012-07-07 02:21:56 +02:00
|
|
|
function (rel) {
|
|
|
|
commandContext.createRelationship(rel);
|
2011-07-30 23:55:32 +02:00
|
|
|
}.bind(this));
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
this._deletedTopicModels = [];
|
|
|
|
this._parentTopicIds = [];
|
2010-12-13 15:07:20 +01:00
|
|
|
this._deletedRelationships = [];
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
});
|