feat(modelling): unify drag/drop handling from palette/context-pad

Related to bpmn-io/diagram-js#60
This commit is contained in:
Nico Rehwaldt 2014-12-23 16:48:12 +01:00
parent 1dd19fdb0d
commit 355059c30a
2 changed files with 34 additions and 32 deletions

View File

@ -47,29 +47,23 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
var bpmnElement = element.businessObject;
function startConnect(event, element) {
connect.start(event, element, null);
}
function append(element, type) {
var target = modeling.appendShape(element, { type: type });
selection.select(target);
directEditing.activate(target);
function startConnect(event, element, autoActivate) {
connect.start(event, element, autoActivate);
}
function appendAction(type, className) {
function appendListener(event, element) {
var shape = elementFactory.createShape({ type: type });
create.start(event, shape, element);
}
return {
group: 'model',
className: className,
action: {
dragstart: function(event, element) {
var shape = elementFactory.createShape({ type: type });
create.start(event, shape, element);
},
click: function(event, element) {
append(element, type);
}
dragstart: appendListener,
click: appendListener
}
};
}
@ -99,18 +93,22 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
});
}
_.extend(actions, {
'delete': {
group: 'edit',
className: 'icon-trash',
action: function(e) {
function removeElement(e) {
if (element.waypoints) {
modeling.removeConnection(element);
} else {
modeling.removeShape(element);
}
}
_.extend(actions, {
'delete': {
group: 'edit',
className: 'icon-trash',
action: {
click: removeElement,
dragstart: removeElement
}
}
});

View File

@ -20,12 +20,8 @@ PaletteProvider.$inject = [ 'palette', 'create', 'elementFactory' ];
PaletteProvider.prototype.getPaletteEntries = function(element) {
function createAction(type, group, className, title, options) {
return {
group: group,
className: className,
title: title || 'Create ' + type,
action: {
dragstart: function(event) {
function createListener(event) {
var shape = elementFactory.createShape(_.extend({ type: type }, options));
if (options) {
@ -34,6 +30,14 @@ PaletteProvider.prototype.getPaletteEntries = function(element) {
create.start(event, shape);
}
return {
group: group,
className: className,
title: title || 'Create ' + type,
action: {
dragstart: createListener,
click: createListener
}
};
}