1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow config select input to override default width

This commit is contained in:
Nick O'Leary 2016-04-25 20:42:11 +01:00
parent 1b06afb81c
commit 71b2e714ee

View File

@ -183,11 +183,24 @@ RED.editor = (function() {
*/ */
function prepareConfigNodeSelect(node,property,type,prefix) { function prepareConfigNodeSelect(node,property,type,prefix) {
var input = $("#"+prefix+"-"+property); var input = $("#"+prefix+"-"+property);
var node_def = RED.nodes.getType(type); if (input.length === 0 ) {
return;
input.replaceWith('<select style="width: 60%;" id="'+prefix+'-'+property+'"></select>'); }
var existingWidthCSS = input[0].style.width;
var newWidth;
if (existingWidthCSS !== '') {
if (/%/.test(existingWidthCSS)) {
newWidth = (input.width()-10)+"%";
} else {
newWidth = input.width()-50;
}
} else {
newWidth = "60%";
}
var select = $('<select id="'+prefix+'-'+property+'"></select>');
select.width(newWidth);
input.replaceWith(select);
updateConfigNodeSelect(property,type,node[property],prefix); updateConfigNodeSelect(property,type,node[property],prefix);
var select = $("#"+prefix+"-"+property);
select.after(' <a id="'+prefix+'-lookup-'+property+'" class="editor-button"><i class="fa fa-pencil"></i></a>'); select.after(' <a id="'+prefix+'-lookup-'+property+'" class="editor-button"><i class="fa fa-pencil"></i></a>');
$('#'+prefix+'-lookup-'+property).click(function(e) { $('#'+prefix+'-lookup-'+property).click(function(e) {
showEditConfigNodeDialog(property,type,select.find(":selected").val(),prefix); showEditConfigNodeDialog(property,type,select.find(":selected").val(),prefix);
@ -195,6 +208,8 @@ RED.editor = (function() {
}); });
var label = ""; var label = "";
var configNode = RED.nodes.node(node[property]); var configNode = RED.nodes.node(node[property]);
var node_def = RED.nodes.getType(type);
if (configNode && node_def.label) { if (configNode && node_def.label) {
if (typeof node_def.label == "function") { if (typeof node_def.label == "function") {
label = node_def.label.call(configNode); label = node_def.label.call(configNode);