;(function() { RED.editor.registerEditPane("editor-tab-appearance", function(node) { return { label: RED._("editor-tab.appearance"), name: RED._("editor-tab.appearance"), iconClass: "fa fa-object-group", create: function(container) { this.content = container; buildAppearanceForm(this.content,node); if (node.type === 'subflow') { this.defaultIcon = "node-red/subflow.svg"; } else { var iconPath = RED.utils.getDefaultNodeIcon(node._def,node); this.defaultIcon = iconPath.module+"/"+iconPath.file; if (node.icon && node.icon !== this.defaultIcon) { this.isDefaultIcon = false; } else { this.isDefaultIcon = true; } } }, resize: function(size) { }, close: function() { }, show: function() { refreshLabelForm(this.content, node); }, apply: function(editState) { if (updateLabels(node, editState.changes, editState.outputMap)) { editState.changed = true; } if (!node._def.defaults || !node._def.defaults.hasOwnProperty("icon")) { var icon = $("#red-ui-editor-node-icon").val()||""; if (!this.isDefaultIcon) { if ((node.icon && icon !== node.icon) || (!node.icon && icon !== "")) { editState.changes.icon = node.icon; node.icon = icon; editState.changed = true; } } else { if (icon !== "" && icon !== this.defaultIcon) { editState.changes.icon = node.icon; node.icon = icon; editState.changed = true; } else { var iconPath = RED.utils.getDefaultNodeIcon(node._def, node); var currentDefaultIcon = iconPath.module+"/"+iconPath.file; if (this.defaultIcon !== currentDefaultIcon) { editState.changes.icon = node.icon; node.icon = currentDefaultIcon; editState.changed = true; } } } } if (node.type === "subflow") { var newCategory = $("#subflow-appearance-input-category").val().trim(); if (newCategory === "_custom_") { newCategory = $("#subflow-appearance-input-custom-category").val().trim(); if (newCategory === "") { newCategory = node.category; } } if (newCategory === 'subflows') { newCategory = ''; } if (newCategory != node.category) { editState.changes['category'] = node.category; node.category = newCategory; editState.changed = true; } var oldColor = node.color; var newColor = $("#red-ui-editor-node-color").val(); if (oldColor !== newColor) { editState.changes.color = node.color; node.color = newColor; editState.changed = true; RED.utils.clearNodeColorCache(); if (node.type === "subflow") { var nodeDefinition = RED.nodes.getType( "subflow:" + node.id ); nodeDefinition["color"] = newColor; } } } var showLabel = node._def.hasOwnProperty("showLabel")?node._def.showLabel:true; if (!$("#node-input-show-label").prop('checked')) { // Not checked - hide label if (showLabel) { // Default to show label if (node.l !== false) { editState.changes.l = node.l; editState.changed = true; } node.l = false; } else { // Node has showLabel:false (eg link nodes) if (node.hasOwnProperty('l') && node.l) { editState.changes.l = node.l; editState.changed = true; } delete node.l; } } else { // Checked - show label if (showLabel) { // Default to show label if (node.hasOwnProperty('l') && !node.l) { editState.changes.l = node.l; editState.changed = true; } delete node.l; } else { if (!node.l) { editState.changes.l = node.l; editState.changed = true; } node.l = true; } } } }; }); function buildAppearanceForm(container,node) { var dialogForm = $('
').appendTo(container); var i,row; if (node.type === "subflow") { var categoryRow = $("", { class: "form-row" }).appendTo(dialogForm); $("", { for: "subflow-appearance-input-category", "data-i18n": "editor:subflow.category" }).appendTo(categoryRow); var categorySelector = $("", { id: "subflow-appearance-input-category" }).css({ width: "250px" }).appendTo(categoryRow); $("", { type: "text", id: "subflow-appearance-input-custom-category" }).css({ display: "none", "margin-left": "10px", width: "calc(100% - 250px)" }).appendTo(categoryRow); var categories = RED.palette.getCategories(); categories.sort(function(A,B) { return A.label.localeCompare(B.label); }); categories.forEach(function(cat) { categorySelector.append($("").val(cat.id).text(cat.label)); }); categorySelector.append($("").attr('disabled',true).text("---")); categorySelector.append($("").val("_custom_").text(RED._("palette.addCategory"))); $("#subflow-appearance-input-category").on("change", function() { var val = $(this).val(); if (val === "_custom_") { $("#subflow-appearance-input-category").width(120); $("#subflow-appearance-input-custom-category").show(); } else { $("#subflow-appearance-input-category").width(250); $("#subflow-appearance-input-custom-category").hide(); } }); $("#subflow-appearance-input-category").val(node.category||"subflows"); var userCount = 0; var subflowType = "subflow:"+node.id; // RED.nodes.eachNode(function(n) { // if (n.type === subflowType) { // userCount++; // } // }); $("#red-ui-editor-subflow-user-count") .text(RED._("subflow.subflowInstances", {count:node.instances.length})).show(); } $('