2014-06-27 15:52:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A provider for BPMN 2.0 elements context pad
|
|
|
|
*/
|
2014-12-07 12:08:50 +00:00
|
|
|
function ContextPadProvider(contextPad, directEditing, modeling, selection, elementFactory, connect, create) {
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
contextPad.registerProvider(this);
|
|
|
|
|
|
|
|
this._directEditing = directEditing;
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
this._modeling = modeling;
|
2014-12-07 12:08:50 +00:00
|
|
|
this._selection = selection;
|
2014-09-11 14:44:56 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
this._elementFactory = elementFactory;
|
2014-09-11 14:44:56 +00:00
|
|
|
this._connect = connect;
|
2014-12-07 12:08:50 +00:00
|
|
|
this._create = create;
|
2014-06-27 15:52:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 14:10:02 +00:00
|
|
|
ContextPadProvider.$inject = [
|
|
|
|
'contextPad',
|
|
|
|
'directEditing',
|
|
|
|
'modeling',
|
|
|
|
'selection',
|
|
|
|
'elementFactory',
|
|
|
|
'connect',
|
|
|
|
'create'
|
|
|
|
];
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
ContextPadProvider.prototype.getContextPadEntries = function(element) {
|
|
|
|
|
|
|
|
var directEditing = this._directEditing,
|
2014-07-23 16:53:33 +00:00
|
|
|
modeling = this._modeling,
|
2014-09-11 14:44:56 +00:00
|
|
|
selection = this._selection,
|
2014-12-07 12:08:50 +00:00
|
|
|
elementFactory = this._elementFactory,
|
|
|
|
connect = this._connect,
|
|
|
|
create = this._create;
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
var actions = {};
|
|
|
|
|
|
|
|
if (element.type === 'label') {
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bpmnElement = element.businessObject;
|
|
|
|
|
2014-09-11 14:44:56 +00:00
|
|
|
function startConnect(event, element) {
|
|
|
|
connect.start(event, element, null);
|
|
|
|
}
|
|
|
|
|
2014-06-27 15:52:34 +00:00
|
|
|
function append(element, type) {
|
2014-12-07 12:08:50 +00:00
|
|
|
var target = modeling.appendShape(element, { type: type });
|
2014-07-18 13:29:41 +00:00
|
|
|
|
|
|
|
selection.select(target);
|
2014-06-27 15:52:34 +00:00
|
|
|
directEditing.activate(target);
|
|
|
|
}
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
function appendAction(type, className) {
|
|
|
|
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);
|
2014-09-11 14:44:56 +00:00
|
|
|
}
|
2014-06-27 15:52:34 +00:00
|
|
|
}
|
2014-12-07 12:08:50 +00:00
|
|
|
};
|
|
|
|
}
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
if (bpmnElement.$instanceOf('bpmn:FlowNode')) {
|
|
|
|
|
|
|
|
if (!bpmnElement.$instanceOf('bpmn:EndEvent')) {
|
|
|
|
|
|
|
|
_.extend(actions, {
|
|
|
|
'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event'),
|
|
|
|
'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway'),
|
|
|
|
'append.append-task': appendAction('bpmn:Task', 'icon-task'),
|
|
|
|
'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent', 'icon-intermediate-event'),
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
|
|
|
className: 'icon-connection',
|
|
|
|
action: {
|
|
|
|
click: startConnect,
|
|
|
|
dragstart: startConnect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_.extend(actions, {
|
|
|
|
'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation')
|
|
|
|
});
|
2014-06-27 15:52:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 11:28:35 +00:00
|
|
|
_.extend(actions, {
|
2014-12-07 12:08:50 +00:00
|
|
|
'delete': {
|
2014-09-11 14:44:56 +00:00
|
|
|
group: 'edit',
|
2014-11-05 13:05:31 +00:00
|
|
|
className: 'icon-trash',
|
2014-09-04 11:28:35 +00:00
|
|
|
action: function(e) {
|
2014-12-23 13:24:34 +00:00
|
|
|
|
|
|
|
if (element.waypoints) {
|
|
|
|
modeling.removeConnection(element);
|
|
|
|
} else {
|
|
|
|
modeling.removeShape(element);
|
|
|
|
}
|
2014-09-04 11:28:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-27 15:52:34 +00:00
|
|
|
return actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-29 14:03:08 +00:00
|
|
|
module.exports = ContextPadProvider;
|