RED.editor.envVarList = (function() { var currentLocale = 'en-US'; var DEFAULT_ENV_TYPE_LIST = ['str','num','bool','json','bin','env']; var DEFAULT_ENV_TYPE_LIST_INC_CRED = ['str','num','bool','json','bin','env','cred','jsonata']; /** * Create env var edit interface * @param container - container * @param node - subflow node */ function buildPropertiesList(envContainer, node) { var isTemplateNode = (node.type === "subflow"); envContainer .css({ 'min-height':'150px', 'min-width':'450px' }) .editableList({ header: isTemplateNode?$('
'):undefined, addItem: function(container, i, opt) { // If this is an instance node, these are properties unique to // this instance - ie opt.parent will not be defined. if (isTemplateNode) { container.addClass("red-ui-editor-subflow-env-editable") } var envRow = $('
').appendTo(container); var nameField = null; var valueField = null; nameField = $('', { class: "node-input-env-name", type: "text", placeholder: RED._("common.label.name") }).attr("autocomplete","disable").appendTo(envRow).val(opt.name); valueField = $('',{ style: "width:100%", class: "node-input-env-value", type: "text", }).attr("autocomplete","disable").appendTo(envRow); var types = (opt.ui && opt.ui.opts && opt.ui.opts.types); if (!types) { types = isTemplateNode ? DEFAULT_ENV_TYPE_LIST : DEFAULT_ENV_TYPE_LIST_INC_CRED; } valueField.typedInput({default:'str',types:types}); valueField.typedInput('type', opt.type); if (opt.type === "cred") { if (opt.value) { valueField.typedInput('value', opt.value); } else if (node.credentials && node.credentials[opt.name]) { valueField.typedInput('value', node.credentials[opt.name]); } else if (node.credentials && node.credentials['has_'+opt.name]) { valueField.typedInput('value', "__PWRD__"); } else { valueField.typedInput('value', ""); } } else { valueField.typedInput('value', opt.value); } opt.nameField = nameField; opt.valueField = valueField; var actionButton = $('',{href:"#",class:"red-ui-editableList-item-remove red-ui-button red-ui-button-small"}).appendTo(envRow); $('',{class:"fa "+(opt.parent?"fa-reply":"fa-remove")}).appendTo(actionButton); var removeTip = RED.popover.tooltip(actionButton,RED._("subflow.env.remove")); actionButton.on("click", function(evt) { evt.preventDefault(); removeTip.close(); container.parent().addClass("red-ui-editableList-item-deleting") container.fadeOut(300, function() { envContainer.editableList('removeItem',opt); }); }); if (isTemplateNode) { // Add the UI customisation row // if `opt.ui` does not exist, then apply defaults. If these // defaults do not change then they will get stripped off // before saving. if (opt.type === 'cred') { opt.ui = opt.ui || { icon: "", type: "cred" } opt.ui.type = "cred"; } else { opt.ui = opt.ui || { icon: "", type: "input", opts: {types:DEFAULT_ENV_TYPE_LIST} } } opt.ui.label = opt.ui.label || {}; opt.ui.type = opt.ui.type || "input"; if ((opt.ui.type === "cred") && opt.ui.opts && opt.ui.opts.types) { opt.ui.type = "input"; } var uiRow = $('
').appendTo(container).hide(); // save current info for reverting on cancel // var copy = $.extend(true, {}, ui); $('').prependTo(envRow).on("click", function (evt) { evt.preventDefault(); if ($(this).hasClass('expanded')) { uiRow.slideUp(); $(this).removeClass('expanded'); } else { uiRow.slideDown(); $(this).addClass('expanded'); } }); buildEnvEditRow(uiRow, opt.ui, nameField, valueField); nameField.trigger('change'); } }, sortable: ".red-ui-editableList-item-handle", removable: false }); var parentEnv = {}; var envList = []; if (/^subflow:/.test(node.type)) { var subflowDef = RED.nodes.subflow(node.type.substring(8)); if (subflowDef.env) { subflowDef.env.forEach(function(env) { var item = { name:env.name, parent: { type: env.type, value: env.value, ui: env.ui } } envList.push(item); parentEnv[env.name] = item; }) } } if (node.env) { for (var i = 0; i < node.env.length; i++) { var env = node.env[i]; if (parentEnv.hasOwnProperty(env.name)) { parentEnv[env.name].type = env.type; parentEnv[env.name].value = env.value; } else { envList.push({ name: env.name, type: env.type, value: env.value, ui: env.ui }); } } } envList.forEach(function(env) { if (env.parent && env.parent.ui && env.parent.ui.type === 'hide') { return; } if (!isTemplateNode && env.parent) { return; } envContainer.editableList('addItem', JSON.parse(JSON.stringify(env))); }); } /** * Create UI edit interface for environment variable * @param container - container * @param env - env var definition * @param nameField - name field of env var * @param valueField - value field of env var */ function buildEnvEditRow(container, ui, nameField, valueField) { container.addClass("red-ui-editor-subflow-env-ui-row") var topRow = $('
').appendTo(container); $('
').appendTo(topRow); $('
').text(RED._("editor.icon")).appendTo(topRow); $('
').text(RED._("editor.label")).appendTo(topRow); $('
').text(RED._("editor.inputType")).appendTo(topRow); var row = $('
').appendTo(container); $('
').appendTo(row); var typeOptions = { 'input': {types:DEFAULT_ENV_TYPE_LIST}, 'select': {opts:[]}, 'spinner': {}, 'cred': {} }; if (ui.opts) { typeOptions[ui.type] = ui.opts; } else { // Pick up the default values if not otherwise provided ui.opts = typeOptions[ui.type]; } var iconCell = $('
').appendTo(row); var iconButton = $('').appendTo(iconCell); iconButton.on("click", function(evt) { evt.preventDefault(); var icon = ui.icon || ""; var iconPath = (icon ? RED.utils.separateIconPath(icon) : {}); RED.editor.iconPicker.show(iconButton, null, iconPath, true, function (newIcon) { iconButton.empty(); var path = newIcon || ""; var newPath = RED.utils.separateIconPath(path); if (newPath) { $('').addClass(newPath.file).appendTo(iconButton); } ui.icon = path; }); }) if (ui.icon) { var newPath = RED.utils.separateIconPath(ui.icon); $('').appendTo(iconButton); } var labelCell = $('
').appendTo(row); var label = ui.label && ui.label[currentLocale] || ""; var labelInput = $('').val(label).appendTo(labelCell); ui.labelField = labelInput; labelInput.on('change', function(evt) { ui.label = ui.label || {}; var val = $(this).val().trim(); if (val === "") { delete ui.label[currentLocale]; } else { ui.label[currentLocale] = val; } }) var labelIcon = $('').appendTo(labelCell); RED.popover.tooltip(labelIcon,function() { var langs = Object.keys(ui.label); var content = $("
"); if (langs.indexOf(currentLocale) === -1) { langs.push(currentLocale); langs.sort(); } langs.forEach(function(l) { var row = $('
').appendTo(content); $('').css({display:"inline-block",width:"120px"}).text(RED._("languages."+l)+(l===currentLocale?"*":"")).appendTo(row); $('').text(ui.label[l]||"").appendTo(row); }); return content; }) nameField.on('change',function(evt) { labelInput.attr("placeholder",$(this).val()) }); var inputCell = $('
').appendTo(row); var inputCellInput = $('').css("width","100%").appendTo(inputCell); if (ui.type === "input") { inputCellInput.val(ui.opts.types.join(",")); } var checkbox; var selectBox; inputCellInput.typedInput({ types: [ { value:"input", label:RED._("editor.inputs.input"), icon:"fa fa-i-cursor",showLabel:false,multiple:true,options:[ {value:"str",label:RED._("editor.types.str"),icon:"red/images/typedInput/az.svg"}, {value:"num",label:RED._("editor.types.num"),icon:"red/images/typedInput/09.svg"}, {value:"bool",label:RED._("editor.types.bool"),icon:"red/images/typedInput/bool.svg"}, {value:"json",label:RED._("editor.types.json"),icon:"red/images/typedInput/json.svg"}, {value: "bin",label: RED._("editor.types.bin"),icon: "red/images/typedInput/bin.svg"}, {value: "env",label: RED._("editor.types.env"),icon: "red/images/typedInput/env.svg"}, {value: "cred",label: RED._("editor.types.cred"),icon: "fa fa-lock"} ], default: DEFAULT_ENV_TYPE_LIST, valueLabel: function(container,value) { container.css("padding",0); var innerContainer = $('
').appendTo(container); var input = $('
').appendTo(innerContainer); $('').appendTo(input); if (value.length) { value.forEach(function(v) { if (!/^fa /.test(v.icon)) { $('',{src:v.icon,style:"max-width:14px; padding: 0 3px; margin-top:-4px; margin-left: 1px"}).appendTo(input); } else { var s = $('',{style:"max-width:14px; padding: 0 3px; margin-top:-4px; margin-left: 1px"}).appendTo(input); $("",{class: v.icon}).appendTo(s); } }) } else { $('').text(RED._("editor.selectType")).appendTo(input); } } }, { value: "cred", label: RED._("typedInput.type.cred"), icon:"fa fa-lock", showLabel: false, valueLabel: function(container,value) { container.css("padding",0); var innerContainer = $('
').css({ "border-top-right-radius": "4px", "border-bottom-right-radius": "4px" }).appendTo(container); $('
').html("••••••••").appendTo(innerContainer); } }, { value:"select", label:RED._("editor.inputs.select"), icon:"fa fa-tasks",showLabel:false, valueLabel: function(container,value) { container.css("padding","0"); selectBox = $('').appendTo(container); if (ui.opts && Array.isArray(ui.opts.opts)) { ui.opts.opts.forEach(function(o) { var label = lookupLabel(o.l, o.l["en-US"]||o.v, currentLocale); // $('