'use strict'; var is = require('bpmn-js/lib/util/ModelUtil').is; var elementHelper = require('../../../../helper/ElementHelper'), inputOutputHelper = require('../../../../helper/InputOutputHelper'), cmdHelper = require('../../../../helper/CmdHelper'), utils = require('../../../../Utils'); var entryFactory = require('../../../../factory/EntryFactory'), scriptImplementation = require('./Script'); function createElement(type, parent, factory, properties) { return elementHelper.createElement(type, properties, parent, factory); } function isScript(elem) { return is(elem, 'activiti:Script'); } function isList(elem) { return is(elem, 'activiti:List'); } function isMap(elem) { return is(elem, 'activiti:Map'); } function ensureInputOutputSupported(element, insideConnector) { return inputOutputHelper.isInputOutputSupported(element, insideConnector); } module.exports = function(element, bpmnFactory, options, translate) { var typeInfo = { 'activiti:Map': { value: 'map', label: translate('Map') }, 'activiti:List': { value: 'list', label: translate('List') }, 'activiti:Script': { value: 'script', label: translate('Script') } }; options = options || {}; var insideConnector = !!options.insideConnector, idPrefix = options.idPrefix || ''; var getSelected = options.getSelectedParameter; if (!ensureInputOutputSupported(element, insideConnector)) { return []; } var entries = []; var isSelected = function(element, node) { return getSelected(element, node); }; // parameter name //////////////////////////////////////////////////////// entries.push(entryFactory.validationAwareTextField({ id: idPrefix + 'parameterName', label: translate('Name'), modelProperty: 'name', getProperty: function(element, node) { return (getSelected(element, node) || {}).name; }, setProperty: function(element, values, node) { var param = getSelected(element, node); return cmdHelper.updateBusinessObject(element, param, values); }, validate: function(element, values, node) { var bo = getSelected(element, node); var validation = {}; if (bo) { var nameValue = values.name; if (nameValue) { if (utils.containsSpace(nameValue)) { validation.name = translate('Name must not contain spaces'); } } else { validation.name = translate('Parameter must have a name'); } } return validation; }, hidden: function(element, node) { return !isSelected(element, node); } })); // parameter type ////////////////////////////////////////////////////// var selectOptions = [ { value: 'text', name: translate('Text') }, { value: 'script', name: translate('Script') }, { value: 'list', name: translate('List') }, { value: 'map', name: translate('Map') } ]; entries.push(entryFactory.selectBox({ id : idPrefix + 'parameterType', label: translate('Type'), selectOptions: selectOptions, modelProperty: 'parameterType', get: function(element, node) { var bo = getSelected(element, node); var parameterType = 'text'; if (typeof bo !== 'undefined') { var definition = bo.get('definition'); if (typeof definition !== 'undefined') { var type = definition.$type; parameterType = typeInfo[type].value; } } return { parameterType: parameterType }; }, set: function(element, values, node) { var bo = getSelected(element, node); var properties = { value: undefined, definition: undefined }; var createParameterTypeElem = function(type) { return createElement(type, bo, bpmnFactory); }; var parameterType = values.parameterType; if (parameterType === 'script') { properties.definition = createParameterTypeElem('activiti:Script'); } else if (parameterType === 'list') { properties.definition = createParameterTypeElem('activiti:List'); } else if (parameterType === 'map') { properties.definition = createParameterTypeElem('activiti:Map'); } return cmdHelper.updateBusinessObject(element, bo, properties); }, show: function(element, node) { return isSelected(element, node); } })); // parameter value (type = text) /////////////////////////////////////////////////////// entries.push(entryFactory.textBox({ id : idPrefix + 'parameterType-text', label : translate('Value'), modelProperty: 'value', get: function(element, node) { return { value: (getSelected(element, node) || {}).value }; }, set: function(element, values, node) { var param = getSelected(element, node); values.value = values.value || undefined; return cmdHelper.updateBusinessObject(element, param, values); }, show: function(element, node) { var bo = getSelected(element, node); return bo && !bo.definition; } })); // parameter value (type = script) /////////////////////////////////////////////////////// var script = scriptImplementation('scriptFormat', 'value', true, translate); entries.push({ id: idPrefix + 'parameterType-script', html: '