camunda-bpmn-js-behaviors
Version:
Camunda Platform 7 and 8 behaviors for bpmn-js
61 lines (44 loc) • 1.52 kB
JavaScript
import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil';
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
import { getEventDefinition } from '../util/EventDefinition';
export default class CleanUpMessageRefBehavior extends CommandInterceptor {
constructor(eventBus, modeling) {
super(eventBus, modeling);
this.postExecuted('shape.replace', function(event) {
const newShape = event.context.newShape;
if (!is(newShape, 'bpmn:ThrowEvent')) {
return;
}
const messageEventDefinition = getMessageEventDefinition(newShape);
if (!messageEventDefinition) {
return;
}
const messageRef = messageEventDefinition.get('messageRef');
if (!messageRef) {
return;
}
modeling.updateModdleProperties(newShape, messageEventDefinition, {
messageRef: undefined
});
});
this.postExecuted('shape.replace', function(event) {
const newShape = event.context.newShape,
bo = getBusinessObject(newShape);
if (!is(bo, 'bpmn:SendTask')) {
return;
}
const messageRef = bo.get('messageRef');
if (!messageRef) {
return;
}
modeling.updateProperties(newShape, {
messageRef: undefined
});
});
}
}
CleanUpMessageRefBehavior.$inject = [ 'eventBus', 'modeling' ];
// helpers //////////
function getMessageEventDefinition(element) {
return getEventDefinition(element, 'bpmn:MessageEventDefinition');
}