camunda-bpmn-js-behaviors
Version:
Camunda Platform 7 and 8 behaviors for bpmn-js
80 lines (64 loc) • 1.82 kB
JavaScript
import {
getBusinessObject,
is,
isAny
} from 'bpmn-js/lib/util/ModelUtil';
import { getEventDefinition } from '../../util/EventDefinition';
export const TIMER_PROPERTIES = [
'timeCycle',
'timeDate',
'timeDuration'
];
export function getTimerEventDefinition(element) {
return getEventDefinition(element, 'bpmn:TimerEventDefinition');
}
/**
* Check whether a given timer expression type is supported for a given element.
*
* @param {string} type
* @param {Element|ModdleElement} element
*
* @return {boolean}
*/
export function isTimerExpressionTypeSupported(type, element) {
const businessObject = getBusinessObject(element);
switch (type) {
case 'timeDate':
return isAny(element, [
'bpmn:BoundaryEvent',
'bpmn:IntermediateCatchEvent',
'bpmn:StartEvent'
]);
case 'timeCycle':
if (is(element, 'bpmn:StartEvent') && (!hasParentEventSubProcess(businessObject)) || !isInterrupting(businessObject)) {
return true;
}
if (is(element, 'bpmn:BoundaryEvent') && !isInterrupting(businessObject)) {
return true;
}
return false;
case 'timeDuration':
if (isAny(element, [
'bpmn:BoundaryEvent',
'bpmn:IntermediateCatchEvent'
])) {
return true;
}
if (is(element, 'bpmn:StartEvent') && hasParentEventSubProcess(businessObject)) {
return true;
}
return false;
default:
return false;
}
}
function isInterrupting(businessObject) {
if (is(businessObject, 'bpmn:BoundaryEvent')) {
return businessObject.get('cancelActivity') !== false;
}
return businessObject.get('isInterrupting') !== false;
}
function hasParentEventSubProcess(businessObject) {
const parent = businessObject.$parent;
return parent && is(parent, 'bpmn:SubProcess') && parent.get('triggeredByEvent');
}