wisemapping-open-source/mindplot/src/main/javascript/commands/AddTopicCommand.js

70 lines
2.6 KiB
JavaScript
Raw Normal View History

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-07-26 20:07:53 +02:00
mindplot.commands.AddTopicCommand = new Class(
2009-06-07 20:59:43 +02:00
{
2011-07-30 23:55:32 +02:00
Extends:mindplot.Command,
initialize: function(model, parentTopicId, animated) {
$assert(model, 'Model can not be null');
this.parent();
2011-07-30 23:55:32 +02:00
this._model = model;
this._parentId = parentTopicId;
this._id = mindplot.Command._nextUUID();
this._animated = $defined(animated) ? animated : false;
},
2011-07-30 23:55:32 +02:00
execute: function(commandContext) {
// Add a new topic ...
var topic = commandContext.createTopic(this._model, !this._animated);
2009-06-07 20:59:43 +02:00
2011-07-30 23:55:32 +02:00
// Connect to topic ...
if ($defined(this._parentId)) {
var parentTopic = commandContext.findTopics(this._parentId)[0];
commandContext.connect(topic, parentTopic, !this._animated);
}
2009-06-07 20:59:43 +02:00
2011-07-30 23:55:32 +02:00
var doneFn = function() {
// Finally, focus ...
var designer = commandContext._designer;
2011-08-05 06:06:56 +02:00
designer.onObjectFocusEvent(topic);
2011-07-30 23:55:32 +02:00
topic.setOnFocus(true);
};
if (this._animated) {
core.Utils.setVisibilityAnimated([topic,topic.getOutgoingLine()], true, doneFn);
2011-08-30 01:10:05 +02:00
} else {
2011-07-30 23:55:32 +02:00
doneFn.attempt();
2011-08-30 01:10:05 +02:00
}
2011-07-30 23:55:32 +02:00
},
2011-07-30 23:55:32 +02:00
undoExecute: function(commandContext) {
// Finally, delete the topic from the workspace ...
var topicId = this._model.getId();
var topic = commandContext.findTopics(topicId)[0];
var doneFn = function() {
commandContext.deleteTopic(topic);
};
if (this._animated) {
core.Utils.setVisibilityAnimated([topic,topic.getOutgoingLine()], false, doneFn);
}
else
doneFn.attempt();
}
2011-07-30 23:55:32 +02:00
});