Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / version / composition / custom-properties-provider / provider / camunda / parts / implementation / ResultVariable.js
1 'use strict';
2
3 import { is } from 'bpmn-js/lib/util/ModelUtil';
4
5 import assign from 'lodash.assign';
6
7 var entryFactory = require('bpmn-js-properties-panel/lib/factory/EntryFactory'),
8     cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper');
9
10 export default function(element, bpmnFactory, options, translate) {
11     var getBusinessObject = options.getBusinessObject,
12         hideResultVariable = options.hideResultVariable,
13         id = options.id || 'resultVariable';
14
15     var resultVariableEntry = entryFactory.textField({
16         id: id,
17         label: translate('Result Variable'),
18         modelProperty: 'resultVariable',
19
20         get: function(element) {
21             var bo = getBusinessObject(element);
22             return { resultVariable: bo.get('camunda:resultVariable') };
23         },
24
25         set: function(element, values) {
26             var bo = getBusinessObject(element);
27
28             var resultVariable = values.resultVariable || undefined;
29
30             var props = {
31                 'camunda:resultVariable': resultVariable
32             };
33
34             if (is(bo, 'camunda:DmnCapable') && !resultVariable) {
35                 props = assign(
36                     { 'camunda:mapDecisionResult': 'resultList' },
37                     props
38                 );
39             }
40
41             return cmdHelper.updateBusinessObject(element, bo, props);
42         },
43
44         hidden: function() {
45             if (typeof hideResultVariable === 'function') {
46                 return hideResultVariable.apply(resultVariableEntry, arguments);
47             }
48         }
49     });
50
51     return [resultVariableEntry];
52 }