RemoveVariableEventBehaviour.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. var inherits = require('inherits');
  3. var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor').default;
  4. var is = require('bpmn-js/lib/util/ModelUtil').is;
  5. var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;
  6. /**
  7. * Remove 'camunda:variableEvents' property when a startEvent is moved out of an event subProcess.
  8. */
  9. function RemoveVariableEventBehaviour(
  10. modeling, injector, bpmnFactory, moddleCopy
  11. ) {
  12. injector.invoke(CommandInterceptor, this);
  13. this.postExecuted(['shape.move', 'shape.create'], function(context) {
  14. var newParent = context.newParent || context.parent,
  15. newParentBusinessObject = getBusinessObject(newParent),
  16. shape = context.shape,
  17. shapeBusinessObject = getBusinessObject(shape),
  18. eventDefinitions, definitionsCopy;
  19. var update = false;
  20. if (is(shape, 'bpmn:StartEvent')) {
  21. if (!(is(newParent, 'bpmn:SubProcess') && newParentBusinessObject.get('triggeredByEvent'))) {
  22. eventDefinitions = shapeBusinessObject.get('eventDefinitions');
  23. definitionsCopy = eventDefinitions.slice();
  24. definitionsCopy.forEach(function(eventDefinition, index) {
  25. if (!is(eventDefinition, 'bpmn:ConditionalEventDefinition')) {
  26. return;
  27. }
  28. if (eventDefinition.get('camunda:variableEvents')) {
  29. update = true;
  30. var newDefinition = bpmnFactory.create('bpmn:ConditionalEventDefinition');
  31. moddleCopy.copyElement(eventDefinition, newDefinition);
  32. newDefinition.$parent = eventDefinition.$parent;
  33. // remove variableEvents property
  34. newDefinition.variableEvents = undefined;
  35. definitionsCopy[index] = newDefinition;
  36. }
  37. });
  38. if (update) {
  39. modeling.updateProperties(shape, { 'eventDefinitions': definitionsCopy });
  40. }
  41. }
  42. }
  43. }, true);
  44. }
  45. RemoveVariableEventBehaviour.$inject = [
  46. 'modeling',
  47. 'injector',
  48. 'bpmnFactory',
  49. 'moddleCopy'
  50. ];
  51. inherits(RemoveVariableEventBehaviour, CommandInterceptor);
  52. module.exports = RemoveVariableEventBehaviour;