mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Enable config node dialog to have editor ui
This commit is contained in:
parent
a0aee2021d
commit
12b95f1c72
@ -15,6 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
RED.editor = (function() {
|
RED.editor = (function() {
|
||||||
var editing_node = null;
|
var editing_node = null;
|
||||||
|
var editing_config_node = null;
|
||||||
var subflowEditor;
|
var subflowEditor;
|
||||||
|
|
||||||
function getCredentialsURL(nodeType, nodeID) {
|
function getCredentialsURL(nodeType, nodeID) {
|
||||||
@ -668,7 +669,7 @@ RED.editor = (function() {
|
|||||||
function showEditConfigNodeDialog(name,type,id) {
|
function showEditConfigNodeDialog(name,type,id) {
|
||||||
var adding = (id == "_ADD_");
|
var adding = (id == "_ADD_");
|
||||||
var node_def = RED.nodes.getType(type);
|
var node_def = RED.nodes.getType(type);
|
||||||
var configNode = RED.nodes.node(id);
|
editing_config_node = RED.nodes.node(id);
|
||||||
|
|
||||||
var ns;
|
var ns;
|
||||||
if (node_def.set.module === "node-red") {
|
if (node_def.set.module === "node-red") {
|
||||||
@ -682,8 +683,8 @@ RED.editor = (function() {
|
|||||||
activeWorkspace = RED.nodes.subflow(RED.workspaces.active());
|
activeWorkspace = RED.nodes.subflow(RED.workspaces.active());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configNode == null) {
|
if (editing_config_node == null) {
|
||||||
configNode = {
|
editing_config_node = {
|
||||||
id: (1+Math.random()*4294967295).toString(16),
|
id: (1+Math.random()*4294967295).toString(16),
|
||||||
_def: node_def,
|
_def: node_def,
|
||||||
type: type,
|
type: type,
|
||||||
@ -692,10 +693,10 @@ RED.editor = (function() {
|
|||||||
}
|
}
|
||||||
for (var d in node_def.defaults) {
|
for (var d in node_def.defaults) {
|
||||||
if (node_def.defaults[d].value) {
|
if (node_def.defaults[d].value) {
|
||||||
configNode[d] = node_def.defaults[d].value;
|
editing_config_node[d] = node_def.defaults[d].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configNode["_"] = node_def._;
|
editing_config_node["_"] = node_def._;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#node-config-dialog-edit-form").html($("script[data-template-name='"+type+"']").html());
|
$("#node-config-dialog-edit-form").html($("script[data-template-name='"+type+"']").html());
|
||||||
@ -714,7 +715,7 @@ RED.editor = (function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
prepareEditDialog(configNode,node_def,"node-config-input");
|
prepareEditDialog(editing_config_node,node_def,"node-config-input");
|
||||||
|
|
||||||
var buttons = $( "#node-config-dialog" ).dialog("option","buttons");
|
var buttons = $( "#node-config-dialog" ).dialog("option","buttons");
|
||||||
if (adding) {
|
if (adding) {
|
||||||
@ -732,24 +733,24 @@ RED.editor = (function() {
|
|||||||
var configProperty = $(this).dialog('option','node-property');
|
var configProperty = $(this).dialog('option','node-property');
|
||||||
var configId = $(this).dialog('option','node-id');
|
var configId = $(this).dialog('option','node-id');
|
||||||
var configType = $(this).dialog('option','node-type');
|
var configType = $(this).dialog('option','node-type');
|
||||||
var configNode = RED.nodes.node(configId);
|
|
||||||
var configTypeDef = RED.nodes.getType(configType);
|
var configTypeDef = RED.nodes.getType(configType);
|
||||||
|
|
||||||
if (configTypeDef.ondelete) {
|
if (configTypeDef.ondelete) {
|
||||||
configTypeDef.ondelete.call(RED.nodes.node(configId));
|
configTypeDef.ondelete.call(editing_config_node);
|
||||||
}
|
}
|
||||||
if (configTypeDef.oneditdelete) {
|
if (configTypeDef.oneditdelete) {
|
||||||
configTypeDef.oneditdelete.call(RED.nodes.node(configId));
|
configTypeDef.oneditdelete.call(editing_config_node);
|
||||||
}
|
}
|
||||||
var historyEvent = {
|
var historyEvent = {
|
||||||
t:'delete',
|
t:'delete',
|
||||||
nodes:[configNode],
|
nodes:[editing_config_node],
|
||||||
changes: {},
|
changes: {},
|
||||||
dirty: RED.nodes.dirty()
|
dirty: RED.nodes.dirty()
|
||||||
}
|
}
|
||||||
RED.nodes.remove(configId);
|
RED.nodes.remove(configId);
|
||||||
for (var i=0;i<configNode.users.length;i++) {
|
for (var i=0;i<editing_config_node.users.length;i++) {
|
||||||
var user = configNode.users[i];
|
var user = editing_config_node.users[i];
|
||||||
historyEvent.changes[user.id] = {
|
historyEvent.changes[user.id] = {
|
||||||
changed: user.changed,
|
changed: user.changed,
|
||||||
valid: user.valid
|
valid: user.valid
|
||||||
@ -773,10 +774,10 @@ RED.editor = (function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
buttons[1].text = "Update";
|
buttons[1].text = "Update";
|
||||||
$("#node-config-dialog-user-count").find("span").html(RED._("editor.nodesUse", {count:configNode.users.length})).parent().show();
|
$("#node-config-dialog-user-count").find("span").html(RED._("editor.nodesUse", {count:editing_config_node.users.length})).parent().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configNode._def.exclusive) {
|
if (editing_config_node._def.exclusive) {
|
||||||
$("#node-config-dialog-scope").hide();
|
$("#node-config-dialog-scope").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#node-config-dialog-scope").show();
|
$("#node-config-dialog-scope").show();
|
||||||
@ -785,21 +786,21 @@ RED.editor = (function() {
|
|||||||
|
|
||||||
|
|
||||||
var nodeUserFlows = {};
|
var nodeUserFlows = {};
|
||||||
configNode.users.forEach(function(n) {
|
editing_config_node.users.forEach(function(n) {
|
||||||
nodeUserFlows[n.z] = true;
|
nodeUserFlows[n.z] = true;
|
||||||
});
|
});
|
||||||
var flowCount = Object.keys(nodeUserFlows).length;
|
var flowCount = Object.keys(nodeUserFlows).length;
|
||||||
|
|
||||||
var tabSelect = $("#node-config-dialog-scope").empty();
|
var tabSelect = $("#node-config-dialog-scope").empty();
|
||||||
tabSelect.off("change");
|
tabSelect.off("change");
|
||||||
tabSelect.append('<option value=""'+(!configNode.z?" selected":"")+' data-i18n="sidebar.config.global"></option>');
|
tabSelect.append('<option value=""'+(!editing_config_node.z?" selected":"")+' data-i18n="sidebar.config.global"></option>');
|
||||||
tabSelect.append('<option disabled data-i18n="sidebar.config.flows"></option>');
|
tabSelect.append('<option disabled data-i18n="sidebar.config.flows"></option>');
|
||||||
RED.nodes.eachWorkspace(function(ws) {
|
RED.nodes.eachWorkspace(function(ws) {
|
||||||
var workspaceLabel = ws.label;
|
var workspaceLabel = ws.label;
|
||||||
if (nodeUserFlows[ws.id]) {
|
if (nodeUserFlows[ws.id]) {
|
||||||
workspaceLabel = "* "+workspaceLabel;
|
workspaceLabel = "* "+workspaceLabel;
|
||||||
}
|
}
|
||||||
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==configNode.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==editing_config_node.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
||||||
});
|
});
|
||||||
tabSelect.append('<option disabled data-i18n="sidebar.config.subflows"></option>');
|
tabSelect.append('<option disabled data-i18n="sidebar.config.subflows"></option>');
|
||||||
RED.nodes.eachSubflow(function(ws) {
|
RED.nodes.eachSubflow(function(ws) {
|
||||||
@ -807,7 +808,7 @@ RED.editor = (function() {
|
|||||||
if (nodeUserFlows[ws.id]) {
|
if (nodeUserFlows[ws.id]) {
|
||||||
workspaceLabel = "* "+workspaceLabel;
|
workspaceLabel = "* "+workspaceLabel;
|
||||||
}
|
}
|
||||||
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==configNode.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==editing_config_node.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
||||||
});
|
});
|
||||||
if (flowCount > 0) {
|
if (flowCount > 0) {
|
||||||
tabSelect.on('change',function() {
|
tabSelect.on('change',function() {
|
||||||
@ -834,7 +835,7 @@ RED.editor = (function() {
|
|||||||
$( "#node-config-dialog" )
|
$( "#node-config-dialog" )
|
||||||
.dialog("option","node-adding",adding)
|
.dialog("option","node-adding",adding)
|
||||||
.dialog("option","node-property",name)
|
.dialog("option","node-property",name)
|
||||||
.dialog("option","node-id",configNode.id)
|
.dialog("option","node-id",editing_config_node.id)
|
||||||
.dialog("option","node-type",type)
|
.dialog("option","node-type",type)
|
||||||
.dialog("option","title",(adding?RED._("editor.addNewConfig", {type:type}):RED._("editor.editConfig", {type:type})))
|
.dialog("option","title",(adding?RED._("editor.addNewConfig", {type:type}):RED._("editor.editConfig", {type:type})))
|
||||||
.dialog( "open" );
|
.dialog( "open" );
|
||||||
@ -910,46 +911,29 @@ RED.editor = (function() {
|
|||||||
var configType = $(this).dialog('option','node-type');
|
var configType = $(this).dialog('option','node-type');
|
||||||
var configAdding = $(this).dialog('option','node-adding');
|
var configAdding = $(this).dialog('option','node-adding');
|
||||||
var configTypeDef = RED.nodes.getType(configType);
|
var configTypeDef = RED.nodes.getType(configType);
|
||||||
var configNode;
|
|
||||||
var d;
|
var d;
|
||||||
var input;
|
var input;
|
||||||
var scope = $("#node-config-dialog-scope").val();
|
var scope = $("#node-config-dialog-scope").val();
|
||||||
if (configAdding) {
|
|
||||||
configNode = {type:configType,id:configId,users:[]};
|
|
||||||
for (d in configTypeDef.defaults) {
|
for (d in configTypeDef.defaults) {
|
||||||
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
||||||
input = $("#node-config-input-"+d);
|
input = $("#node-config-input-"+d);
|
||||||
if (input.attr('type') === "checkbox") {
|
if (input.attr('type') === "checkbox") {
|
||||||
configNode[d] = input.prop('checked');
|
editing_config_node[d] = input.prop('checked');
|
||||||
} else {
|
} else {
|
||||||
configNode[d] = input.val();
|
editing_config_node[d] = input.val();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
configNode.label = configTypeDef.label;
|
|
||||||
configNode._def = configTypeDef;
|
|
||||||
configNode.z = scope;
|
|
||||||
RED.nodes.add(configNode);
|
|
||||||
updateConfigNodeSelect(configProperty,configType,configNode.id);
|
|
||||||
} else {
|
|
||||||
configNode = RED.nodes.node(configId);
|
|
||||||
for (d in configTypeDef.defaults) {
|
|
||||||
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
|
||||||
input = $("#node-config-input-"+d);
|
|
||||||
if (input.attr('type') === "checkbox") {
|
|
||||||
configNode[d] = input.prop('checked');
|
|
||||||
} else {
|
|
||||||
configNode[d] = input.val();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
editing_config_node.label = configTypeDef.label;
|
||||||
|
editing_config_node.z = scope;
|
||||||
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
configNode.users = configNode.users.filter(function(n) {
|
editing_config_node.users = editing_config_node.users.filter(function(n) {
|
||||||
var keep = true;
|
var keep = true;
|
||||||
for (var d in n._def.defaults) {
|
for (var d in n._def.defaults) {
|
||||||
if (n._def.defaults.hasOwnProperty(d)) {
|
if (n._def.defaults.hasOwnProperty(d)) {
|
||||||
if (n._def.defaults[d].type === configNode.type &&
|
if (n._def.defaults[d].type === editing_config_node.type &&
|
||||||
n[d] === configNode.id &&
|
n[d] === editing_config_node.id &&
|
||||||
n.z !== scope) {
|
n.z !== scope) {
|
||||||
keep = false;
|
keep = false;
|
||||||
n[d] = null;
|
n[d] = null;
|
||||||
@ -962,18 +946,22 @@ RED.editor = (function() {
|
|||||||
return keep;
|
return keep;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
configNode.z = scope;
|
|
||||||
updateConfigNodeSelect(configProperty,configType,configId);
|
if (configAdding) {
|
||||||
|
RED.nodes.add(editing_config_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateConfigNodeSelect(configProperty,configType,editing_config_node.id);
|
||||||
|
|
||||||
if (configTypeDef.credentials) {
|
if (configTypeDef.credentials) {
|
||||||
updateNodeCredentials(configNode,configTypeDef.credentials,"node-config-input");
|
updateNodeCredentials(editing_config_node,configTypeDef.credentials,"node-config-input");
|
||||||
}
|
}
|
||||||
if (configTypeDef.oneditsave) {
|
if (configTypeDef.oneditsave) {
|
||||||
configTypeDef.oneditsave.call(RED.nodes.node(configId));
|
configTypeDef.oneditsave.call(editing_config_node);
|
||||||
}
|
}
|
||||||
validateNode(configNode);
|
validateNode(editing_config_node);
|
||||||
for (var i=0;i<configNode.users.length;i++) {
|
for (var i=0;i<editing_config_node.users.length;i++) {
|
||||||
var user = configNode.users[i];
|
var user = editing_config_node.users[i];
|
||||||
validateNode(user);
|
validateNode(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user