wisemapping-open-source/mindplot/src/main/javascript/BrixActionDispatcher.js

154 lines
5.3 KiB
JavaScript
Raw Normal View History

/*
* 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.
*/
mindplot.BrixActionDispatcher = new Class({
Extends: mindplot.ActionDispatcher,
2011-08-05 03:12:53 +02:00
initialize: function(commandContext, fireOnChange) {
this.parent(commandContext, fireOnChange);
2011-08-08 02:13:20 +02:00
this._commandContext = commandContext;
},
2011-09-10 06:17:48 +02:00
dragTopic: function(topicId, position, order, parentTopic) {
var framework = this._getFramework();
var node = framework.getTopic(topicId);
// Set node order ...
if (order != null) {
node.setOrder(order);
} else if (position != null) {
// Set position ...
node.setPosition(position);
} else {
$assert("Illegal commnad state exception.");
}
// Finally, connect node ...
if ($defined(this._parentId)) {
var parentNode = topic.findTopics([this._parentId])[0];
node.disconnect();
node.connect(parentNode);
}
},
changeTextToTopic : function(topicsIds, text) {
var framework = this._getFramework();
var topicId;
2011-08-08 02:13:20 +02:00
if (!(topicsIds instanceof Array)) {
topicId = topicsIds;
} else {
topicId = topicsIds[0];
2011-08-08 02:13:20 +02:00
}
2011-09-10 02:53:41 +02:00
var node = framework.getTopic(topicId);
node.setText(text);
2011-08-11 04:11:50 +02:00
},
_getFramework:function () {
return mindplot.collaboration.CollaborationManager.getInstance().getCollaborativeFramework();
},
2011-09-09 07:22:44 +02:00
addTopic : function(nodeModel, parentTopicId, animated) {
var framework = this._getFramework();
2011-09-10 02:53:41 +02:00
var cmindmap = framework.getModel();
2011-09-14 13:51:38 +02:00
var cparent = $defined(parentTopicId) ? framework.getTopic(parentTopicId) : cmindmap.getCentralTopic();
2011-09-10 02:53:41 +02:00
var cnode = cmindmap.createNode(nodeModel.getType(), nodeModel.getId());
2011-09-14 13:51:38 +02:00
nodeModel.copyTo(cnode);
2011-09-09 07:22:44 +02:00
2011-09-14 13:51:38 +02:00
cnode.connectTo(cparent);
},
changeFontSizeToTopic : function(topicsIds, size) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontSize(size, true);
}.bind(this));
},
changeFontColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontColor(color, true);
}.bind(this));
},
changeFontFamilyToTopic : function(topicsIds, family) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setFontFamily(family, true);
}.bind(this));
},
changeFontStyleToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
var style = ( topic.getFontStyle() == "italic") ? "normal" : "italic";
topic.setFontStyle(style, true);
}.bind(this));
},
2011-09-10 02:53:41 +02:00
changeShapeTypeToTopic : function(topicsIds, shapeType) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setShapeType(shapeType);
}.bind(this))
},
changeFontWeightToTopic : function(topicsIds) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
var weight = (topic.getFontWeight() == "bold") ? "normal" : "bold";
topic.setFontWeight(weight, true);
}.bind(this));
},
changeBackgroundColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setBackgroundColor(color, true);
}.bind(this));
},
changeBorderColorToTopic : function(topicsIds, color) {
topicsIds.forEach(function(topicId) {
var framework = this._getFramework();
var topic = framework.getTopic(topicId);
topic.setBorderColor(color);
}.bind(this));
},
deleteTopics : function(topicsIds, relIds) {
$assert(topicsIds, "topicsIds can not be null");
var framework = this._getFramework();
var mindmap = framework.getModel();
2011-09-14 13:51:38 +02:00
topicsIds.forEach(function(topicId) {
var topic = framework.getTopic(topicId);
topic.deleteNode();
});
}
});