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

301 lines
10 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.StandaloneActionDispatcher = new Class({
Extends:mindplot.ActionDispatcher,
initialize:function (commandContext) {
2011-08-05 03:12:53 +02:00
this.parent(commandContext);
2011-08-05 06:06:56 +02:00
this._actionRunner = new mindplot.DesignerActionRunner(commandContext, this);
},
2012-07-08 23:41:35 +02:00
addTopics:function (models, parentTopicsId) {
var command = new mindplot.commands.AddTopicCommand(models, parentTopicsId);
this.execute(command);
},
2012-07-07 06:33:34 +02:00
addRelationship:function (model) {
2011-10-09 22:59:16 +02:00
var command = new mindplot.commands.AddRelationshipCommand(model);
this.execute(command);
},
deleteEntities:function (topicsIds, relIds) {
2011-11-14 01:18:34 +01:00
var command = new mindplot.commands.DeleteCommand(topicsIds, relIds);
this.execute(command);
},
dragTopic:function (topicId, position, order, parentTopic) {
var command = new mindplot.commands.DragTopicCommand(topicId, position, order, parentTopic);
this.execute(command);
},
moveTopic:function (topicId, position) {
2012-01-18 05:26:39 +01:00
$assert($defined(topicId), "topicsId can not be null");
$assert($defined(position), "position can not be null");
var commandFunc = function (topic, value) {
2012-01-18 05:26:39 +01:00
var result = topic.getPosition();
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {node:topic.getModel(), position:value});
2012-01-18 05:26:39 +01:00
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicId, position);
2012-01-18 05:32:55 +01:00
this.execute(command);
2012-01-18 05:26:39 +01:00
},
2012-01-18 05:32:55 +01:00
moveControlPoint:function (ctrlPoint, point) {
var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point);
this.execute(command);
},
changeFontStyleToTopic:function (topicsIds) {
var commandFunc = function (topic) {
var result = topic.getFontStyle();
var style = (result == "italic") ? "normal" : "italic";
topic.setFontStyle(style, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds);
2012-01-18 05:32:55 +01:00
this.execute(command);
},
changeTextToTopic:function (topicsIds, text) {
2011-09-10 02:53:41 +02:00
$assert($defined(topicsIds), "topicsIds can not be null");
2011-08-05 03:12:53 +02:00
var commandFunc = function (topic, value) {
2011-08-05 03:12:53 +02:00
var result = topic.getText();
topic.setText(value);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, text);
2012-01-18 05:32:55 +01:00
this.execute(command);
2011-08-05 03:12:53 +02:00
},
changeFontFamilyToTopic:function (topicIds, fontFamily) {
$assert(topicIds, "topicIds can not be null");
$assert(fontFamily, "fontFamily can not be null");
var commandFunc = function (topic, fontFamily) {
var result = topic.getFontFamily();
topic.setFontFamily(fontFamily, true);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicIds, fontFamily);
this.execute(command);
},
changeFontColorToTopic:function (topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "color can not be null");
var commandFunc = function (topic, color) {
var result = topic.getFontColor();
topic.setFontColor(color, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discardDuplicated = "fontColorCommandId";
this.execute(command);
},
changeBackgroundColorToTopic:function (topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "color can not be null");
var commandFunc = function (topic, color) {
var result = topic.getBackgroundColor();
topic.setBackgroundColor(color);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discardDuplicated = "backColor";
this.execute(command);
},
changeBorderColorToTopic:function (topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "topicIds can not be null");
var commandFunc = function (topic, color) {
var result = topic.getBorderColor();
topic.setBorderColor(color);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discardDuplicated = "borderColorCommandId";
this.execute(command);
},
changeFontSizeToTopic:function (topicsIds, size) {
$assert(topicsIds, "topicIds can not be null");
$assert(size, "size can not be null");
var commandFunc = function (topic, size) {
var result = topic.getFontSize();
topic.setFontSize(size, true);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, size);
this.execute(command);
},
changeShapeTypeToTopic:function (topicsIds, shapeType) {
$assert(topicsIds, "topicsIds can not be null");
$assert(shapeType, "shapeType can not be null");
var commandFunc = function (topic, shapeType) {
var result = topic.getShapeType();
topic.setShapeType(shapeType, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, shapeType);
this.execute(command);
},
changeFontWeightToTopic:function (topicsIds) {
$assert(topicsIds, "topicsIds can not be null");
var commandFunc = function (topic) {
var result = topic.getFontWeight();
var weight = (result == "bold") ? "normal" : "bold";
topic.setFontWeight(weight, true);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds);
this.execute(command);
},
shrinkBranch:function (topicsIds, collapse) {
2011-08-05 06:34:51 +02:00
$assert(topicsIds, "topicsIds can not be null");
var commandFunc = function (topic, isShrink) {
topic.setChildrenShrunken(isShrink);
2011-08-05 06:34:51 +02:00
return !isShrink;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, collapse);
2012-01-17 04:26:29 +01:00
this.execute(command, false);
2011-08-05 06:34:51 +02:00
},
addFeatureToTopic:function (topicId, featureType, attributes) {
var command = new mindplot.commands.AddFeatureToTopicCommand(topicId, featureType, attributes);
this.execute(command);
},
changeFeatureToTopic:function (topicId, featureId, attributes) {
var command = new mindplot.commands.ChangeFeatureToTopicCommand(topicId, featureId, attributes);
this.execute(command);
},
removeFeatureFromTopic:function (topicId, featureId) {
var command = new mindplot.commands.RemoveFeatureFromTopicCommand(topicId, featureId);
this.execute(command);
},
execute:function (command) {
this._actionRunner.execute(command);
}
});
2011-08-05 03:12:53 +02:00
mindplot.CommandContext = new Class({
initialize:function (designer) {
2011-08-05 03:12:53 +02:00
$assert(designer, "designer can not be null");
this._designer = designer;
},
findTopics:function (topicsIds) {
2011-09-10 02:53:41 +02:00
$assert($defined(topicsIds), "topicsIds can not be null");
2011-08-05 03:12:53 +02:00
if (!(topicsIds instanceof Array)) {
topicsIds = [topicsIds];
}
2011-08-30 01:32:12 +02:00
var designerTopics = this._designer.getModel().getTopics();
return designerTopics.filter(function (topic) {
2011-08-30 01:32:12 +02:00
return topicsIds.contains(topic.getId());
2011-08-05 03:12:53 +02:00
});
},
deleteTopic:function (topic) {
this._designer._removeTopic(topic);
2011-08-05 03:12:53 +02:00
},
createTopic:function (model, isVisible) {
2011-08-05 03:12:53 +02:00
$assert(model, "model can not be null");
2012-03-08 00:35:06 +01:00
return this._designer._nodeModelToNodeGraph(model, isVisible);
2011-08-05 03:12:53 +02:00
},
createModel:function () {
2011-08-05 03:12:53 +02:00
var mindmap = this._designer.getMindmap();
return mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE);
},
connect:function (childTopic, parentTopic, isVisible) {
2011-08-05 03:12:53 +02:00
childTopic.connectTo(parentTopic, this._designer._workspace, isVisible);
},
2011-08-05 03:12:53 +02:00
disconnect:function (topic) {
2011-08-05 03:12:53 +02:00
topic.disconnect(this._designer._workspace);
},
2012-07-07 06:33:34 +02:00
addRelationship:function (model) {
2011-08-05 03:12:53 +02:00
$assert(model, "model cannot be null");
2012-07-07 06:33:34 +02:00
return this._designer._addRelationship(model);
2011-08-05 03:12:53 +02:00
},
deleteRelationship:function (relationship) {
this._designer._deleteRelationship(relationship);
2011-08-05 03:12:53 +02:00
},
findRelationships:function (relIds) {
$assert($defined(relIds), "relId can not be null");
if (!(relIds instanceof Array)) {
relIds = [relIds];
}
var designerRel = this._designer.getModel().getRelationships();
return designerRel.filter(function (rel) {
return relIds.contains(rel.getId());
});
2012-07-09 23:52:59 +02:00
},
moveTopic:function (topic, position) {
$assert(topic, "topic cannot be null");
$assert(position, "position cannot be null");
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {node:topic.getModel(), position:position});
2011-09-02 07:31:03 +02:00
}
2011-08-05 03:12:53 +02:00
});