84 lines
2.7 KiB
JavaScript
Raw Normal View History

2009-06-07 18:59:43 +00:00
/*
2012-10-04 20:48:01 -03:00
* Copyright [2012] [wisemapping]
2011-07-30 18:55:32 -03:00
*
* 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 18:59:43 +00:00
2011-07-30 18:55:32 -03:00
mindplot.commands.DragTopicCommand = new Class({
2011-07-26 15:07:53 -03:00
Extends:mindplot.Command,
2012-09-27 08:12:03 -03:00
initialize:function (topicId, position, order, parentTopic) {
$assert(topicId, "topicId must be defined");
2012-09-27 08:12:03 -03:00
this._topicsId = topicId;
if ($defined(parentTopic))
this._parentId = parentTopic.getId();
this.parent();
this._position = position;
this._order = order;
2009-06-07 18:59:43 +00:00
},
2011-09-08 10:03:42 -03:00
2012-07-09 18:52:59 -03:00
execute:function (commandContext) {
2009-06-07 18:59:43 +00:00
2012-09-27 08:12:03 -03:00
var topic = commandContext.findTopics(this._topicsId)[0];
topic.setVisibility(false);
2009-06-07 18:59:43 +00:00
// Save old position ...
var origParentTopic = topic.getOutgoingConnectedTopic();
2011-11-13 21:18:34 -03:00
2011-07-30 18:55:32 -03:00
// In this case, topics are positioned using order ...
2012-07-09 18:52:59 -03:00
var origOrder = topic.getOrder();
var origPosition = topic.getPosition();
2009-06-07 18:59:43 +00:00
// Disconnect topic ..
2011-11-13 21:18:34 -03:00
if ($defined(origParentTopic) && origParentTopic != this._parentId) {
2009-06-07 18:59:43 +00:00
commandContext.disconnect(topic);
}
// Set topic order ...
2011-07-30 18:55:32 -03:00
if (this._order != null) {
topic.setOrder(this._order);
2011-07-30 18:55:32 -03:00
} else if (this._position != null) {
2012-07-09 18:52:59 -03:00
commandContext.moveTopic(topic, this._position);
2011-07-30 18:55:32 -03:00
} else {
$assert("Illegal command state exception.");
2009-06-07 18:59:43 +00:00
}
// Finally, connect topic ...
2011-11-13 21:18:34 -03:00
if (origParentTopic != this._parentId) {
if ($defined(this._parentId)) {
2012-09-27 08:12:03 -03:00
var parentTopic = commandContext.findTopics(this._parentId)[0];
2011-11-13 21:18:34 -03:00
commandContext.connect(topic, parentTopic);
}
// Backup old parent id ...
this._parentId = null;
if ($defined(origParentTopic)) {
this._parentId = origParentTopic.getId();
}
2009-06-07 18:59:43 +00:00
}
topic.setVisibility(true);
2009-06-07 18:59:43 +00:00
2011-11-13 21:18:34 -03:00
// Store for undo ...
2011-10-27 21:18:49 -03:00
this._order = origOrder;
this._position = origPosition;
2009-06-07 18:59:43 +00:00
},
2011-10-09 17:59:16 -03:00
2012-07-09 18:52:59 -03:00
undoExecute:function (commandContext) {
2009-06-07 18:59:43 +00:00
this.execute(commandContext);
}
});