RemoveInitiatorBehaviour.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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:initiator` property when a startEvent is moved to or created within a subProcess.
  8. */
  9. function RemoveInitiatorBehaviour(
  10. modeling, injector
  11. ) {
  12. injector.invoke(CommandInterceptor, this);
  13. this.postExecuted(['shape.create','shape.move'], function(context) {
  14. var shape = context.shape,
  15. newParent = context.newParent || context.parent,
  16. businessObject = getBusinessObject(shape);
  17. // if shape is a startEvent and has an initiator proterty
  18. if (is(shape, 'bpmn:StartEvent') && businessObject.get('camunda:initiator') !== undefined) {
  19. // if subProcess becomes the new parent
  20. if ((is(newParent, 'bpmn:SubProcess'))) {
  21. // remove initiator property
  22. modeling.updateProperties(shape, { 'camunda:initiator': undefined });
  23. }
  24. }
  25. }, true);
  26. }
  27. RemoveInitiatorBehaviour.$inject = [
  28. 'modeling',
  29. 'injector',
  30. ];
  31. inherits(RemoveInitiatorBehaviour, CommandInterceptor);
  32. module.exports = RemoveInitiatorBehaviour;