mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add support for exclusive config nodes
This commit is contained in:
parent
7dc838dea6
commit
913fdac671
@ -379,6 +379,32 @@ RED.editor = (function() {
|
|||||||
}
|
}
|
||||||
input.val(label);
|
input.val(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a config-node button for this property
|
||||||
|
* @param node - the node being edited
|
||||||
|
* @param property - the name of the field
|
||||||
|
* @param type - the type of the config-node
|
||||||
|
*/
|
||||||
|
function prepareConfigNodeButton(node,property,type) {
|
||||||
|
var input = $("#node-input-"+property);
|
||||||
|
input.val(node[property]);
|
||||||
|
input.attr("type","hidden");
|
||||||
|
|
||||||
|
var button = $("<a>",{id:"node-input-edit-"+property, class:"btn"});
|
||||||
|
input.after(button);
|
||||||
|
|
||||||
|
if (node[property]) {
|
||||||
|
button.text("edit");
|
||||||
|
} else {
|
||||||
|
button.text("add");
|
||||||
|
}
|
||||||
|
|
||||||
|
button.click(function(e) {
|
||||||
|
showEditConfigNodeDialog(property,type,input.val()||"_ADD_");
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate the editor dialog input field for this property
|
* Populate the editor dialog input field for this property
|
||||||
@ -493,7 +519,11 @@ RED.editor = (function() {
|
|||||||
for (var d in definition.defaults) {
|
for (var d in definition.defaults) {
|
||||||
if (definition.defaults.hasOwnProperty(d)) {
|
if (definition.defaults.hasOwnProperty(d)) {
|
||||||
if (definition.defaults[d].type) {
|
if (definition.defaults[d].type) {
|
||||||
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
|
if (definition.defaults[d].exclusive) {
|
||||||
|
prepareConfigNodeButton(node,d,definition.defaults[d].type);
|
||||||
|
} else {
|
||||||
|
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
preparePropertyEditor(node,d,prefix);
|
preparePropertyEditor(node,d,prefix);
|
||||||
}
|
}
|
||||||
@ -633,25 +663,36 @@ RED.editor = (function() {
|
|||||||
.dialog("option","title",(adding?"Add new ":"Edit ")+type+" config node")
|
.dialog("option","title",(adding?"Add new ":"Edit ")+type+" config node")
|
||||||
.dialog( "open" );
|
.dialog( "open" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConfigNodeSelect(name,type,value) {
|
function updateConfigNodeSelect(name,type,value) {
|
||||||
var select = $("#node-input-"+name);
|
var button = $("#node-input-edit-"+name);
|
||||||
var node_def = RED.nodes.getType(type);
|
if (button.length) {
|
||||||
select.children().remove();
|
if (value) {
|
||||||
RED.nodes.eachConfig(function(config) {
|
button.text("edit");
|
||||||
if (config.type == type) {
|
} else {
|
||||||
var label = "";
|
button.text("add");
|
||||||
if (typeof node_def.label == "function") {
|
|
||||||
label = node_def.label.call(config);
|
|
||||||
} else {
|
|
||||||
label = node_def.label;
|
|
||||||
}
|
|
||||||
select.append('<option value="'+config.id+'"'+(value==config.id?" selected":"")+'>'+label+'</option>');
|
|
||||||
}
|
}
|
||||||
});
|
$("#node-input-"+name).val(value);
|
||||||
|
} else {
|
||||||
select.append('<option value="_ADD_"'+(value===""?" selected":"")+'>Add new '+type+'...</option>');
|
|
||||||
window.setTimeout(function() { select.change();},50);
|
var select = $("#node-input-"+name);
|
||||||
|
var node_def = RED.nodes.getType(type);
|
||||||
|
select.children().remove();
|
||||||
|
RED.nodes.eachConfig(function(config) {
|
||||||
|
if (config.type == type) {
|
||||||
|
var label = "";
|
||||||
|
if (typeof node_def.label == "function") {
|
||||||
|
label = node_def.label.call(config);
|
||||||
|
} else {
|
||||||
|
label = node_def.label;
|
||||||
|
}
|
||||||
|
select.append('<option value="'+config.id+'"'+(value==config.id?" selected":"")+'>'+label+'</option>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
select.append('<option value="_ADD_"'+(value===""?" selected":"")+'>Add new '+type+'...</option>');
|
||||||
|
window.setTimeout(function() { select.change();},50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$( "#node-config-dialog" ).dialog({
|
$( "#node-config-dialog" ).dialog({
|
||||||
|
@ -162,7 +162,7 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
url: {value:"",required:true},
|
url: {value:"",required:true},
|
||||||
method: {value:"get",required:true},
|
method: {value:"get",required:true},
|
||||||
swaggerDoc: {type:"swagger-doc", required:false}
|
swaggerDoc: {type:"swagger-doc", exclusive:true, required:false}
|
||||||
},
|
},
|
||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
|
Loading…
Reference in New Issue
Block a user