959 lines
34 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-27 14:53: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.
*/
2011-10-04 01:16:29 -03:00
mindplot.Designer = new Class({
2014-03-15 03:55:42 -03:00
Extends: mindplot.Events,
2012-07-01 17:21:02 -03:00
initialize:function (options, divElement) {
2012-02-01 20:31:40 -03:00
$assert(options, "options must be defined");
$assert(options.zoom, "zoom must be defined");
2014-10-07 01:16:56 -03:00
$assert(options.size, "size must be defined");
2011-07-27 14:53:32 -03:00
$assert(divElement, "divElement must be defined");
2012-07-01 17:21:02 -03:00
// Set up i18n location ...
mindplot.Messages.init(options.locale);
2012-07-01 17:21:02 -03:00
2012-02-01 20:31:40 -03:00
this._options = options;
2012-02-03 21:21:29 -03:00
// Set full div elem render area ...
2014-03-04 22:48:31 -03:00
divElement.css(options.size);
2012-02-03 21:21:29 -03:00
// Dispatcher manager ...
2011-08-04 22:12:53 -03:00
var commandContext = new mindplot.CommandContext(this);
this._actionDispatcher = new mindplot.StandaloneActionDispatcher(commandContext);
var me = this;
2012-07-01 17:21:02 -03:00
this._actionDispatcher.addEvent("modelUpdate", function (event) {
me.fireEvent("modelUpdate", event);
});
2011-08-04 22:12:53 -03:00
mindplot.ActionDispatcher.setInstance(this._actionDispatcher);
2012-02-01 20:31:40 -03:00
this._model = new mindplot.DesignerModel(options);
2011-07-27 14:53:32 -03:00
// Init Screen manager..
var screenManager = new mindplot.ScreenManager(divElement);
this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom());
2012-01-30 20:17:47 -03:00
// Init layout manager ...
this._eventBussDispatcher = new mindplot.layout.EventBusDispatcher(this.getModel());
2011-07-27 14:53:32 -03:00
// Register events
2012-02-01 20:31:40 -03:00
if (!this.isReadOnly()) {
// Register mouse events ...
this._registerMouseEvents();
// Register keyboard events ...
mindplot.DesignerKeyboard.register(this);
2012-01-30 20:17:47 -03:00
this._dragManager = this._buildDragManager(this._workspace);
}
this._registerWheelEvents();
2011-10-09 17:59:16 -03:00
this._relPivot = new mindplot.RelationshipPivot(this._workspace, this);
2012-02-03 21:21:29 -03:00
// Set editor working area ...
this.setViewPort(options.viewPort);
mindplot.TopicEventDispatcher.configure(this.isReadOnly());
2012-07-08 18:41:35 -03:00
this._clipboard = [];
},
/**
* Deactivates the keyboard events so you can enter text into forms
*/
2012-07-01 17:21:02 -03:00
deactivateKeyboard:function () {
mindplot.DesignerKeyboard.getInstance().deactivate();
this.deselectAll();
},
_registerWheelEvents:function () {
2012-09-18 20:56:51 -03:00
var workspace = this._workspace;
2014-05-13 02:22:42 -03:00
var me = this;
// Zoom In and Zoom Out must active event
2014-05-13 02:22:42 -03:00
$(document).on('mousewheel', function (event) {
// Change mousewheel handling so we let the default
2014-05-13 02:22:42 -03:00
// event happen if we are outside the container. -> FIXME: it still happening?
/*var coords = screenManager.getContainer().getCoordinates();
var isOutsideContainer = event.client.y < coords.top ||
event.client.y > coords.bottom ||
event.client.x < coords.left ||
event.client.x > coords.right;
if (!isOutsideContainer) {
if (event.wheel > 0) {
this.zoomIn(1.05);
}
else {
this.zoomOut(1.05);
}
event.preventDefault();
2014-05-13 02:22:42 -03:00
}*/
if (event.deltaY > 0) {
me.zoomIn(1.05);
}
2014-05-13 02:22:42 -03:00
else {
me.zoomOut(1.05);
}
event.preventDefault();
});
},
/**
* Activates the keyboard events so you can enter text into forms
*/
2012-07-01 17:21:02 -03:00
activateKeyboard:function () {
mindplot.DesignerKeyboard.getInstance().activate();
},
2012-07-01 17:21:02 -03:00
addEvent:function (type, listener) {
if (type == mindplot.TopicEvent.EDIT || type == mindplot.TopicEvent.CLICK) {
var editor = mindplot.TopicEventDispatcher.getInstance();
editor.addEvent(type, listener);
} else {
this.parent(type, listener);
}
},
2012-07-01 17:21:02 -03:00
_registerMouseEvents:function () {
var workspace = this._workspace;
var screenManager = workspace.getScreenManager();
var me = this;
// Initialize workspace event listeners.
2012-07-01 17:21:02 -03:00
screenManager.addEvent('update', function () {
2011-08-20 10:50:48 -03:00
// Topic must be set to his original state. All editors must be closed.
var topics = me.getModel().getTopics();
_.each(topics, function(object){
2011-08-20 10:50:48 -03:00
object.closeEditors();
});
// Clean some selected nodes on event ..
if (me._cleanScreen)
me._cleanScreen();
});
// Deselect on click ...
2012-07-01 17:21:02 -03:00
screenManager.addEvent('click', function (event) {
me.onObjectFocusEvent(null, event);
});
// Create nodes on double click...
2012-07-01 17:21:02 -03:00
screenManager.addEvent('dblclick', function (event) {
if (workspace.isWorkspaceEventsEnabled()) {
2012-01-17 00:51:13 -03:00
var mousePos = screenManager.getWorkspaceMousePosition(event);
var centralTopic = me.getModel().getCentralTopic();
var model = me._createChildModel(centralTopic, mousePos);
2012-07-08 18:41:35 -03:00
this._actionDispatcher.addTopics([model], [centralTopic.getId()]);
}
});
2012-09-20 09:23:48 -03:00
// Register mouse drag and drop event ...
function noopHandler(evt) {
evt.stopPropagation();
evt.preventDefault();
}
// Enable drag events ...
2012-11-04 15:56:26 -03:00
// @Todo: Images support on progress ...
// Element.NativeEvents.dragenter = 2;
// Element.NativeEvents.dragexit = 2;
// Element.NativeEvents.dragover = 2;
// Element.NativeEvents.drop = 2;
2012-09-20 09:23:48 -03:00
//
2012-11-04 15:56:26 -03:00
// screenManager.addEvent('dragenter', noopHandler);
// screenManager.addEvent('dragexit', noopHandler);
// screenManager.addEvent('dragover', noopHandler);
// screenManager.addEvent('drop', function (evt) {
// evt.stopPropagation();
// evt.preventDefault();
////
// var files = evt.event.dataTransfer.files;
// console.log(event);
//
// var count = files.length;
//
// // Only call the handler if 1 or more files was dropped.
// if (count > 0) {
//
// var model = this.getMindmap().createNode();
// model.setImageSize(80, 43);
// model.setMetadata("{'media':'video,'url':'http://www.youtube.com/watch?v=P3FrXftyuzw&feature=g-vrec&context=G2b4ab69RVAAAAAAAAAA'}");
// model.setImageUrl("images/logo-small.png");
// model.setShapeType(mindplot.model.TopicShape.IMAGE);
//
// var position = screenManager.getWorkspaceMousePosition(evt);
// model.setPosition(position.x, position.y);
// model.setPosition(100, 100);
//
// this._actionDispatcher.addTopics([model]);
// }
// }.bind(this));
2012-09-20 09:23:48 -03:00
2011-07-27 14:53:32 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
_buildDragManager:function (workspace) {
2012-01-30 20:17:47 -03:00
var designerModel = this.getModel();
var dragConnector = new mindplot.DragConnector(designerModel, this._workspace);
var dragManager = new mindplot.DragManager(workspace, this._eventBussDispatcher);
var topics = designerModel.getTopics();
2012-07-01 17:21:02 -03:00
dragManager.addEvent('startdragging', function () {
// Enable all mouse events.
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(false);
}
});
2012-07-01 17:21:02 -03:00
dragManager.addEvent('dragging', function (event, dragTopic) {
2012-01-18 01:26:39 -03:00
dragTopic.updateFreeLayout(event);
if (!dragTopic.isFreeLayoutOn(event)) {
// The node is being drag. Is the connection still valid ?
dragConnector.checkConnection(dragTopic);
if (!dragTopic.isVisible() && dragTopic.isConnected()) {
dragTopic.setVisibility(true);
}
2012-01-21 18:02:38 -03:00
}
});
2012-07-01 17:21:02 -03:00
dragManager.addEvent('enddragging', function (event, dragTopic) {
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(true);
}
dragTopic.applyChanges(workspace);
});
2012-01-30 20:17:47 -03:00
return dragManager;
},
2012-07-01 17:21:02 -03:00
setViewPort:function (size) {
this._workspace.setViewPort(size);
var model = this.getModel();
this._workspace.setZoom(model.getZoom(), true);
},
2011-07-27 14:53:32 -03:00
2012-03-07 17:40:10 -03:00
2012-07-01 17:21:02 -03:00
_buildNodeGraph:function (model, readOnly) {
2011-07-27 14:53:32 -03:00
// Create node graph ...
2012-02-01 20:31:40 -03:00
var topic = mindplot.NodeGraph.create(model, {readOnly:readOnly});
this.getModel().addTopic(topic);
var me = this;
2011-07-27 14:53:32 -03:00
// Add Topic events ...
2012-02-01 20:31:40 -03:00
if (!readOnly) {
2011-08-20 10:50:48 -03:00
// If a node had gained focus, clean the rest of the nodes ...
2012-07-01 17:21:02 -03:00
topic.addEvent('mousedown', function (event) {
me.onObjectFocusEvent(topic, event);
});
// Register node listeners ...
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
// Central Topic doesn't support to be dragged
2012-02-01 20:31:40 -03:00
this._dragManager.add(topic);
}
2011-08-20 10:50:48 -03:00
}
2011-07-27 14:53:32 -03:00
// Connect Topic ...
var isConnected = model.isConnected();
if (isConnected) {
// Improve this ...
var targetTopicModel = model.getParent();
var targetTopic = null;
var topics = this.getModel().getTopics();
2011-07-27 14:53:32 -03:00
for (var i = 0; i < topics.length; i++) {
var t = topics[i];
if (t.getModel() == targetTopicModel) {
targetTopic = t;
// Disconnect the node. It will be connected again later ...
model.disconnect();
break;
}
}
$assert(targetTopic, "Could not find a topic to connect");
topic.connectTo(targetTopic, this._workspace);
2009-06-07 18:59:43 +00:00
}
2012-07-01 17:21:02 -03:00
topic.addEvent('ontblur', function () {
var topics = me.getModel().filterSelectedTopics();
var rels = me.getModel().filterSelectedRelationships();
2011-10-04 01:16:29 -03:00
if (topics.length == 0 || rels.length == 0) {
me.fireEvent('onblur');
2011-10-04 01:16:29 -03:00
}
});
2011-10-04 01:16:29 -03:00
2012-07-01 17:21:02 -03:00
topic.addEvent('ontfocus', function () {
var topics = me.getModel().filterSelectedTopics();
var rels = me.getModel().filterSelectedRelationships();
2011-10-04 01:16:29 -03:00
if (topics.length == 1 || rels.length == 1) {
me.fireEvent('onfocus');
2011-10-04 01:16:29 -03:00
}
});
2011-10-04 01:16:29 -03:00
return topic;
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
onObjectFocusEvent:function (currentObject, event) {
2011-08-20 10:50:48 -03:00
// Close node editors ..
var topics = this.getModel().getTopics();
_.each(topics, function(topic) {
2011-08-20 10:50:48 -03:00
topic.closeEditors();
});
2011-08-05 01:06:56 -03:00
var model = this.getModel();
var objects = model.getEntities();
_.each(objects, function(object) {
2011-08-20 10:50:48 -03:00
// Disable all nodes on focus but not the current if Ctrl key isn't being pressed
if (!$defined(event) || (!event.ctrlKey && !event.metaKey)) {
if (object.isOnFocus() && object != currentObject) {
object.setOnFocus(false);
2011-07-27 14:53:32 -03:00
}
2011-08-20 10:50:48 -03:00
}
});
2011-07-27 14:53:32 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
selectAll:function () {
var model = this.getModel();
var objects = model.getEntities();
_.each(objects, function(object) {
object.setOnFocus(true);
});
},
2012-07-01 17:21:02 -03:00
deselectAll:function () {
var objects = this.getModel().getEntities();
_.each(objects, function (object) {
object.setOnFocus(false);
});
},
/**
* Set the zoom of the map.
* @param: zoom: number between 0.3 and 1.9
*/
2012-07-01 17:21:02 -03:00
setZoom:function (zoom) {
if (zoom > 1.9 || zoom < 0.3) {
2012-07-01 17:21:02 -03:00
$notify($msg('ZOOM_IN_ERROR'));
return;
}
this.getModel().setZoom(zoom);
this._workspace.setZoom(zoom);
},
2012-07-01 17:21:02 -03:00
zoomOut:function (factor) {
2011-08-25 00:01:17 -03:00
if (!factor)
factor = 1.2;
var model = this.getModel();
var scale = model.getZoom() * factor;
if (scale <= 1.9) {
model.setZoom(scale);
this._workspace.setZoom(scale);
}
else {
2012-07-01 17:21:02 -03:00
$notify($msg('ZOOM_ERROR'));
2011-08-25 00:01:17 -03:00
}
},
2012-07-01 17:21:02 -03:00
zoomIn:function (factor) {
if (!factor)
factor = 1.2;
var model = this.getModel();
var scale = model.getZoom() / factor;
2011-08-25 00:01:17 -03:00
2011-07-27 14:53:32 -03:00
if (scale >= 0.3) {
model.setZoom(scale);
2011-08-25 00:01:17 -03:00
this._workspace.setZoom(scale);
2011-07-27 14:53:32 -03:00
}
else {
2012-07-01 17:21:02 -03:00
$notify($msg('ZOOM_ERROR'));
2011-07-27 14:53:32 -03:00
}
},
2012-07-08 18:41:35 -03:00
copyToClipboard:function () {
var topics = this.getModel().filterSelectedTopics();
if (topics.length <= 0) {
// If there are more than one node selected,
$notify($msg('AT_LEAST_ONE_TOPIC_MUST_BE_SELECTED'));
return;
}
// Exclude central topic ..
topics = topics.filter(function (topic) {
2012-09-20 09:23:48 -03:00
return !topic.isCentralTopic();
2012-07-08 18:41:35 -03:00
});
this._clipboard = topics.map(function (topic) {
var nodeModel = topic.getModel().deepCopy();
// Change position to make the new topic evident...
var pos = nodeModel.getPosition();
nodeModel.setPosition(pos.x + (60 * Math.sign(pos.x)), pos.y + 30);
return nodeModel;
});
$notify($msg('SELECTION_COPIED_TO_CLIPBOARD'));
},
pasteClipboard:function () {
if (this._clipboard.length == 0) {
$notify($msg('CLIPBOARD_IS_EMPTY'));
return;
}
this._actionDispatcher.addTopics(this._clipboard);
this._clipboard = [];
},
2012-07-01 17:21:02 -03:00
getModel:function () {
return this._model;
},
2009-06-07 18:59:43 +00:00
2012-07-02 22:54:59 -03:00
shrinkSelectedBranch:function () {
var nodes = this.getModel().filterSelectedTopics();
2012-07-02 23:09:32 -03:00
if (nodes.length <= 0 || nodes.length != 1) {
2012-07-02 22:54:59 -03:00
// If there are more than one node selected,
2012-07-02 23:09:32 -03:00
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED_COLLAPSE'));
2012-07-02 22:54:59 -03:00
return;
}
// Execute event ...
var topic = nodes[0];
2012-11-28 22:09:29 -03:00
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken());
}
2012-07-02 22:54:59 -03:00
},
2012-07-01 17:21:02 -03:00
createChildForSelectedNode:function () {
var nodes = this.getModel().filterSelectedTopics();
2011-07-27 14:53:32 -03:00
if (nodes.length <= 0) {
// If there are more than one node selected,
2012-07-01 17:21:02 -03:00
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
2011-07-27 14:53:32 -03:00
return;
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
}
2011-09-09 21:53:41 -03:00
if (nodes.length != 1) {
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
// If there are more than one node selected,
2012-07-01 17:21:02 -03:00
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
2011-07-27 14:53:32 -03:00
return;
}
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
// Add new node ...
2011-09-09 21:53:41 -03:00
var parentTopic = nodes[0];
var parentTopicId = parentTopic.getId();
2012-01-14 09:58:06 -03:00
var childModel = this._createChildModel(parentTopic);
2009-06-07 18:59:43 +00:00
// Execute event ...
2012-07-08 18:41:35 -03:00
this._actionDispatcher.addTopics([childModel], [parentTopicId]);
2011-08-20 10:50:48 -03:00
},
2009-06-07 18:59:43 +00:00
_copyNodeProps: function(sourceModel,targetModel){
// I don't copy the font size if the target is the source is the central topic.
if(sourceModel.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE)
{
var fontSize = sourceModel.getFontSize();
if(fontSize){
targetModel.setFontSize(fontSize)
}
}
var fontFamily = sourceModel.getFontFamily();
if(fontFamily){
targetModel.setFontFamily(fontFamily)
}
var fontColor = sourceModel.getFontColor();
if(fontColor){
targetModel.setFontColor(fontColor)
}
var fontWeight = sourceModel.getFontWeight();
if(fontWeight){
targetModel.setFontWeight(fontWeight)
}
var fontStyle = sourceModel.getFontStyle();
if(fontStyle){
targetModel.setFontStyle(fontStyle)
}
var shape = sourceModel.getShapeType();
if(shape){
targetModel.setShapeType(shape)
}
var borderColor = sourceModel.getBorderColor();
if(borderColor){
targetModel.setBorderColor(borderColor)
}
var backgroundColor = sourceModel.getBackgroundColor();
if(backgroundColor){
targetModel.setBackgroundColor(backgroundColor)
}
},
2012-07-01 17:21:02 -03:00
_createChildModel:function (topic, mousePos) {
2012-01-14 09:58:06 -03:00
// Create a new node ...
var parentModel = topic.getModel();
var mindmap = parentModel.getMindmap();
var childModel = mindmap.createNode();
2012-01-14 09:58:06 -03:00
// Create a new node ...
var layoutManager = this._eventBussDispatcher.getLayoutManager();
var result = layoutManager.predict(topic.getId(), null, mousePos);
2012-01-14 09:58:06 -03:00
childModel.setOrder(result.order);
var position = result.position;
childModel.setPosition(position.x, position.y);
this._copyNodeProps(parentModel,childModel);
2012-01-14 09:58:06 -03:00
return childModel;
},
2012-07-01 17:21:02 -03:00
addDraggedNode:function (event, model) {
2012-03-07 17:40:10 -03:00
$assert(event, "event can not be null");
$assert(model, "model can not be null");
2012-03-07 17:40:10 -03:00
// Position far from the visual area ...
model.setPosition(1000, 1000);
2012-07-08 18:41:35 -03:00
this._actionDispatcher.addTopics([model]);
2012-03-07 17:40:10 -03:00
var topic = this.getModel().findTopicById(model.getId());
// Simulate a mouse down event to start the dragging ...
topic.fireEvent("mousedown", event);
},
2012-07-01 17:21:02 -03:00
createSiblingForSelectedNode:function () {
var nodes = this.getModel().filterSelectedTopics();
2011-07-27 14:53:32 -03:00
if (nodes.length <= 0) {
// If there are no nodes selected,
2012-07-01 17:21:02 -03:00
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
2011-07-27 14:53:32 -03:00
return;
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
}
if (nodes.length > 1) {
// If there are more than one node selected,
2012-07-01 17:21:02 -03:00
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
2011-07-27 14:53:32 -03:00
return;
}
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
var topic = nodes[0];
if (!topic.getOutgoingConnectedTopic()) { // Central topic and isolated topics ....
2011-07-27 14:53:32 -03:00
// Central topic doesn't have siblings ...
this.createChildForSelectedNode();
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
} else {
var parentTopic = topic.getOutgoingConnectedTopic();
2012-01-14 09:58:06 -03:00
var siblingModel = this._createSiblingModel(topic);
// Hack: if parent is central topic, add node below not on opposite side.
// This should be done in the layout
if (parentTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
siblingModel.setOrder(topic.getOrder() + 2);
}
2011-07-27 14:53:32 -03:00
var parentTopicId = parentTopic.getId();
2012-07-08 18:41:35 -03:00
this._actionDispatcher.addTopics([siblingModel], [parentTopicId]);
2009-06-07 18:59:43 +00:00
}
2011-08-25 00:17:13 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
_createSiblingModel:function (topic) {
2012-01-14 09:58:06 -03:00
var result = null;
var parentTopic = topic.getOutgoingConnectedTopic();
if (parentTopic != null) {
// Create a new node ...
var model = topic.getModel();
var mindmap = model.getMindmap();
result = mindmap.createNode();
2012-01-14 09:58:06 -03:00
// Create a new node ...
var order = topic.getOrder() + 1;
result.setOrder(order);
result.setPosition(10, 10); // Set a dummy position ...
2012-01-14 09:58:06 -03:00
}
this._copyNodeProps(model,result);
2012-01-14 09:58:06 -03:00
return result;
},
2012-07-01 17:21:02 -03:00
showRelPivot:function (event) {
var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) {
// This could not happen ...
2012-07-11 23:04:30 -03:00
$notify($msg('RELATIONSHIP_COULD_NOT_BE_CREATED'));
return;
}
2011-10-09 17:59:16 -03:00
// Current mouse position ....
2011-07-27 14:53:32 -03:00
var screen = this._workspace.getScreenManager();
var pos = screen.getWorkspaceMousePosition(event);
2011-10-09 17:59:16 -03:00
// create a connection ...
this._relPivot.start(nodes[0], pos);
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
getMindmapProperties:function () {
return {zoom:this.getModel().getZoom()};
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
loadMap:function (mindmapModel) {
2011-09-08 09:16:50 -03:00
$assert(mindmapModel, "mindmapModel can not be null");
this._mindmap = mindmapModel;
2009-06-07 18:59:43 +00:00
// Init layout manager ...
2012-07-01 17:21:02 -03:00
var size = {width:25, height:25};
var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size);
var me = this;
2012-07-01 17:21:02 -03:00
layoutManager.addEvent('change', function (event) {
var id = event.getId();
var topic = me.getModel().findTopicById(id);
topic.setPosition(event.getPosition());
topic.setOrder(event.getOrder());
});
this._eventBussDispatcher.setLayoutManager(layoutManager);
2012-01-21 18:02:38 -03:00
// Building node graph ...
var branches = mindmapModel.getBranches();
for (var i = 0; i < branches.length; i++) {
// NodeModel -> NodeGraph ...
var nodeModel = branches[i];
var nodeGraph = this._nodeModelToNodeGraph(nodeModel);
2009-06-07 18:59:43 +00:00
// Update shrink render state...
nodeGraph.setBranchVisibility(true);
}
2011-11-13 21:18:34 -03:00
var relationships = mindmapModel.getRelationships();
for (var j = 0; j < relationships.length; j++) {
this._relationshipModelToRelationship(relationships[j]);
}
2009-06-07 18:59:43 +00:00
// Place the focus on the Central Topic
var centralTopic = this.getModel().getCentralTopic();
this.goToNode(centralTopic);
2012-01-09 23:50:52 -03:00
// Finally, sort the map ...
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
2012-02-04 12:51:50 -03:00
this.fireEvent('loadSuccess');
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
getMindmap:function () {
2011-07-27 14:53:32 -03:00
return this._mindmap;
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
undo:function () {
2011-10-15 13:23:27 -03:00
// @Todo: This is a hack...
this._actionDispatcher._actionRunner.undo();
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
redo:function () {
2011-10-15 13:23:27 -03:00
this._actionDispatcher._actionRunner.redo();
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
isReadOnly:function () {
2012-02-01 20:31:40 -03:00
return this._options.readOnly;
},
_nodeModelToNodeGraph:function (nodeModel) {
2011-07-27 14:53:32 -03:00
$assert(nodeModel, "Node model can not be null");
2012-01-12 00:49:18 -03:00
var children = nodeModel.getChildren().slice();
2012-07-01 17:21:02 -03:00
children = children.sort(function (a, b) {
return a.getOrder() - b.getOrder()
});
2012-01-12 00:49:18 -03:00
2012-02-01 20:31:40 -03:00
var nodeGraph = this._buildNodeGraph(nodeModel, this.isReadOnly());
nodeGraph.setVisibility(false);
2009-06-07 18:59:43 +00:00
2014-03-05 00:14:28 -03:00
this._workspace.append(nodeGraph);
2011-07-27 14:53:32 -03:00
for (var i = 0; i < children.length; i++) {
var child = children[i];
if ($defined(child))
this._nodeModelToNodeGraph(child);
2011-07-27 14:53:32 -03:00
}
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
return nodeGraph;
2011-11-13 21:18:34 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
_relationshipModelToRelationship:function (model) {
2011-07-27 14:53:32 -03:00
$assert(model, "Node model can not be null");
2011-10-09 17:59:16 -03:00
2012-07-07 11:52:23 -03:00
var result = this._buildRelationshipShape(model);
2011-10-09 17:59:16 -03:00
2012-07-07 01:33:34 -03:00
var sourceTopic = result.getSourceTopic();
sourceTopic.addRelationship(result);
2011-10-09 17:59:16 -03:00
2012-07-07 01:33:34 -03:00
var targetTopic = result.getTargetTopic();
targetTopic.addRelationship(result);
result.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
2014-03-05 00:14:28 -03:00
this._workspace.append(result);
2012-07-07 01:33:34 -03:00
return result;
2011-10-09 17:59:16 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-07 01:33:34 -03:00
_addRelationship:function (model) {
2012-07-13 21:27:52 -03:00
var mindmap = this.getMindmap();
mindmap.addRelationship(model);
2011-07-27 14:53:32 -03:00
return this._relationshipModelToRelationship(model);
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-13 21:27:52 -03:00
_deleteRelationship:function (rel) {
var sourceTopic = rel.getSourceTopic();
sourceTopic.deleteRelationship(rel);
2012-07-13 21:27:52 -03:00
var targetTopic = rel.getTargetTopic();
targetTopic.deleteRelationship(rel);
2012-07-13 21:27:52 -03:00
this.getModel().removeRelationship(rel);
this._workspace.removeChild(rel);
2012-07-13 21:27:52 -03:00
var mindmap = this.getMindmap();
mindmap.deleteRelationship(rel.getModel());
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-07 11:52:23 -03:00
_buildRelationshipShape:function (model) {
2011-10-09 17:59:16 -03:00
var dmodel = this.getModel();
var sourceTopicId = model.getFromNode();
var sourceTopic = dmodel.findTopicById(sourceTopicId);
var targetTopicId = model.getToNode();
var targetTopic = dmodel.findTopicById(targetTopicId);
2012-11-18 20:17:16 -03:00
$assert(targetTopic, "targetTopic could not be found:" + targetTopicId + dmodel.getTopics().map(function (e) {
2012-11-17 14:38:34 -03:00
return e.getId()
}));
2009-06-07 18:59:43 +00:00
// Build relationship line ....
2012-07-07 01:33:34 -03:00
var result = new mindplot.Relationship(sourceTopic, targetTopic, model);
var me = this;
result.addEvent('ontblur', function () {
var topics = me.getModel().filterSelectedTopics();
var rels = me.getModel().filterSelectedRelationships();
if (topics.length == 0 || rels.length == 0) {
me.fireEvent('onblur');
}
});
result.addEvent('ontfocus', function () {
var topics = me.getModel().filterSelectedTopics();
var rels = me.getModel().filterSelectedRelationships();
if (topics.length == 1 || rels.length == 1) {
me.fireEvent('onfocus');
}
});
2009-06-07 18:59:43 +00:00
2011-07-27 14:53:32 -03:00
// Append it to the workspace ...
2012-07-07 01:33:34 -03:00
dmodel.addRelationship(result);
2012-07-07 01:33:34 -03:00
return result;
2011-08-20 10:50:48 -03:00
},
2009-06-07 18:59:43 +00:00
_removeTopic:function (node) {
2012-09-20 09:23:48 -03:00
if (!node.isCentralTopic()) {
2011-07-27 14:53:32 -03:00
var parent = node._parent;
node.disconnect(this._workspace);
//remove children
2012-03-07 01:13:50 -03:00
while (node.getChildren().length > 0) {
this._removeTopic(node.getChildren()[0]);
2011-07-27 14:53:32 -03:00
}
this._workspace.removeChild(node);
this.getModel().removeTopic(node);
2011-07-27 14:53:32 -03:00
// Delete this node from the model...
var model = node.getModel();
model.deleteNode();
if ($defined(parent)) {
this.goToNode(parent);
2011-07-27 14:53:32 -03:00
}
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
_resetEdition:function () {
var screenManager = this._workspace.getScreenManager();
screenManager.fireEvent("update");
screenManager.fireEvent("mouseup");
this._relPivot.dispose();
},
deleteSelectedEntities:function () {
// Is there some action in progress ?.
this._resetEdition();
2011-07-27 14:53:32 -03:00
var topics = this.getModel().filterSelectedTopics();
var relation = this.getModel().filterSelectedRelationships();
if (topics.length <= 0 && relation.length <= 0) {
// If there are more than one node selected,
$notify($msg('ENTITIES_COULD_NOT_BE_DELETED'));
return;
2012-09-20 09:23:48 -03:00
} else if (topics.length == 1 && topics[0].isCentralTopic()) {
2012-07-07 11:52:23 -03:00
$notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED'));
return;
}
2012-07-07 11:52:23 -03:00
// If the central topic has been selected, I must filter ir
var topicIds = topics.filter(function (topic) {
2012-09-20 09:23:48 -03:00
return !topic.isCentralTopic();
2012-07-07 11:52:23 -03:00
}).map(function (topic) {
return topic.getId()
});
2012-07-07 13:18:27 -03:00
var relIds = relation.map(function (rel) {
return rel.getId();
});
// Finally delete the topics ...
if (topicIds.length > 0 || relIds.length > 0) {
this._actionDispatcher.deleteEntities(topicIds, relIds);
2009-06-07 18:59:43 +00:00
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeFontFamily:function (font) {
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontFamilyToTopic(topicsIds, font);
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeFontStyle:function () {
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontStyleToTopic(topicsIds);
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeFontColor:function (color) {
$assert(color, "color can not be null");
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontColorToTopic(topicsIds, color);
2009-06-07 18:59:43 +00:00
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeBackgroundColor:function (color) {
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
var validateFunc = function (topic) {
2012-02-27 22:47:10 -03:00
return topic.getShapeType() != mindplot.model.TopicShape.LINE;
2009-06-07 18:59:43 +00:00
};
var validateError = 'Color can not be set to line topics.';
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeBackgroundColorToTopic(topicsIds, color);
2011-07-27 14:53:32 -03:00
}
2011-08-20 10:50:48 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
changeBorderColor:function (color) {
var validateFunc = function (topic) {
2012-03-07 17:40:10 -03:00
return topic.getShapeType() != mindplot.model.TopicShape.LINE;
2011-07-27 14:53:32 -03:00
};
var validateError = 'Color can not be set to line topics.';
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeBorderColorToTopic(topicsIds, color);
2009-06-07 18:59:43 +00:00
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeFontSize:function (size) {
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontSizeToTopic(topicsIds, size);
2011-07-27 14:53:32 -03:00
}
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeTopicShape:function (shape) {
var validateFunc = function (topic) {
2012-02-27 22:47:10 -03:00
return !(topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.TopicShape.LINE)
2009-06-07 18:59:43 +00:00
};
2011-07-27 14:53:32 -03:00
var validateError = 'Central Topic shape can not be changed to line figure.';
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
2011-09-09 21:53:41 -03:00
this._actionDispatcher.changeShapeTypeToTopic(topicsIds, shape);
2011-07-27 14:53:32 -03:00
}
2011-08-20 10:50:48 -03:00
},
2011-07-27 14:53:32 -03:00
2012-07-01 17:21:02 -03:00
changeFontWeight:function () {
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontWeightToTopic(topicsIds);
2011-07-27 14:53:32 -03:00
}
2011-08-20 10:50:48 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
addIconType:function (iconType) {
var topicsIds = this.getModel().filterTopicsIds();
2011-07-27 14:53:32 -03:00
if (topicsIds.length > 0) {
this._actionDispatcher.addFeatureToTopic(topicsIds[0], mindplot.TopicFeature.Icon.id, {id:iconType});
2011-07-27 14:53:32 -03:00
}
2011-08-20 10:50:48 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
addLink:function () {
2011-10-07 01:30:55 -03:00
var model = this.getModel();
var topic = model.selectedTopic();
if (topic) {
topic.showLinkEditor();
}
2011-07-27 14:53:32 -03:00
},
2012-07-01 17:21:02 -03:00
addNote:function () {
2011-08-25 22:08:39 -03:00
var model = this.getModel();
var topic = model.selectedTopic();
if (topic) {
topic.showNoteEditor();
}
2011-07-27 14:53:32 -03:00
},
2009-06-07 18:59:43 +00:00
2012-07-01 17:21:02 -03:00
goToNode:function (node) {
2011-07-27 14:53:32 -03:00
node.setOnFocus(true);
this.onObjectFocusEvent(node);
2011-07-27 14:53:32 -03:00
},
2012-07-01 17:21:02 -03:00
getWorkSpace:function () {
2011-07-27 14:53:32 -03:00
return this._workspace;
}
}
2011-07-27 14:53:32 -03:00
);