1 var entryFactory = require('bpmn-js-properties-panel/lib/factory/EntryFactory'),
2 cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper'),
3 extensionElementsHelper = require('bpmn-js-properties-panel/lib/helper/ExtensionElementsHelper'),
4 elementHelper = require('bpmn-js-properties-panel/lib/helper/ElementHelper');
6 var assign = require('lodash.assign');
7 var map = require('lodash.map');
8 import { implementationType } from './implementationConstants';
10 var DEFAULT_DELEGATE_PROPS = ['class', 'expression', 'delegateExpression'];
12 var DELEGATE_PROPS = {
13 'camunda:class': undefined,
14 'camunda:expression': undefined,
15 'camunda:delegateExpression': undefined,
16 'camunda:resultVariable': undefined
19 var DMN_CAPABLE_PROPS = {
20 'camunda:decisionRef': undefined,
21 'camunda:decisionRefBinding': 'latest',
22 'camunda:decisionRefVersion': undefined,
23 'camunda:mapDecisionResult': 'resultList',
24 'camunda:decisionRefTenantId': undefined
27 var EXTERNAL_CAPABLE_PROPS = {
28 'camunda:type': undefined,
29 'camunda:topic': undefined
32 const ACTIVITY_PROPS = {};
34 ACTIVITY_PROPS[implementationType] = undefined;
36 module.exports = function(element, bpmnFactory, options, translate) {
37 var DEFAULT_OPTIONS = [
38 { value: 'class', name: translate('Java Class') },
39 { value: 'expression', name: translate('Expression') },
40 { value: 'delegateExpression', name: translate('Delegate Expression') }
43 var DMN_OPTION = [{ value: 'dmn', name: translate('DMN') }];
45 var EXTERNAL_OPTION = [{ value: 'external', name: translate('External') }];
47 var CONNECTOR_OPTION = [
48 { value: 'connector', name: translate('Connector') }
51 var SCRIPT_OPTION = [{ value: 'script', name: translate('Script') }];
53 var ACTIVITY_OPTION = [
54 { value: 'workflowActivity', name: translate('Activity') }
57 var getType = options.getImplementationType,
58 getBusinessObject = options.getBusinessObject;
60 var hasDmnSupport = options.hasDmnSupport,
61 hasExternalSupport = options.hasExternalSupport,
62 hasServiceTaskLikeSupport = options.hasServiceTaskLikeSupport,
63 hasScriptSupport = options.hasScriptSupport;
67 var selectOptions = DEFAULT_OPTIONS.concat([]);
70 selectOptions = selectOptions.concat(DMN_OPTION);
73 if (hasExternalSupport) {
74 selectOptions = selectOptions.concat(EXTERNAL_OPTION);
77 if (hasServiceTaskLikeSupport) {
78 selectOptions = selectOptions.concat(CONNECTOR_OPTION);
81 if (hasScriptSupport) {
82 selectOptions = selectOptions.concat(SCRIPT_OPTION);
85 selectOptions = selectOptions.concat(ACTIVITY_OPTION);
87 selectOptions.push({ value: '' });
90 entryFactory.selectBox({
92 label: translate('Implementation'),
93 selectOptions: selectOptions,
94 modelProperty: 'implType',
96 get: function(element) {
98 implType: getType(element) || ''
102 set: function(element, values) {
103 var bo = getBusinessObject(element);
104 var oldType = getType(element);
105 var newType = values.implType;
107 var props = assign({}, DELEGATE_PROPS);
109 if (DEFAULT_DELEGATE_PROPS.indexOf(newType) !== -1) {
111 if (DEFAULT_DELEGATE_PROPS.indexOf(oldType) !== -1) {
112 newValue = bo.get('camunda:' + oldType);
115 props['camunda:' + newType] = newValue;
119 props = assign(props, DMN_CAPABLE_PROPS);
120 if (newType === 'dmn') {
121 props['camunda:decisionRef'] = '';
125 if (hasExternalSupport) {
126 props = assign(props, EXTERNAL_CAPABLE_PROPS);
127 if (newType === 'external') {
128 props['camunda:type'] = 'external';
129 props['camunda:topic'] = '';
133 if (hasScriptSupport) {
134 props['camunda:script'] = undefined;
136 if (newType === 'script') {
137 props['camunda:script'] = elementHelper.createElement(
146 props = assign(props, ACTIVITY_PROPS);
147 props[implementationType.ACTIVITY] = undefined;
149 if (newType === 'workflowActivity') {
150 props[implementationType.ACTIVITY] = '';
151 props[implementationType.ACTIVITY_RESOURCE] = '';
153 var inputsOutputs = extensionElementsHelper.getExtensionElements(
155 'camunda:InputOutput'
158 map(inputsOutputs, function(inputOutput) {
159 return extensionElementsHelper.removeEntry(
169 cmdHelper.updateBusinessObject(element, bo, props)
172 if (hasServiceTaskLikeSupport) {
173 var connectors = extensionElementsHelper.getExtensionElements(
178 map(connectors, function(connector) {
179 return extensionElementsHelper.removeEntry(
187 if (newType === 'connector') {
188 var extensionElements = bo.get('extensionElements');
189 if (!extensionElements) {
190 extensionElements = elementHelper.createElement(
191 'bpmn:ExtensionElements',
197 cmdHelper.updateBusinessObject(element, bo, {
198 extensionElements: extensionElements
202 var connector = elementHelper.createElement(
209 cmdHelper.addAndRemoveElementsFromList(