2016-04-20 15:31:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ModelUtil = require('../../util/ModelUtil'),
|
|
|
|
getBusinessObject = ModelUtil.getBusinessObject,
|
|
|
|
is = ModelUtil.is;
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
var ModelCloneHelper = require('../../util/model/ModelCloneHelper');
|
|
|
|
|
|
|
|
var ModelCloneUtils = require('../../util/model/ModelCloneUtils'),
|
|
|
|
getProperties = ModelCloneUtils.getProperties;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
var IGNORED_PROPERTIES = ModelCloneUtils.IGNORED_PROPERTIES;
|
|
|
|
|
|
|
|
var filter = require('lodash/collection/filter'),
|
|
|
|
forEach = require('lodash/collection/forEach');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
function setProperties(descriptor, data, properties) {
|
|
|
|
forEach(properties, function(property) {
|
2016-06-14 09:06:51 +00:00
|
|
|
if (data[property] !== undefined) {
|
2016-04-20 15:31:42 +00:00
|
|
|
descriptor[property] = data[property];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeProperties(element, properties) {
|
|
|
|
forEach(properties, function(prop) {
|
|
|
|
if (element[prop]) {
|
|
|
|
delete element[prop];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function BpmnCopyPaste(bpmnFactory, eventBus, copyPaste, clipboard, moddle, canvas, bpmnRules) {
|
|
|
|
|
2017-01-23 13:12:43 +00:00
|
|
|
var helper = new ModelCloneHelper(eventBus);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
copyPaste.registerDescriptor(function(element, descriptor) {
|
|
|
|
var businessObject = getBusinessObject(element),
|
2017-01-19 15:16:56 +00:00
|
|
|
newBusinessObject = bpmnFactory.create(businessObject.$type);
|
|
|
|
|
|
|
|
var properties = getProperties(businessObject.$descriptor);
|
|
|
|
|
|
|
|
properties = filter(properties, function(property) {
|
|
|
|
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
descriptor.businessObject = helper.clone(businessObject, newBusinessObject, properties);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
descriptor.type = element.type;
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
setProperties(descriptor, businessObject.di, [ 'isExpanded' ]);
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
if (element.type === 'label') {
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperties(descriptor, businessObject, [
|
2017-01-19 15:16:56 +00:00
|
|
|
'type',
|
2016-04-20 15:31:42 +00:00
|
|
|
'processRef',
|
2017-01-19 15:16:56 +00:00
|
|
|
'triggeredByEvent'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (businessObject.default) {
|
|
|
|
descriptor.default = businessObject.default.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptor;
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.on('element.paste', function(context) {
|
|
|
|
var descriptor = context.descriptor,
|
|
|
|
createdElements = context.createdElements,
|
|
|
|
parent = descriptor.parent,
|
2016-05-20 10:40:15 +00:00
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
businessObject,
|
|
|
|
source,
|
|
|
|
target,
|
|
|
|
canConnect;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
if (descriptor.type === 'label') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(parent, 'bpmn:Process')) {
|
|
|
|
descriptor.parent = is(rootElement, 'bpmn:Collaboration') ? rootElement : parent;
|
2016-04-26 12:02:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 10:40:15 +00:00
|
|
|
if (descriptor.type === 'bpmn:DataOutputAssociation' ||
|
|
|
|
descriptor.type === 'bpmn:DataInputAssociation' ||
|
|
|
|
descriptor.type === 'bpmn:MessageFlow') {
|
|
|
|
descriptor.parent = rootElement;
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 10:40:15 +00:00
|
|
|
if (is(parent, 'bpmn:Lane')) {
|
|
|
|
descriptor.parent = parent.parent;
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that the correct type of connection is created
|
|
|
|
if (descriptor.waypoints) {
|
|
|
|
source = createdElements[descriptor.source];
|
|
|
|
target = createdElements[descriptor.target];
|
|
|
|
|
|
|
|
if (source && target) {
|
|
|
|
source = source.element;
|
|
|
|
target = target.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
canConnect = bpmnRules.canConnect(source, target);
|
|
|
|
|
|
|
|
if (canConnect) {
|
|
|
|
descriptor.type = canConnect.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
businessObject = descriptor.businessObject;
|
|
|
|
|
|
|
|
// remove the id or else we cannot paste multiple times
|
|
|
|
delete businessObject.id;
|
|
|
|
|
|
|
|
// assign an ID
|
|
|
|
bpmnFactory._ensureId(businessObject);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) {
|
|
|
|
descriptor.processRef = businessObject.processRef = bpmnFactory.create('bpmn:Process');
|
|
|
|
}
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
setProperties(businessObject, descriptor, [
|
2016-06-14 09:06:51 +00:00
|
|
|
'isExpanded',
|
|
|
|
'triggeredByEvent'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
removeProperties(descriptor, [
|
2016-06-14 09:06:51 +00:00
|
|
|
'triggeredByEvent'
|
2016-06-07 06:46:45 +00:00
|
|
|
]);
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BpmnCopyPaste.$inject = [
|
|
|
|
'bpmnFactory',
|
|
|
|
'eventBus',
|
|
|
|
'copyPaste',
|
|
|
|
'clipboard',
|
|
|
|
'moddle',
|
|
|
|
'canvas',
|
|
|
|
'bpmnRules'
|
|
|
|
];
|
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
module.exports = BpmnCopyPaste;
|