2013-09-05 16:02:48 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2013-09-05 16:02:48 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
2014-08-08 01:01:35 +02:00
|
|
|
RED.editor = (function() {
|
2016-01-31 23:27:14 +01:00
|
|
|
|
2016-05-03 16:45:29 +02:00
|
|
|
|
|
|
|
var editStack = [];
|
2013-09-05 16:02:48 +02:00
|
|
|
var editing_node = null;
|
2015-11-06 12:08:07 +01:00
|
|
|
var editing_config_node = null;
|
2015-10-23 23:14:21 +02:00
|
|
|
var subflowEditor;
|
2013-09-05 16:02:48 +02:00
|
|
|
|
2016-04-14 03:07:49 +02:00
|
|
|
var editTrayWidthCache = {};
|
|
|
|
|
2014-05-07 20:19:08 +02:00
|
|
|
function getCredentialsURL(nodeType, nodeID) {
|
|
|
|
var dashedType = nodeType.replace(/\s+/g, '-');
|
|
|
|
return 'credentials/' + dashedType + "/" + nodeID;
|
|
|
|
}
|
2014-05-16 09:34:23 +02:00
|
|
|
|
2014-05-27 17:06:25 +02:00
|
|
|
/**
|
2015-05-07 17:44:55 +02:00
|
|
|
* Validate a node
|
2014-05-27 17:06:25 +02:00
|
|
|
* @param node - the node being validated
|
|
|
|
* @returns {boolean} whether the node is valid. Sets node.dirty if needed
|
|
|
|
*/
|
|
|
|
function validateNode(node) {
|
2015-03-20 00:11:55 +01:00
|
|
|
var oldValue = node.valid;
|
2015-03-20 22:20:04 +01:00
|
|
|
var oldChanged = node.changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
node.valid = true;
|
|
|
|
var subflow;
|
|
|
|
var isValid;
|
2015-03-20 22:20:04 +01:00
|
|
|
var hasChanged;
|
2015-03-20 00:11:55 +01:00
|
|
|
if (node.type.indexOf("subflow:")===0) {
|
|
|
|
subflow = RED.nodes.subflow(node.type.substring(8));
|
|
|
|
isValid = subflow.valid;
|
2015-03-20 22:20:04 +01:00
|
|
|
hasChanged = subflow.changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
if (isValid === undefined) {
|
|
|
|
isValid = validateNode(subflow);
|
2015-03-20 22:20:04 +01:00
|
|
|
hasChanged = subflow.changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
}
|
2018-03-14 05:51:50 +01:00
|
|
|
node.valid = isValid && validateNodeProperties(node, node._def.defaults, node);
|
2015-07-30 12:03:37 +02:00
|
|
|
node.changed = node.changed || hasChanged;
|
2015-03-20 00:11:55 +01:00
|
|
|
} else if (node._def) {
|
2015-03-12 00:37:44 +01:00
|
|
|
node.valid = validateNodeProperties(node, node._def.defaults, node);
|
|
|
|
if (node._def._creds) {
|
|
|
|
node.valid = node.valid && validateNodeProperties(node, node._def.credentials, node._def._creds);
|
|
|
|
}
|
2015-03-20 00:11:55 +01:00
|
|
|
} else if (node.type == "subflow") {
|
|
|
|
var subflowNodes = RED.nodes.filterNodes({z:node.id});
|
|
|
|
for (var i=0;i<subflowNodes.length;i++) {
|
|
|
|
isValid = subflowNodes[i].valid;
|
2015-03-20 22:20:04 +01:00
|
|
|
hasChanged = subflowNodes[i].changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
if (isValid === undefined) {
|
|
|
|
isValid = validateNode(subflowNodes[i]);
|
2015-03-20 22:20:04 +01:00
|
|
|
hasChanged = subflowNodes[i].changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
}
|
|
|
|
node.valid = node.valid && isValid;
|
2015-03-20 22:20:04 +01:00
|
|
|
node.changed = node.changed || hasChanged;
|
2015-03-20 00:11:55 +01:00
|
|
|
}
|
|
|
|
var subflowInstances = RED.nodes.filterNodes({type:"subflow:"+node.id});
|
|
|
|
var modifiedTabs = {};
|
|
|
|
for (i=0;i<subflowInstances.length;i++) {
|
|
|
|
subflowInstances[i].valid = node.valid;
|
2015-07-30 12:03:37 +02:00
|
|
|
subflowInstances[i].changed = subflowInstances[i].changed || node.changed;
|
2015-03-20 00:11:55 +01:00
|
|
|
subflowInstances[i].dirty = true;
|
|
|
|
modifiedTabs[subflowInstances[i].z] = true;
|
|
|
|
}
|
|
|
|
Object.keys(modifiedTabs).forEach(function(id) {
|
|
|
|
var subflow = RED.nodes.subflow(id);
|
|
|
|
if (subflow) {
|
|
|
|
validateNode(subflow);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-03-20 22:20:04 +01:00
|
|
|
if (oldValue !== node.valid || oldChanged !== node.changed) {
|
2015-03-20 00:11:55 +01:00
|
|
|
node.dirty = true;
|
|
|
|
subflow = RED.nodes.subflow(node.z);
|
|
|
|
if (subflow) {
|
|
|
|
validateNode(subflow);
|
2015-03-12 00:37:44 +01:00
|
|
|
}
|
2014-05-27 17:06:25 +02:00
|
|
|
}
|
2015-03-20 00:11:55 +01:00
|
|
|
return node.valid;
|
2014-05-27 17:06:25 +02:00
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2014-05-27 17:06:25 +02:00
|
|
|
/**
|
|
|
|
* Validate a node's properties for the given set of property definitions
|
|
|
|
* @param node - the node being validated
|
|
|
|
* @param definition - the node property definitions (either def.defaults or def.creds)
|
|
|
|
* @param properties - the node property values to validate
|
|
|
|
* @returns {boolean} whether the node's properties are valid
|
|
|
|
*/
|
|
|
|
function validateNodeProperties(node, definition, properties) {
|
|
|
|
var isValid = true;
|
|
|
|
for (var prop in definition) {
|
2014-09-22 14:22:23 +02:00
|
|
|
if (definition.hasOwnProperty(prop)) {
|
|
|
|
if (!validateNodeProperty(node, definition, prop, properties[prop])) {
|
|
|
|
isValid = false;
|
|
|
|
}
|
2014-05-27 17:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
if (node.icon) {
|
|
|
|
var iconPath = RED.utils.separateIconPath(node.icon);
|
2017-12-19 12:11:10 +01:00
|
|
|
if (!iconPath.module) {
|
|
|
|
return isValid;
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconSets = RED.nodes.getIconSets();
|
|
|
|
var iconFileList = iconSets[iconPath.module];
|
|
|
|
if (!iconFileList || iconFileList.indexOf(iconPath.file) === -1) {
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-27 17:06:25 +02:00
|
|
|
return isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a individual node property
|
|
|
|
* @param node - the node being validated
|
|
|
|
* @param definition - the node property definitions (either def.defaults or def.creds)
|
|
|
|
* @param property - the property name being validated
|
|
|
|
* @param value - the property value being validated
|
|
|
|
* @returns {boolean} whether the node proprty is valid
|
|
|
|
*/
|
2014-05-16 09:34:23 +02:00
|
|
|
function validateNodeProperty(node,definition,property,value) {
|
2013-09-05 16:02:48 +02:00
|
|
|
var valid = true;
|
2016-03-13 15:29:36 +01:00
|
|
|
if (/^\$\([a-zA-Z_][a-zA-Z0-9_]*\)$/.test(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-16 09:34:23 +02:00
|
|
|
if ("required" in definition[property] && definition[property].required) {
|
2013-09-05 16:02:48 +02:00
|
|
|
valid = value !== "";
|
|
|
|
}
|
2014-05-16 09:34:23 +02:00
|
|
|
if (valid && "validate" in definition[property]) {
|
2016-07-28 14:27:34 +02:00
|
|
|
try {
|
|
|
|
valid = definition[property].validate.call(node,value);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Validation error:",node.type,node.id,"property: "+property,"value:",value,err);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-05-16 09:34:23 +02:00
|
|
|
if (valid && definition[property].type && RED.nodes.getType(definition[property].type) && !("validate" in definition[property])) {
|
2013-11-17 18:49:32 +01:00
|
|
|
if (!value || value == "_ADD_") {
|
2015-03-09 21:42:23 +01:00
|
|
|
valid = definition[property].hasOwnProperty("required") && !definition[property].required;
|
2013-11-17 18:49:32 +01:00
|
|
|
} else {
|
2016-03-13 14:25:38 +01:00
|
|
|
var configNode = RED.nodes.node(value);
|
|
|
|
valid = (configNode !== null && (configNode.valid == null || configNode.valid));
|
2013-11-17 18:49:32 +01:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2016-04-26 23:00:02 +02:00
|
|
|
|
|
|
|
function validateNodeEditor(node,prefix) {
|
|
|
|
for (var prop in node._def.defaults) {
|
|
|
|
if (node._def.defaults.hasOwnProperty(prop)) {
|
|
|
|
validateNodeEditorProperty(node,node._def.defaults,prop,prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node._def.credentials) {
|
|
|
|
for (prop in node._def.credentials) {
|
|
|
|
if (node._def.credentials.hasOwnProperty(prop)) {
|
|
|
|
validateNodeEditorProperty(node,node._def.credentials,prop,prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 05:51:50 +01:00
|
|
|
validateIcon(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateIcon(node) {
|
2018-01-19 23:48:03 +01:00
|
|
|
if (node._def.hasOwnProperty("defaults") && !node._def.defaults.hasOwnProperty("icon") && node.icon) {
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconPath = RED.utils.separateIconPath(node.icon);
|
|
|
|
var iconSets = RED.nodes.getIconSets();
|
|
|
|
var iconFileList = iconSets[iconPath.module];
|
|
|
|
var iconModule = $("#node-settings-icon-module");
|
|
|
|
var iconFile = $("#node-settings-icon-file");
|
|
|
|
if (!iconFileList) {
|
|
|
|
iconModule.addClass("input-error");
|
|
|
|
iconFile.removeClass("input-error");
|
|
|
|
} else if (iconFileList.indexOf(iconPath.file) === -1) {
|
|
|
|
iconModule.removeClass("input-error");
|
|
|
|
iconFile.addClass("input-error");
|
|
|
|
} else {
|
|
|
|
iconModule.removeClass("input-error");
|
|
|
|
iconFile.removeClass("input-error");
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 23:00:02 +02:00
|
|
|
}
|
2018-03-14 05:51:50 +01:00
|
|
|
|
2016-04-26 23:00:02 +02:00
|
|
|
function validateNodeEditorProperty(node,defaults,property,prefix) {
|
|
|
|
var input = $("#"+prefix+"-"+property);
|
|
|
|
if (input.length > 0) {
|
2016-09-08 21:49:44 +02:00
|
|
|
var value = input.val();
|
|
|
|
if (defaults[property].hasOwnProperty("format") && defaults[property].format !== "" && input[0].nodeName === "DIV") {
|
|
|
|
value = input.text();
|
|
|
|
}
|
2016-09-08 21:46:30 +02:00
|
|
|
if (!validateNodeProperty(node, defaults, property,value)) {
|
2016-04-26 23:00:02 +02:00
|
|
|
input.addClass("input-error");
|
|
|
|
} else {
|
|
|
|
input.removeClass("input-error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 17:06:25 +02:00
|
|
|
/**
|
|
|
|
* Called when the node's properties have changed.
|
|
|
|
* Marks the node as dirty and needing a size check.
|
|
|
|
* Removes any links to non-existant outputs.
|
|
|
|
* @param node - the node that has been updated
|
2016-11-08 18:00:47 +01:00
|
|
|
* @param outputMap - (optional) a map of old->new port numbers if wires should be moved
|
2014-05-27 17:06:25 +02:00
|
|
|
* @returns {array} the links that were removed due to this update
|
|
|
|
*/
|
2016-11-08 18:00:47 +01:00
|
|
|
function updateNodeProperties(node, outputMap) {
|
2013-09-05 16:02:48 +02:00
|
|
|
node.resize = true;
|
|
|
|
node.dirty = true;
|
|
|
|
var removedLinks = [];
|
2014-02-25 00:35:11 +01:00
|
|
|
if (node.ports) {
|
2016-11-08 18:00:47 +01:00
|
|
|
if (outputMap) {
|
|
|
|
RED.nodes.eachLink(function(l) {
|
|
|
|
if (l.source === node && outputMap.hasOwnProperty(l.sourcePort)) {
|
2017-02-07 23:30:54 +01:00
|
|
|
if (outputMap[l.sourcePort] === "-1") {
|
2016-11-08 18:00:47 +01:00
|
|
|
removedLinks.push(l);
|
|
|
|
} else {
|
|
|
|
l.sourcePort = outputMap[l.sourcePort];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
if (node.outputs < node.ports.length) {
|
|
|
|
while (node.outputs < node.ports.length) {
|
|
|
|
node.ports.pop();
|
|
|
|
}
|
|
|
|
RED.nodes.eachLink(function(l) {
|
2016-11-08 18:00:47 +01:00
|
|
|
if (l.source === node && l.sourcePort >= node.outputs && removedLinks.indexOf(l) === -1) {
|
2016-01-04 23:05:17 +01:00
|
|
|
removedLinks.push(l);
|
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
});
|
|
|
|
} else if (node.outputs > node.ports.length) {
|
|
|
|
while (node.outputs > node.ports.length) {
|
|
|
|
node.ports.push(node.ports.length);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
if (node.inputs === 0) {
|
2015-03-16 00:41:16 +01:00
|
|
|
removedLinks.concat(RED.nodes.filterLinks({target:node}));
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
|
|
|
for (var l=0;l<removedLinks.length;l++) {
|
|
|
|
RED.nodes.removeLink(removedLinks[l]);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
return removedLinks;
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
/**
|
|
|
|
* Create a config-node select box for this property
|
|
|
|
* @param node - the node being edited
|
|
|
|
* @param property - the name of the field
|
|
|
|
* @param type - the type of the config-node
|
|
|
|
*/
|
2016-04-19 22:41:26 +02:00
|
|
|
function prepareConfigNodeSelect(node,property,type,prefix) {
|
|
|
|
var input = $("#"+prefix+"-"+property);
|
2016-04-25 21:42:11 +02:00
|
|
|
if (input.length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-27 00:48:59 +02:00
|
|
|
var newWidth = input.width();
|
|
|
|
var attrStyle = input.attr('style');
|
|
|
|
var m;
|
|
|
|
if ((m = /width\s*:\s*(\d+(%|[a-z]+))/i.exec(attrStyle)) !== null) {
|
|
|
|
newWidth = m[1];
|
2016-04-25 21:42:11 +02:00
|
|
|
} else {
|
2016-06-27 00:48:59 +02:00
|
|
|
newWidth = "70%";
|
|
|
|
}
|
|
|
|
var outerWrap = $("<div></div>").css({display:'inline-block',position:'relative'});
|
|
|
|
var selectWrap = $("<div></div>").css({position:'absolute',left:0,right:'40px'}).appendTo(outerWrap);
|
|
|
|
var select = $('<select id="'+prefix+'-'+property+'"></select>').appendTo(selectWrap);
|
|
|
|
|
|
|
|
outerWrap.width(newWidth).height(input.height());
|
|
|
|
if (outerWrap.width() === 0) {
|
|
|
|
outerWrap.width("70%");
|
2016-04-25 21:42:11 +02:00
|
|
|
}
|
2016-06-27 00:48:59 +02:00
|
|
|
input.replaceWith(outerWrap);
|
|
|
|
// set the style attr directly - using width() on FF causes a value of 114%...
|
|
|
|
select.attr('style',"width:100%");
|
2016-04-19 22:41:26 +02:00
|
|
|
updateConfigNodeSelect(property,type,node[property],prefix);
|
2016-06-27 00:48:59 +02:00
|
|
|
$('<a id="'+prefix+'-lookup-'+property+'" class="editor-button"><i class="fa fa-pencil"></i></a>')
|
|
|
|
.css({position:'absolute',right:0,top:0})
|
|
|
|
.appendTo(outerWrap);
|
2016-05-31 14:01:49 +02:00
|
|
|
$('#'+prefix+'-lookup-'+property).click(function(e) {
|
|
|
|
showEditConfigNodeDialog(property,type,select.find(":selected").val(),prefix);
|
2014-05-07 00:42:54 +02:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
var label = "";
|
|
|
|
var configNode = RED.nodes.node(node[property]);
|
2016-04-25 21:42:11 +02:00
|
|
|
var node_def = RED.nodes.getType(type);
|
|
|
|
|
2016-11-22 13:57:08 +01:00
|
|
|
if (configNode) {
|
|
|
|
label = RED.utils.getNodeLabel(configNode,configNode.id);
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
|
|
|
input.val(label);
|
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2015-05-06 12:08:01 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2016-04-19 22:41:26 +02:00
|
|
|
function prepareConfigNodeButton(node,property,type,prefix) {
|
|
|
|
var input = $("#"+prefix+"-"+property);
|
2015-05-06 12:08:01 +02:00
|
|
|
input.val(node[property]);
|
|
|
|
input.attr("type","hidden");
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2016-04-19 22:41:26 +02:00
|
|
|
var button = $("<a>",{id:prefix+"-edit-"+property, class:"editor-button"});
|
2015-05-06 12:08:01 +02:00
|
|
|
input.after(button);
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2015-05-06 12:08:01 +02:00
|
|
|
if (node[property]) {
|
2015-05-22 01:40:27 +02:00
|
|
|
button.text(RED._("editor.configEdit"));
|
2015-05-06 12:08:01 +02:00
|
|
|
} else {
|
2015-05-22 01:40:27 +02:00
|
|
|
button.text(RED._("editor.configAdd"));
|
2015-05-06 12:08:01 +02:00
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2015-05-06 12:08:01 +02:00
|
|
|
button.click(function(e) {
|
2016-04-19 22:41:26 +02:00
|
|
|
showEditConfigNodeDialog(property,type,input.val()||"_ADD_",prefix);
|
2015-05-07 17:44:55 +02:00
|
|
|
e.preventDefault();
|
2015-05-06 12:08:01 +02:00
|
|
|
});
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
/**
|
|
|
|
* Populate the editor dialog input field for this property
|
|
|
|
* @param node - the node being edited
|
|
|
|
* @param property - the name of the field
|
|
|
|
* @param prefix - the prefix to use in the input element ids (node-input|node-config-input)
|
2016-08-26 01:28:22 +02:00
|
|
|
* @param definition - the definition of the field
|
2014-05-07 00:42:54 +02:00
|
|
|
*/
|
2016-08-25 17:47:30 +02:00
|
|
|
function preparePropertyEditor(node,property,prefix,definition) {
|
2014-05-07 00:42:54 +02:00
|
|
|
var input = $("#"+prefix+"-"+property);
|
2016-10-01 00:35:05 +02:00
|
|
|
if (input.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
if (input.attr('type') === "checkbox") {
|
|
|
|
input.prop('checked',node[property]);
|
2016-08-25 18:09:56 +02:00
|
|
|
}
|
2016-08-25 17:47:30 +02:00
|
|
|
else {
|
2014-05-07 00:42:54 +02:00
|
|
|
var val = node[property];
|
|
|
|
if (val == null) {
|
|
|
|
val = "";
|
|
|
|
}
|
2016-09-08 21:49:44 +02:00
|
|
|
if (definition !== undefined && definition[property].hasOwnProperty("format") && definition[property].format !== "" && input[0].nodeName === "DIV") {
|
|
|
|
input.html(RED.text.format.getHtml(val, definition[property].format, {}, false, "en"));
|
2016-08-25 18:09:56 +02:00
|
|
|
RED.text.format.attach(input[0], definition[property].format, {}, false, "en");
|
2016-08-25 17:47:30 +02:00
|
|
|
} else {
|
2016-09-08 21:49:44 +02:00
|
|
|
input.val(val);
|
2016-10-01 00:35:05 +02:00
|
|
|
if (input[0].nodeName === 'INPUT' || input[0].nodeName === 'TEXTAREA') {
|
|
|
|
RED.text.bidi.prepareInput(input);
|
|
|
|
}
|
2016-08-25 18:09:56 +02:00
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
/**
|
|
|
|
* Add an on-change handler to revalidate a node field
|
|
|
|
* @param node - the node being edited
|
2014-05-16 09:34:23 +02:00
|
|
|
* @param definition - the definition of the node
|
2014-05-07 00:42:54 +02:00
|
|
|
* @param property - the name of the field
|
|
|
|
* @param prefix - the prefix to use in the input element ids (node-input|node-config-input)
|
|
|
|
*/
|
2014-05-16 09:34:23 +02:00
|
|
|
function attachPropertyChangeHandler(node,definition,property,prefix) {
|
2016-09-08 21:49:44 +02:00
|
|
|
var input = $("#"+prefix+"-"+property);
|
2016-09-08 21:46:30 +02:00
|
|
|
if (definition !== undefined && "format" in definition[property] && definition[property].format !== "" && input[0].nodeName === "DIV") {
|
|
|
|
$("#"+prefix+"-"+property).on('change keyup', function(event,skipValidation) {
|
|
|
|
if (!skipValidation) {
|
|
|
|
validateNodeEditor(node,prefix);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$("#"+prefix+"-"+property).change(function(event,skipValidation) {
|
|
|
|
if (!skipValidation) {
|
|
|
|
validateNodeEditor(node,prefix);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-06-24 12:13:19 +02:00
|
|
|
/**
|
|
|
|
* Assign the value to each credential field
|
|
|
|
* @param node
|
|
|
|
* @param credDef
|
|
|
|
* @param credData
|
|
|
|
* @param prefix
|
|
|
|
*/
|
|
|
|
function populateCredentialsInputs(node, credDef, credData, prefix) {
|
2014-08-08 01:01:35 +02:00
|
|
|
var cred;
|
|
|
|
for (cred in credDef) {
|
2014-07-19 01:16:21 +02:00
|
|
|
if (credDef.hasOwnProperty(cred)) {
|
|
|
|
if (credDef[cred].type == 'password') {
|
|
|
|
if (credData[cred]) {
|
|
|
|
$('#' + prefix + '-' + cred).val(credData[cred]);
|
2014-07-20 21:42:41 +02:00
|
|
|
} else if (credData['has_' + cred]) {
|
2014-07-19 01:16:21 +02:00
|
|
|
$('#' + prefix + '-' + cred).val('__PWRD__');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#' + prefix + '-' + cred).val('');
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-08 21:46:30 +02:00
|
|
|
preparePropertyEditor(credData, cred, prefix, credDef);
|
2014-06-24 12:13:19 +02:00
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
attachPropertyChangeHandler(node, credDef, cred, prefix);
|
2014-06-24 12:13:19 +02:00
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
2014-06-24 12:13:19 +02:00
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2014-07-19 01:16:21 +02:00
|
|
|
/**
|
|
|
|
* Update the node credentials from the edit form
|
|
|
|
* @param node - the node containing the credentials
|
|
|
|
* @param credDefinition - definition of the credentials
|
|
|
|
* @param prefix - prefix of the input fields
|
|
|
|
* @return {boolean} whether anything has changed
|
|
|
|
*/
|
|
|
|
function updateNodeCredentials(node, credDefinition, prefix) {
|
|
|
|
var changed = false;
|
|
|
|
if(!node.credentials) {
|
2014-07-20 23:00:02 +02:00
|
|
|
node.credentials = {_:{}};
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var cred in credDefinition) {
|
|
|
|
if (credDefinition.hasOwnProperty(cred)) {
|
|
|
|
var input = $("#" + prefix + '-' + cred);
|
|
|
|
var value = input.val();
|
|
|
|
if (credDefinition[cred].type == 'password') {
|
2014-08-08 01:01:35 +02:00
|
|
|
node.credentials['has_' + cred] = (value !== "");
|
2014-07-19 01:16:21 +02:00
|
|
|
if (value == '__PWRD__') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
changed = true;
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
2014-08-27 23:06:45 +02:00
|
|
|
node.credentials[cred] = value;
|
2014-07-19 01:16:21 +02:00
|
|
|
if (value != node.credentials._[cred]) {
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
2014-06-24 12:13:19 +02:00
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
/**
|
|
|
|
* Prepare all of the editor dialog fields
|
|
|
|
* @param node - the node being edited
|
|
|
|
* @param definition - the node definition
|
|
|
|
* @param prefix - the prefix to use in the input element ids (node-input|node-config-input)
|
|
|
|
*/
|
2017-02-16 22:41:20 +01:00
|
|
|
function prepareEditDialog(node,definition,prefix,done) {
|
2014-05-07 00:42:54 +02:00
|
|
|
for (var d in definition.defaults) {
|
2014-08-08 01:01:35 +02:00
|
|
|
if (definition.defaults.hasOwnProperty(d)) {
|
|
|
|
if (definition.defaults[d].type) {
|
2015-07-08 23:12:52 +02:00
|
|
|
var configTypeDef = RED.nodes.getType(definition.defaults[d].type);
|
2015-09-26 00:17:57 +02:00
|
|
|
if (configTypeDef) {
|
|
|
|
if (configTypeDef.exclusive) {
|
2016-04-19 22:41:26 +02:00
|
|
|
prepareConfigNodeButton(node,d,definition.defaults[d].type,prefix);
|
2015-09-26 00:17:57 +02:00
|
|
|
} else {
|
2016-04-19 22:41:26 +02:00
|
|
|
prepareConfigNodeSelect(node,d,definition.defaults[d].type,prefix);
|
2015-09-26 00:17:57 +02:00
|
|
|
}
|
2015-05-06 12:08:01 +02:00
|
|
|
} else {
|
2015-09-26 00:17:57 +02:00
|
|
|
console.log("Unknown type:", definition.defaults[d].type);
|
2016-09-08 21:46:30 +02:00
|
|
|
preparePropertyEditor(node,d,prefix,definition.defaults);
|
2015-05-06 12:08:01 +02:00
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
} else {
|
2016-09-08 21:46:30 +02:00
|
|
|
preparePropertyEditor(node,d,prefix,definition.defaults);
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
|
|
|
attachPropertyChangeHandler(node,definition.defaults,d,prefix);
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
var completePrepare = function() {
|
|
|
|
if (definition.oneditprepare) {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
definition.oneditprepare.call(node);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditprepare",node.id,node.type,err.toString());
|
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
2016-05-19 23:42:28 +02:00
|
|
|
// Now invoke any change handlers added to the fields - passing true
|
|
|
|
// to prevent full node validation from being triggered each time
|
|
|
|
for (var d in definition.defaults) {
|
|
|
|
if (definition.defaults.hasOwnProperty(d)) {
|
|
|
|
$("#"+prefix+"-"+d).trigger("change",[true]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (definition.credentials) {
|
|
|
|
for (d in definition.credentials) {
|
|
|
|
if (definition.credentials.hasOwnProperty(d)) {
|
|
|
|
$("#"+prefix+"-"+d).trigger("change",[true]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 23:00:02 +02:00
|
|
|
validateNodeEditor(node,prefix);
|
2017-02-16 22:41:20 +01:00
|
|
|
if (done) {
|
|
|
|
done();
|
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
if (definition.credentials) {
|
2014-07-19 01:16:21 +02:00
|
|
|
if (node.credentials) {
|
|
|
|
populateCredentialsInputs(node, definition.credentials, node.credentials, prefix);
|
|
|
|
completePrepare();
|
2014-06-24 12:13:19 +02:00
|
|
|
} else {
|
|
|
|
$.getJSON(getCredentialsURL(node.type, node.id), function (data) {
|
2014-07-19 01:16:21 +02:00
|
|
|
node.credentials = data;
|
|
|
|
node.credentials._ = $.extend(true,{},data);
|
|
|
|
populateCredentialsInputs(node, definition.credentials, node.credentials, prefix);
|
|
|
|
completePrepare();
|
2014-06-24 12:13:19 +02:00
|
|
|
});
|
|
|
|
}
|
2014-07-19 01:16:21 +02:00
|
|
|
} else {
|
|
|
|
completePrepare();
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2016-05-03 16:45:29 +02:00
|
|
|
function getEditStackTitle() {
|
|
|
|
var title = '<ul class="editor-tray-breadcrumbs">';
|
2017-10-25 16:26:24 +02:00
|
|
|
var label;
|
|
|
|
for (var i=editStack.length-1;i<editStack.length;i++) {
|
2016-05-03 16:45:29 +02:00
|
|
|
var node = editStack[i];
|
2017-10-25 16:26:24 +02:00
|
|
|
label = node.type;
|
2016-11-15 01:19:04 +01:00
|
|
|
if (node.type === '_expression') {
|
2017-05-03 18:17:36 +02:00
|
|
|
label = RED._("expressionEditor.title");
|
2017-03-13 00:52:31 +01:00
|
|
|
} else if (node.type === '_json') {
|
2017-05-03 18:17:36 +02:00
|
|
|
label = RED._("jsonEditor.title");
|
2017-09-20 11:30:07 +02:00
|
|
|
} else if (node.type === '_markdown') {
|
|
|
|
label = RED._("markdownEditor.title");
|
2017-06-11 22:19:46 +02:00
|
|
|
} else if (node.type === '_buffer') {
|
|
|
|
label = RED._("bufferEditor.title");
|
2016-11-15 01:19:04 +01:00
|
|
|
} else if (node.type === 'subflow') {
|
2016-05-03 16:45:29 +02:00
|
|
|
label = RED._("subflow.editSubflow",{name:node.name})
|
|
|
|
} else if (node.type.indexOf("subflow:")===0) {
|
|
|
|
var subflow = RED.nodes.subflow(node.type.substring(8));
|
|
|
|
label = RED._("subflow.editSubflow",{name:subflow.name})
|
|
|
|
} else {
|
|
|
|
if (typeof node._def.paletteLabel !== "undefined") {
|
|
|
|
try {
|
|
|
|
label = (typeof node._def.paletteLabel === "function" ? node._def.paletteLabel.call(node._def) : node._def.paletteLabel)||"";
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+node.type+".paletteLabel",err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i === editStack.length-1) {
|
|
|
|
if (RED.nodes.node(node.id)) {
|
|
|
|
label = RED._("editor.editNode",{type:label});
|
|
|
|
} else {
|
|
|
|
label = RED._("editor.addNewConfig",{type:label});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
title += '<li>'+label+'</li>';
|
|
|
|
}
|
|
|
|
title += '</ul>';
|
2017-10-25 16:26:24 +02:00
|
|
|
return label;
|
2016-05-03 16:45:29 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 00:01:31 +01:00
|
|
|
function buildEditForm(container,formId,type,ns) {
|
|
|
|
var dialogForm = $('<form id="'+formId+'" class="form-horizontal" autocomplete="off"></form>').appendTo(container);
|
2016-11-15 01:19:04 +01:00
|
|
|
dialogForm.html($("script[data-template-name='"+type+"']").html());
|
|
|
|
ns = ns||"node-red";
|
|
|
|
dialogForm.find('[data-i18n]').each(function() {
|
|
|
|
var current = $(this).attr("data-i18n");
|
|
|
|
var keys = current.split(";");
|
|
|
|
for (var i=0;i<keys.length;i++) {
|
|
|
|
var key = keys[i];
|
|
|
|
if (key.indexOf(":") === -1) {
|
|
|
|
var prefix = "";
|
|
|
|
if (key.indexOf("[")===0) {
|
|
|
|
var parts = key.split("]");
|
|
|
|
prefix = parts[0]+"]";
|
|
|
|
key = parts[1];
|
|
|
|
}
|
|
|
|
keys[i] = prefix+ns+":"+key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(this).attr("data-i18n",keys.join(";"));
|
|
|
|
});
|
2017-01-09 00:14:14 +01:00
|
|
|
// Add dummy fields to prevent 'Enter' submitting the form in some
|
|
|
|
// cases, and also prevent browser auto-fill of password
|
|
|
|
// Add in reverse order as they are prepended...
|
|
|
|
$('<input type="password" style="display: none;" />').prependTo(dialogForm);
|
2016-11-15 01:19:04 +01:00
|
|
|
$('<input type="text" style="display: none;" />').prependTo(dialogForm);
|
|
|
|
dialogForm.submit(function(e) { e.preventDefault();});
|
|
|
|
return dialogForm;
|
|
|
|
}
|
|
|
|
|
2017-02-06 14:23:42 +01:00
|
|
|
function refreshLabelForm(container,node) {
|
2017-02-08 11:46:24 +01:00
|
|
|
|
|
|
|
var inputPlaceholder = node._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
|
|
|
var outputPlaceholder = node._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
|
|
|
|
2017-02-06 14:23:42 +01:00
|
|
|
var inputsDiv = $("#node-label-form-inputs");
|
|
|
|
var outputsDiv = $("#node-label-form-outputs");
|
2017-02-07 23:30:54 +01:00
|
|
|
|
|
|
|
var inputCount = node.inputs || node._def.inputs || 0;
|
2017-02-06 14:23:42 +01:00
|
|
|
var children = inputsDiv.children();
|
2017-05-15 17:26:42 +02:00
|
|
|
var childCount = children.length;
|
|
|
|
if (childCount === 1 && $(children[0]).hasClass('node-label-form-none')) {
|
|
|
|
childCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childCount < inputCount) {
|
|
|
|
if (childCount === 0) {
|
|
|
|
// remove the 'none' placeholder
|
|
|
|
$(children[0]).remove();
|
|
|
|
}
|
|
|
|
for (i = childCount;i<inputCount;i++) {
|
2017-02-08 11:46:24 +01:00
|
|
|
buildLabelRow("input",i,"",inputPlaceholder).appendTo(inputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
2017-05-15 17:26:42 +02:00
|
|
|
} else if (childCount > inputCount) {
|
|
|
|
for (i=inputCount;i<childCount;i++) {
|
2017-02-06 14:23:42 +01:00
|
|
|
$(children[i]).remove();
|
|
|
|
}
|
2017-05-15 17:26:42 +02:00
|
|
|
if (outputCount === 0) {
|
|
|
|
buildLabelRow().appendTo(inputsDiv);
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
|
2017-02-07 23:30:54 +01:00
|
|
|
var outputCount;
|
|
|
|
var i;
|
|
|
|
var formOutputs = $("#node-input-outputs").val();
|
|
|
|
|
|
|
|
if (formOutputs === undefined) {
|
|
|
|
outputCount = node.outputs || node._def.outputs || 0;
|
|
|
|
} else if (isNaN(formOutputs)) {
|
|
|
|
var outputMap = JSON.parse(formOutputs);
|
|
|
|
var keys = Object.keys(outputMap);
|
2017-05-15 17:26:42 +02:00
|
|
|
children = outputsDiv.children();
|
|
|
|
childCount = children.length;
|
|
|
|
if (childCount === 1 && $(children[0]).hasClass('node-label-form-none')) {
|
|
|
|
childCount--;
|
|
|
|
}
|
|
|
|
|
2017-02-07 23:30:54 +01:00
|
|
|
outputCount = 0;
|
|
|
|
var rows = [];
|
|
|
|
keys.forEach(function(p) {
|
|
|
|
var row = $("#node-label-form-output-"+p).parent();
|
|
|
|
if (row.length === 0 && outputMap[p] !== -1) {
|
2017-05-15 17:26:42 +02:00
|
|
|
if (childCount === 0) {
|
|
|
|
$(children[0]).remove();
|
|
|
|
childCount = -1;
|
|
|
|
}
|
2017-02-08 11:46:24 +01:00
|
|
|
row = buildLabelRow("output",p,"",outputPlaceholder);
|
2017-05-15 17:26:42 +02:00
|
|
|
} else {
|
|
|
|
row.detach();
|
2017-02-07 23:30:54 +01:00
|
|
|
}
|
|
|
|
if (outputMap[p] !== -1) {
|
|
|
|
outputCount++;
|
|
|
|
rows.push({i:parseInt(outputMap[p]),r:row});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
rows.sort(function(A,B) {
|
|
|
|
return A.i-B.i;
|
|
|
|
})
|
|
|
|
rows.forEach(function(r,i) {
|
|
|
|
r.r.find("label").html((i+1)+".");
|
|
|
|
r.r.appendTo(outputsDiv);
|
|
|
|
})
|
2017-05-15 17:26:42 +02:00
|
|
|
if (rows.length === 0) {
|
|
|
|
buildLabelRow("output",i,"").appendTo(outputsDiv);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
2017-02-07 23:30:54 +01:00
|
|
|
} else {
|
|
|
|
outputCount = Math.max(0,parseInt(formOutputs));
|
|
|
|
}
|
|
|
|
children = outputsDiv.children();
|
2017-05-15 17:26:42 +02:00
|
|
|
childCount = children.length;
|
|
|
|
if (childCount === 1 && $(children[0]).hasClass('node-label-form-none')) {
|
|
|
|
childCount--;
|
|
|
|
}
|
|
|
|
if (childCount < outputCount) {
|
|
|
|
if (childCount === 0) {
|
|
|
|
// remove the 'none' placeholder
|
|
|
|
$(children[0]).remove();
|
|
|
|
}
|
|
|
|
for (i = childCount;i<outputCount;i++) {
|
2017-02-07 23:30:54 +01:00
|
|
|
buildLabelRow("output",i,"").appendTo(outputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
2017-05-15 17:26:42 +02:00
|
|
|
} else if (childCount > outputCount) {
|
|
|
|
for (i=outputCount;i<childCount;i++) {
|
2017-02-06 14:23:42 +01:00
|
|
|
$(children[i]).remove();
|
|
|
|
}
|
2017-05-15 17:26:42 +02:00
|
|
|
if (outputCount === 0) {
|
|
|
|
buildLabelRow().appendTo(outputsDiv);
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-08 11:46:24 +01:00
|
|
|
function buildLabelRow(type, index, value, placeHolder) {
|
2017-05-15 17:26:42 +02:00
|
|
|
var result = $('<div>',{class:"node-label-form-row"});
|
|
|
|
if (type === undefined) {
|
2017-08-07 11:00:28 +02:00
|
|
|
$('<span>').html(RED._("editor.noDefaultLabel")).appendTo(result);
|
2017-05-15 17:26:42 +02:00
|
|
|
result.addClass("node-label-form-none");
|
|
|
|
} else {
|
|
|
|
result.addClass("");
|
|
|
|
var id = "node-label-form-"+type+"-"+index;
|
|
|
|
$('<label>',{for:id}).html((index+1)+".").appendTo(result);
|
|
|
|
var input = $('<input>',{type:"text",id:id, placeholder: placeHolder}).val(value).appendTo(result);
|
|
|
|
var clear = $('<button class="editor-button editor-button-small"><i class="fa fa-times"></i></button>').appendTo(result);
|
|
|
|
clear.click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
input.val("");
|
|
|
|
})
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
function buildLabelForm(container,node) {
|
|
|
|
var dialogForm = $('<form class="dialog-form form-horizontal" autocomplete="off"></form>').appendTo(container);
|
|
|
|
|
|
|
|
var inputCount = node.inputs || node._def.inputs || 0;
|
|
|
|
var outputCount = node.outputs || node._def.outputs || 0;
|
2017-02-08 11:25:58 +01:00
|
|
|
if (node.type === 'subflow') {
|
|
|
|
inputCount = node.in.length;
|
|
|
|
outputCount = node.out.length;
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
|
|
|
|
var inputLabels = node.inputLabels || [];
|
|
|
|
var outputLabels = node.outputLabels || [];
|
|
|
|
|
2017-02-08 11:46:24 +01:00
|
|
|
var inputPlaceholder = node._def.inputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
|
|
|
var outputPlaceholder = node._def.outputLabels?RED._("editor.defaultLabel"):RED._("editor.noDefaultLabel");
|
2017-02-06 14:23:42 +01:00
|
|
|
|
|
|
|
var i,row;
|
2017-05-15 17:26:42 +02:00
|
|
|
$('<div class="form-row"><span data-i18n="editor.labelInputs"></span><div id="node-label-form-inputs"></div></div>').appendTo(dialogForm);
|
2017-02-07 23:30:54 +01:00
|
|
|
var inputsDiv = $("#node-label-form-inputs");
|
2017-02-06 14:23:42 +01:00
|
|
|
if (inputCount > 0) {
|
|
|
|
for (i=0;i<inputCount;i++) {
|
2017-02-08 11:46:24 +01:00
|
|
|
buildLabelRow("input",i,inputLabels[i],inputPlaceholder).appendTo(inputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-15 17:26:42 +02:00
|
|
|
buildLabelRow().appendTo(inputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
2017-05-15 17:26:42 +02:00
|
|
|
$('<div class="form-row"><span data-i18n="editor.labelOutputs"></span><div id="node-label-form-outputs"></div></div>').appendTo(dialogForm);
|
2017-02-07 23:30:54 +01:00
|
|
|
var outputsDiv = $("#node-label-form-outputs");
|
2017-02-06 14:23:42 +01:00
|
|
|
if (outputCount > 0) {
|
|
|
|
for (i=0;i<outputCount;i++) {
|
2017-02-08 11:46:24 +01:00
|
|
|
buildLabelRow("output",i,outputLabels[i],outputPlaceholder).appendTo(outputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-15 17:26:42 +02:00
|
|
|
buildLabelRow().appendTo(outputsDiv);
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
|
2018-03-14 05:51:50 +01:00
|
|
|
if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon"))) {
|
2017-12-19 12:11:10 +01:00
|
|
|
$('<div class="form-row"><div id="node-settings-icon"></div></div>').appendTo(dialogForm);
|
|
|
|
var iconDiv = $("#node-settings-icon");
|
|
|
|
$('<label data-i18n="editor.settingIcon">').appendTo(iconDiv);
|
|
|
|
var iconForm = $('<div>',{class:"node-label-form-row"});
|
|
|
|
iconForm.appendTo(iconDiv);
|
|
|
|
$('<label>').appendTo(iconForm);
|
2017-11-30 14:13:35 +01:00
|
|
|
|
2017-12-19 12:11:10 +01:00
|
|
|
var selectIconModule = $('<select id="node-settings-icon-module"><option value=""></option></select>').appendTo(iconForm);
|
|
|
|
var iconPath;
|
|
|
|
if (node.icon) {
|
|
|
|
iconPath = RED.utils.separateIconPath(node.icon);
|
|
|
|
} else {
|
|
|
|
iconPath = RED.utils.getDefaultNodeIcon(node._def, node);
|
|
|
|
}
|
|
|
|
var iconSets = RED.nodes.getIconSets();
|
|
|
|
Object.keys(iconSets).forEach(function(moduleName) {
|
|
|
|
selectIconModule.append($("<option></option>").val(moduleName).text(moduleName));
|
|
|
|
});
|
|
|
|
if (iconPath.module && !iconSets[iconPath.module]) {
|
|
|
|
selectIconModule.append($("<option disabled></option>").val(iconPath.module).text(iconPath.module));
|
|
|
|
}
|
|
|
|
selectIconModule.val(iconPath.module);
|
|
|
|
var iconModuleHidden = $('<input type="hidden" id="node-settings-icon-module-hidden"></input>').appendTo(iconForm);
|
|
|
|
iconModuleHidden.val(iconPath.module);
|
2017-11-30 14:13:35 +01:00
|
|
|
|
2017-12-19 12:11:10 +01:00
|
|
|
var selectIconFile = $('<select id="node-settings-icon-file"><option value=""></option></select>').appendTo(iconForm);
|
|
|
|
selectIconModule.change(function() {
|
|
|
|
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, true);
|
|
|
|
});
|
|
|
|
var iconFileHidden = $('<input type="hidden" id="node-settings-icon-file-hidden"></input>').appendTo(iconForm);
|
|
|
|
iconFileHidden.val(iconPath.file);
|
|
|
|
selectIconFile.change(function() {
|
|
|
|
selectIconFile.removeClass("input-error");
|
|
|
|
var fileName = selectIconFile.val();
|
|
|
|
iconFileHidden.val(fileName);
|
|
|
|
});
|
2018-01-23 00:25:43 +01:00
|
|
|
var clear = $('<button class="editor-button editor-button-small"><i class="fa fa-times"></i></button>').appendTo(iconForm);
|
|
|
|
clear.click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
var iconPath = RED.utils.getDefaultNodeIcon(node._def, node);
|
|
|
|
selectIconModule.val(iconPath.module);
|
|
|
|
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, true);
|
|
|
|
selectIconFile.removeClass("input-error");
|
|
|
|
selectIconFile.val(iconPath.file);
|
|
|
|
iconFileHidden.val(iconPath.file);
|
|
|
|
});
|
2017-11-30 14:13:35 +01:00
|
|
|
|
2017-12-19 12:11:10 +01:00
|
|
|
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, false);
|
|
|
|
var iconFileList = iconSets[selectIconModule.val()];
|
|
|
|
if (!iconFileList || iconFileList.indexOf(iconPath.file) === -1) {
|
|
|
|
selectIconFile.append($("<option disabled></option>").val(iconPath.file).text(iconPath.file));
|
|
|
|
}
|
|
|
|
selectIconFile.val(iconPath.file);
|
2017-11-30 14:13:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, updateIconFile) {
|
|
|
|
selectIconFile.children().remove();
|
|
|
|
var moduleName = selectIconModule.val();
|
|
|
|
if (moduleName !== null) {
|
|
|
|
iconModuleHidden.val(moduleName);
|
|
|
|
}
|
|
|
|
var iconFileList = iconSets[moduleName];
|
|
|
|
if (iconFileList) {
|
|
|
|
iconFileList.forEach(function(fileName) {
|
|
|
|
if (updateIconFile) {
|
|
|
|
updateIconFile = false;
|
|
|
|
iconFileHidden.val(fileName);
|
|
|
|
}
|
|
|
|
selectIconFile.append($("<option></option>").val(fileName).text(fileName));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
selectIconFile.prop("disabled", !iconFileList);
|
2018-03-14 05:51:50 +01:00
|
|
|
selectIconFile.removeClass("input-error");
|
2017-11-30 14:13:35 +01:00
|
|
|
selectIconModule.removeClass("input-error");
|
2017-02-06 14:23:42 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:39:46 +01:00
|
|
|
function updateLabels(editing_node, changes, outputMap) {
|
|
|
|
var inputLabels = $("#node-label-form-inputs").children().find("input");
|
|
|
|
var outputLabels = $("#node-label-form-outputs").children().find("input");
|
|
|
|
|
|
|
|
var hasNonBlankLabel = false;
|
|
|
|
var changed = false;
|
|
|
|
var newValue = inputLabels.map(function() {
|
|
|
|
var v = $(this).val();
|
|
|
|
hasNonBlankLabel = hasNonBlankLabel || v!== "";
|
|
|
|
return v;
|
|
|
|
}).toArray().slice(0,editing_node.inputs);
|
|
|
|
if ((editing_node.inputLabels === undefined && hasNonBlankLabel) ||
|
|
|
|
(editing_node.inputLabels !== undefined && JSON.stringify(newValue) !== JSON.stringify(editing_node.inputLabels))) {
|
|
|
|
changes.inputLabels = editing_node.inputLabels;
|
|
|
|
editing_node.inputLabels = newValue;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
hasNonBlankLabel = false;
|
|
|
|
newValue = new Array(editing_node.outputs);
|
|
|
|
outputLabels.each(function() {
|
|
|
|
var index = $(this).attr('id').substring(23); // node-label-form-output-<index>
|
|
|
|
if (outputMap && outputMap.hasOwnProperty(index)) {
|
|
|
|
index = parseInt(outputMap[index]);
|
|
|
|
if (index === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var v = $(this).val();
|
|
|
|
hasNonBlankLabel = hasNonBlankLabel || v!== "";
|
|
|
|
newValue[index] = v;
|
|
|
|
});
|
|
|
|
|
|
|
|
if ((editing_node.outputLabels === undefined && hasNonBlankLabel) ||
|
|
|
|
(editing_node.outputLabels !== undefined && JSON.stringify(newValue) !== JSON.stringify(editing_node.outputLabels))) {
|
|
|
|
changes.outputLabels = editing_node.outputLabels;
|
|
|
|
editing_node.outputLabels = newValue;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
function showEditDialog(node) {
|
2016-01-31 23:27:14 +01:00
|
|
|
var editing_node = node;
|
2017-11-30 14:13:35 +01:00
|
|
|
var isDefaultIcon;
|
|
|
|
var defaultIcon;
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.push(node);
|
2014-05-07 00:42:54 +02:00
|
|
|
RED.view.state(RED.state.EDITING);
|
2014-02-25 00:35:11 +01:00
|
|
|
var type = node.type;
|
|
|
|
if (node.type.substring(0,8) == "subflow:") {
|
|
|
|
type = "subflow";
|
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
var trayOptions = {
|
2016-05-03 16:45:29 +02:00
|
|
|
title: getEditStackTitle(),
|
2016-01-31 23:27:14 +01:00
|
|
|
buttons: [
|
2016-11-04 15:29:04 +01:00
|
|
|
{
|
|
|
|
id: "node-dialog-delete",
|
|
|
|
class: 'leftButton',
|
|
|
|
text: RED._("common.label.delete"),
|
|
|
|
click: function() {
|
|
|
|
var startDirty = RED.nodes.dirty();
|
|
|
|
var removedNodes = [];
|
|
|
|
var removedLinks = [];
|
|
|
|
var removedEntities = RED.nodes.remove(editing_node.id);
|
|
|
|
removedNodes.push(editing_node);
|
|
|
|
removedNodes = removedNodes.concat(removedEntities.nodes);
|
|
|
|
removedLinks = removedLinks.concat(removedEntities.links);
|
|
|
|
|
|
|
|
var historyEvent = {
|
|
|
|
t:'delete',
|
|
|
|
nodes:removedNodes,
|
|
|
|
links:removedLinks,
|
|
|
|
changes: {},
|
|
|
|
dirty: startDirty
|
|
|
|
}
|
|
|
|
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
RED.view.redraw(true);
|
|
|
|
RED.history.push(historyEvent);
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
2016-05-03 16:45:29 +02:00
|
|
|
{
|
|
|
|
id: "node-dialog-cancel",
|
|
|
|
text: RED._("common.label.cancel"),
|
|
|
|
click: function() {
|
|
|
|
if (editing_node._def) {
|
|
|
|
if (editing_node._def.oneditcancel) {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
editing_node._def.oneditcancel.call(editing_node);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditcancel",editing_node.id,editing_node.type,err.toString());
|
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var d in editing_node._def.defaults) {
|
|
|
|
if (editing_node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
var def = editing_node._def.defaults[d];
|
|
|
|
if (def.type) {
|
|
|
|
var configTypeDef = RED.nodes.getType(def.type);
|
|
|
|
if (configTypeDef && configTypeDef.exclusive) {
|
|
|
|
var input = $("#node-input-"+d).val()||"";
|
|
|
|
if (input !== "" && !editing_node[d]) {
|
|
|
|
// This node has an exclusive config node that
|
|
|
|
// has just been added. As the user is cancelling
|
|
|
|
// the edit, need to delete the just-added config
|
|
|
|
// node so that it doesn't get orphaned.
|
|
|
|
RED.nodes.remove(input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
2016-01-31 23:27:14 +01:00
|
|
|
{
|
|
|
|
id: "node-dialog-ok",
|
2016-05-03 16:45:29 +02:00
|
|
|
text: RED._("common.label.done"),
|
|
|
|
class: "primary",
|
2016-01-31 23:27:14 +01:00
|
|
|
click: function() {
|
2016-03-21 23:51:48 +01:00
|
|
|
var changes = {};
|
|
|
|
var changed = false;
|
|
|
|
var wasDirty = RED.nodes.dirty();
|
|
|
|
var d;
|
2016-11-08 18:00:47 +01:00
|
|
|
var outputMap;
|
2016-03-21 23:51:48 +01:00
|
|
|
|
|
|
|
if (editing_node._def.oneditsave) {
|
|
|
|
var oldValues = {};
|
|
|
|
for (d in editing_node._def.defaults) {
|
|
|
|
if (editing_node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") {
|
|
|
|
oldValues[d] = editing_node[d];
|
|
|
|
} else {
|
|
|
|
oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v;
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
}
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
var rc = editing_node._def.oneditsave.call(editing_node);
|
|
|
|
if (rc === true) {
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditsave",editing_node.id,editing_node.type,err.toString());
|
2016-03-21 23:51:48 +01:00
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
|
2016-03-21 23:51:48 +01:00
|
|
|
for (d in editing_node._def.defaults) {
|
|
|
|
if (editing_node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") {
|
|
|
|
if (oldValues[d] !== editing_node[d]) {
|
|
|
|
changes[d] = oldValues[d];
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (JSON.stringify(oldValues[d]) !== JSON.stringify(editing_node[d])) {
|
|
|
|
changes[d] = oldValues[d];
|
|
|
|
changed = true;
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
|
2017-02-07 23:30:54 +01:00
|
|
|
var newValue;
|
2016-03-21 23:51:48 +01:00
|
|
|
if (editing_node._def.defaults) {
|
|
|
|
for (d in editing_node._def.defaults) {
|
|
|
|
if (editing_node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
var input = $("#node-input-"+d);
|
|
|
|
if (input.attr('type') === "checkbox") {
|
|
|
|
newValue = input.prop('checked');
|
2016-09-08 21:46:30 +02:00
|
|
|
} else if ("format" in editing_node._def.defaults[d] && editing_node._def.defaults[d].format !== "" && input[0].nodeName === "DIV") {
|
|
|
|
newValue = input.text();
|
2016-03-21 23:51:48 +01:00
|
|
|
} else {
|
|
|
|
newValue = input.val();
|
|
|
|
}
|
|
|
|
if (newValue != null) {
|
2017-02-07 23:30:54 +01:00
|
|
|
if (d === "outputs") {
|
|
|
|
if (newValue.trim() === "") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isNaN(newValue)) {
|
|
|
|
outputMap = JSON.parse(newValue);
|
|
|
|
var outputCount = 0;
|
|
|
|
var outputsChanged = false;
|
|
|
|
var keys = Object.keys(outputMap);
|
|
|
|
keys.forEach(function(p) {
|
|
|
|
if (isNaN(p)) {
|
|
|
|
// New output;
|
|
|
|
outputCount ++;
|
|
|
|
delete outputMap[p];
|
|
|
|
} else {
|
|
|
|
outputMap[p] = outputMap[p]+"";
|
|
|
|
if (outputMap[p] !== "-1") {
|
|
|
|
outputCount++;
|
|
|
|
if (outputMap[p] !== p) {
|
|
|
|
// Output moved
|
|
|
|
outputsChanged = true;
|
|
|
|
} else {
|
|
|
|
delete outputMap[p];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Output removed
|
|
|
|
outputsChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
newValue = outputCount;
|
|
|
|
if (outputsChanged) {
|
|
|
|
changed = true;
|
|
|
|
}
|
2017-12-22 22:14:47 +01:00
|
|
|
} else {
|
|
|
|
newValue = parseInt(newValue);
|
2017-02-07 23:30:54 +01:00
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
if (editing_node[d] != newValue) {
|
|
|
|
if (editing_node._def.defaults[d].type) {
|
|
|
|
if (newValue == "_ADD_") {
|
|
|
|
newValue = "";
|
|
|
|
}
|
|
|
|
// Change to a related config node
|
|
|
|
var configNode = RED.nodes.node(editing_node[d]);
|
|
|
|
if (configNode) {
|
|
|
|
var users = configNode.users;
|
|
|
|
users.splice(users.indexOf(editing_node),1);
|
|
|
|
}
|
|
|
|
configNode = RED.nodes.node(newValue);
|
|
|
|
if (configNode) {
|
|
|
|
configNode.users.push(editing_node);
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
changes[d] = editing_node[d];
|
|
|
|
editing_node[d] = newValue;
|
|
|
|
changed = true;
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
}
|
|
|
|
if (editing_node._def.credentials) {
|
|
|
|
var prefix = 'node-input';
|
|
|
|
var credDefinition = editing_node._def.credentials;
|
|
|
|
var credsChanged = updateNodeCredentials(editing_node,credDefinition,prefix);
|
|
|
|
changed = changed || credsChanged;
|
|
|
|
}
|
2017-02-07 23:30:54 +01:00
|
|
|
// if (editing_node.hasOwnProperty("_outputs")) {
|
|
|
|
// outputMap = editing_node._outputs;
|
|
|
|
// delete editing_node._outputs;
|
|
|
|
// if (Object.keys(outputMap).length > 0) {
|
|
|
|
// changed = true;
|
|
|
|
// }
|
|
|
|
// }
|
2016-11-08 18:00:47 +01:00
|
|
|
var removedLinks = updateNodeProperties(editing_node,outputMap);
|
2017-02-06 14:23:42 +01:00
|
|
|
|
2018-03-20 21:39:46 +01:00
|
|
|
if (updateLabels(editing_node, changes, outputMap)) {
|
2017-02-07 23:30:54 +01:00
|
|
|
changed = true;
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
|
2018-02-22 06:10:31 +01:00
|
|
|
if (!editing_node._def.defaults || !editing_node._def.defaults.hasOwnProperty("icon")) {
|
2017-12-19 12:11:10 +01:00
|
|
|
var iconModule = $("#node-settings-icon-module-hidden").val();
|
|
|
|
var iconFile = $("#node-settings-icon-file-hidden").val();
|
|
|
|
var icon = (iconModule && iconFile) ? iconModule+"/"+iconFile : "";
|
|
|
|
if (!isDefaultIcon) {
|
|
|
|
if (icon !== editing_node.icon) {
|
|
|
|
changes.icon = editing_node.icon;
|
|
|
|
editing_node.icon = icon;
|
|
|
|
changed = true;
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
} else {
|
2017-12-19 12:11:10 +01:00
|
|
|
if (icon !== defaultIcon) {
|
2017-11-30 14:13:35 +01:00
|
|
|
changes.icon = editing_node.icon;
|
2017-12-19 12:11:10 +01:00
|
|
|
editing_node.icon = icon;
|
2017-11-30 14:13:35 +01:00
|
|
|
changed = true;
|
2017-12-19 12:11:10 +01:00
|
|
|
} else {
|
|
|
|
var iconPath = RED.utils.getDefaultNodeIcon(editing_node._def, editing_node);
|
|
|
|
var currentDefaultIcon = iconPath.module+"/"+iconPath.file;
|
|
|
|
if (defaultIcon !== currentDefaultIcon) {
|
|
|
|
changes.icon = editing_node.icon;
|
|
|
|
editing_node.icon = currentDefaultIcon;
|
|
|
|
changed = true;
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 23:51:48 +01:00
|
|
|
if (changed) {
|
|
|
|
var wasChanged = editing_node.changed;
|
|
|
|
editing_node.changed = true;
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
|
|
|
|
var activeSubflow = RED.nodes.subflow(RED.workspaces.active());
|
|
|
|
var subflowInstances = null;
|
|
|
|
if (activeSubflow) {
|
|
|
|
subflowInstances = [];
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type == "subflow:"+RED.workspaces.active()) {
|
|
|
|
subflowInstances.push({
|
|
|
|
id:n.id,
|
|
|
|
changed:n.changed
|
|
|
|
});
|
|
|
|
n.changed = true;
|
|
|
|
n.dirty = true;
|
|
|
|
updateNodeProperties(n);
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
var historyEvent = {
|
|
|
|
t:'edit',
|
|
|
|
node:editing_node,
|
|
|
|
changes:changes,
|
|
|
|
links:removedLinks,
|
|
|
|
dirty:wasDirty,
|
|
|
|
changed:wasChanged
|
|
|
|
};
|
2016-11-08 18:00:47 +01:00
|
|
|
if (outputMap) {
|
|
|
|
historyEvent.outputMap = outputMap;
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
if (subflowInstances) {
|
|
|
|
historyEvent.subflow = {
|
|
|
|
instances:subflowInstances
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
RED.history.push(historyEvent);
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
editing_node.dirty = true;
|
|
|
|
validateNode(editing_node);
|
2016-05-30 00:51:20 +02:00
|
|
|
RED.events.emit("editor:save",editing_node);
|
2016-01-31 23:27:14 +01:00
|
|
|
RED.tray.close();
|
|
|
|
}
|
2015-05-07 15:06:55 +02:00
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
],
|
2016-04-14 03:07:49 +02:00
|
|
|
resize: function(dimensions) {
|
|
|
|
editTrayWidthCache[type] = dimensions.width;
|
2017-01-30 00:01:31 +01:00
|
|
|
$(".editor-tray-content").height(dimensions.height - 78);
|
2017-02-06 14:23:42 +01:00
|
|
|
var form = $(".editor-tray-content form").height(dimensions.height - 78 - 40);
|
2016-03-21 23:51:48 +01:00
|
|
|
if (editing_node && editing_node._def.oneditresize) {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
editing_node._def.oneditresize.call(editing_node,{width:form.width(),height:form.height()});
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditresize",editing_node.id,editing_node.type,err.toString());
|
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
},
|
2017-03-01 18:45:09 +01:00
|
|
|
open: function(tray, done) {
|
2017-01-30 00:01:31 +01:00
|
|
|
var trayFooter = tray.find(".editor-tray-footer");
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
2017-01-31 00:47:18 +01:00
|
|
|
trayBody.parent().css('overflow','hidden');
|
2017-01-30 00:01:31 +01:00
|
|
|
|
2017-01-31 00:47:18 +01:00
|
|
|
var stack = RED.stack.create({
|
|
|
|
container: trayBody,
|
|
|
|
singleExpanded: true
|
2017-01-30 00:01:31 +01:00
|
|
|
});
|
2017-01-31 00:47:18 +01:00
|
|
|
var nodeProperties = stack.add({
|
2017-02-07 23:30:54 +01:00
|
|
|
title: RED._("editor.nodeProperties"),
|
2017-02-06 14:23:42 +01:00
|
|
|
expanded: true
|
2017-01-31 00:47:18 +01:00
|
|
|
});
|
2017-04-07 00:17:06 +02:00
|
|
|
nodeProperties.content.addClass("editor-tray-content");
|
|
|
|
|
2017-01-31 00:47:18 +01:00
|
|
|
var portLabels = stack.add({
|
2017-02-07 23:30:54 +01:00
|
|
|
title: RED._("editor.portLabels"),
|
2017-02-06 14:23:42 +01:00
|
|
|
onexpand: function() {
|
|
|
|
refreshLabelForm(this.content,node);
|
|
|
|
}
|
2017-01-30 00:01:31 +01:00
|
|
|
});
|
2017-04-07 00:17:06 +02:00
|
|
|
portLabels.content.addClass("editor-tray-content");
|
|
|
|
|
2017-01-30 00:01:31 +01:00
|
|
|
|
2016-03-21 23:51:48 +01:00
|
|
|
if (editing_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
var ns;
|
|
|
|
if (node._def.set.module === "node-red") {
|
|
|
|
ns = "node-red";
|
|
|
|
} else {
|
|
|
|
ns = node._def.set.id;
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
var iconPath = RED.utils.getDefaultNodeIcon(node._def,node);
|
|
|
|
defaultIcon = iconPath.module+"/"+iconPath.file;
|
|
|
|
if (node.icon && node.icon !== defaultIcon) {
|
|
|
|
isDefaultIcon = false;
|
|
|
|
} else {
|
|
|
|
isDefaultIcon = true;
|
|
|
|
}
|
2017-02-06 14:23:42 +01:00
|
|
|
buildEditForm(nodeProperties.content,"dialog-form",type,ns);
|
|
|
|
buildLabelForm(portLabels.content,node);
|
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
prepareEditDialog(node,node._def,"node-input", function() {
|
2017-03-01 18:45:09 +01:00
|
|
|
trayBody.i18n();
|
2017-02-16 22:41:20 +01:00
|
|
|
done();
|
|
|
|
});
|
2016-01-31 23:27:14 +01:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
|
|
|
|
RED.view.state(RED.state.DEFAULT);
|
|
|
|
}
|
2016-04-10 20:11:29 +02:00
|
|
|
if (editing_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
RED.workspaces.refresh();
|
2016-05-17 10:16:58 +02:00
|
|
|
RED.view.redraw(true);
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.pop();
|
2016-03-21 23:51:48 +01:00
|
|
|
},
|
|
|
|
show: function() {
|
2016-01-31 23:27:14 +01:00
|
|
|
if (editing_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 01:38:48 +02:00
|
|
|
if (editTrayWidthCache.hasOwnProperty(type)) {
|
2016-04-14 03:07:49 +02:00
|
|
|
trayOptions.width = editTrayWidthCache[type];
|
|
|
|
}
|
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
if (type === 'subflow') {
|
|
|
|
var id = editing_node.type.substring(8);
|
|
|
|
trayOptions.buttons.unshift({
|
2016-06-15 23:01:46 +02:00
|
|
|
class: 'leftButton',
|
2016-03-22 14:13:57 +01:00
|
|
|
text: RED._("subflow.edit"),
|
|
|
|
click: function() {
|
|
|
|
RED.workspaces.show(id);
|
|
|
|
$("#node-dialog-ok").click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-31 23:27:14 +01:00
|
|
|
RED.tray.show(trayOptions);
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
/**
|
|
|
|
* name - name of the property that holds this config node
|
|
|
|
* type - type of config node
|
|
|
|
* id - id of config node to edit. _ADD_ for a new one
|
2016-04-19 22:41:26 +02:00
|
|
|
* prefix - the input prefix of the parent property
|
2016-02-28 00:13:19 +01:00
|
|
|
*/
|
2016-04-19 22:41:26 +02:00
|
|
|
function showEditConfigNodeDialog(name,type,id,prefix) {
|
2013-11-17 18:49:32 +01:00
|
|
|
var adding = (id == "_ADD_");
|
2013-09-05 16:02:48 +02:00
|
|
|
var node_def = RED.nodes.getType(type);
|
2016-02-28 00:13:19 +01:00
|
|
|
var editing_config_node = RED.nodes.node(id);
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2015-05-28 16:28:35 +02:00
|
|
|
var ns;
|
|
|
|
if (node_def.set.module === "node-red") {
|
|
|
|
ns = "node-red";
|
|
|
|
} else {
|
|
|
|
ns = node_def.set.id;
|
|
|
|
}
|
2016-08-26 14:26:42 +02:00
|
|
|
var configNodeScope = ""; // default to global
|
|
|
|
var activeSubflow = RED.nodes.subflow(RED.workspaces.active());
|
|
|
|
if (activeSubflow) {
|
|
|
|
configNodeScope = activeSubflow.id;
|
2015-09-23 23:49:48 +02:00
|
|
|
}
|
2015-11-06 12:08:07 +01:00
|
|
|
if (editing_config_node == null) {
|
|
|
|
editing_config_node = {
|
2016-04-19 22:41:26 +02:00
|
|
|
id: RED.nodes.id(),
|
2014-05-07 00:42:54 +02:00
|
|
|
_def: node_def,
|
2015-09-23 23:49:48 +02:00
|
|
|
type: type,
|
2016-08-26 14:26:42 +02:00
|
|
|
z: configNodeScope,
|
2015-09-23 23:49:48 +02:00
|
|
|
users: []
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-05-09 16:23:33 +02:00
|
|
|
for (var d in node_def.defaults) {
|
|
|
|
if (node_def.defaults[d].value) {
|
2016-06-29 23:53:14 +02:00
|
|
|
editing_config_node[d] = JSON.parse(JSON.stringify(node_def.defaults[d].value));
|
2014-05-09 16:23:33 +02:00
|
|
|
}
|
2015-06-29 17:12:18 +02:00
|
|
|
}
|
2015-11-06 12:08:07 +01:00
|
|
|
editing_config_node["_"] = node_def._;
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.push(editing_config_node);
|
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
RED.view.state(RED.state.EDITING);
|
|
|
|
var trayOptions = {
|
2016-05-03 16:45:29 +02:00
|
|
|
title: getEditStackTitle(), //(adding?RED._("editor.addNewConfig", {type:type}):RED._("editor.editConfig", {type:type})),
|
2016-02-28 00:13:19 +01:00
|
|
|
resize: function() {
|
2016-03-21 23:51:48 +01:00
|
|
|
if (editing_config_node && editing_config_node._def.oneditresize) {
|
2016-03-24 00:22:36 +01:00
|
|
|
var form = $("#node-config-dialog-edit-form");
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
editing_config_node._def.oneditresize.call(editing_config_node,{width:form.width(),height:form.height()});
|
|
|
|
} catch(err) {
|
2017-02-16 22:41:20 +01:00
|
|
|
console.log("oneditresize",editing_config_node.id,editing_config_node.type,err.toString());
|
2016-06-06 15:45:36 +02:00
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
},
|
2017-02-16 22:41:20 +01:00
|
|
|
open: function(tray, done) {
|
2016-02-28 00:13:19 +01:00
|
|
|
var trayHeader = tray.find(".editor-tray-header");
|
|
|
|
var trayFooter = tray.find(".editor-tray-footer");
|
2014-05-07 00:42:54 +02:00
|
|
|
|
2016-06-29 22:07:45 +02:00
|
|
|
if (node_def.hasUsers !== false) {
|
|
|
|
trayFooter.prepend('<div id="node-config-dialog-user-count"><i class="fa fa-info-circle"></i> <span></span></div>');
|
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
trayFooter.append('<span id="node-config-dialog-scope-container"><span id="node-config-dialog-scope-warning" data-i18n="[title]editor.errors.scopeChange"><i class="fa fa-warning"></i></span><select id="node-config-dialog-scope"></select></span>');
|
2015-05-06 23:14:00 +02:00
|
|
|
|
2017-01-30 00:01:31 +01:00
|
|
|
var dialogForm = buildEditForm(tray.find('.editor-tray-body'),"node-config-dialog-edit-form",type,ns);
|
2016-11-15 01:19:04 +01:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
prepareEditDialog(editing_config_node,node_def,"node-config-input", function() {
|
|
|
|
if (editing_config_node._def.exclusive) {
|
|
|
|
$("#node-config-dialog-scope").hide();
|
|
|
|
} else {
|
|
|
|
$("#node-config-dialog-scope").show();
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
2017-02-16 22:41:20 +01:00
|
|
|
$("#node-config-dialog-scope-warning").hide();
|
|
|
|
|
|
|
|
var nodeUserFlows = {};
|
|
|
|
editing_config_node.users.forEach(function(n) {
|
|
|
|
nodeUserFlows[n.z] = true;
|
|
|
|
});
|
|
|
|
var flowCount = Object.keys(nodeUserFlows).length;
|
|
|
|
var tabSelect = $("#node-config-dialog-scope").empty();
|
|
|
|
tabSelect.off("change");
|
|
|
|
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>');
|
|
|
|
RED.nodes.eachWorkspace(function(ws) {
|
|
|
|
var workspaceLabel = ws.label;
|
|
|
|
if (nodeUserFlows[ws.id]) {
|
|
|
|
workspaceLabel = "* "+workspaceLabel;
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
2017-02-16 22:41:20 +01:00
|
|
|
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==editing_config_node.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
2016-02-28 00:13:19 +01:00
|
|
|
});
|
2017-02-16 22:41:20 +01:00
|
|
|
tabSelect.append('<option disabled data-i18n="sidebar.config.subflows"></option>');
|
|
|
|
RED.nodes.eachSubflow(function(ws) {
|
|
|
|
var workspaceLabel = ws.name;
|
|
|
|
if (nodeUserFlows[ws.id]) {
|
|
|
|
workspaceLabel = "* "+workspaceLabel;
|
|
|
|
}
|
|
|
|
tabSelect.append('<option value="'+ws.id+'"'+(ws.id==editing_config_node.z?" selected":"")+'>'+workspaceLabel+'</option>');
|
|
|
|
});
|
|
|
|
if (flowCount > 0) {
|
|
|
|
tabSelect.on('change',function() {
|
|
|
|
var newScope = $(this).val();
|
|
|
|
if (newScope === '') {
|
|
|
|
// global scope - everyone can use it
|
|
|
|
$("#node-config-dialog-scope-warning").hide();
|
|
|
|
} else if (!nodeUserFlows[newScope] || flowCount > 1) {
|
|
|
|
// a user will loose access to it
|
|
|
|
$("#node-config-dialog-scope-warning").show();
|
|
|
|
} else {
|
|
|
|
$("#node-config-dialog-scope-warning").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
tabSelect.i18n();
|
2015-05-06 23:14:00 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
dialogForm.i18n();
|
|
|
|
if (node_def.hasUsers !== false) {
|
|
|
|
$("#node-config-dialog-user-count").find("span").html(RED._("editor.nodesUse", {count:editing_config_node.users.length})).parent().show();
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
2016-02-28 00:13:19 +01:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
RED.workspaces.refresh();
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.pop();
|
2016-03-21 23:51:48 +01:00
|
|
|
},
|
|
|
|
show: function() {
|
|
|
|
if (editing_config_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_config_node);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
trayOptions.buttons = [
|
2016-05-03 16:45:29 +02:00
|
|
|
{
|
|
|
|
id: "node-config-dialog-cancel",
|
|
|
|
text: RED._("common.label.cancel"),
|
|
|
|
click: function() {
|
|
|
|
var configType = type;
|
|
|
|
var configId = editing_config_node.id;
|
|
|
|
var configAdding = adding;
|
|
|
|
var configTypeDef = RED.nodes.getType(configType);
|
|
|
|
|
|
|
|
if (configTypeDef.oneditcancel) {
|
|
|
|
// TODO: what to pass as this to call
|
|
|
|
if (configTypeDef.oneditcancel) {
|
|
|
|
var cn = RED.nodes.node(configId);
|
|
|
|
if (cn) {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
configTypeDef.oneditcancel.call(cn,false);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditcancel",cn.id,cn.type,err.toString());
|
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
} else {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
configTypeDef.oneditcancel.call({id:configId},true);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditcancel",configId,configType,err.toString());
|
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
2016-02-28 00:13:19 +01:00
|
|
|
{
|
|
|
|
id: "node-config-dialog-ok",
|
|
|
|
text: adding?RED._("editor.configAdd"):RED._("editor.configUpdate"),
|
2016-05-03 16:45:29 +02:00
|
|
|
class: "primary",
|
2016-02-28 00:13:19 +01:00
|
|
|
click: function() {
|
|
|
|
var configProperty = name;
|
|
|
|
var configId = editing_config_node.id;
|
|
|
|
var configType = type;
|
|
|
|
var configAdding = adding;
|
|
|
|
var configTypeDef = RED.nodes.getType(configType);
|
|
|
|
var d;
|
|
|
|
var input;
|
|
|
|
var scope = $("#node-config-dialog-scope").val();
|
2016-04-19 22:41:26 +02:00
|
|
|
|
|
|
|
if (configTypeDef.oneditsave) {
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
configTypeDef.oneditsave.call(editing_config_node);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditsave",editing_config_node.id,editing_config_node.type,err.toString());
|
|
|
|
}
|
2016-04-19 22:41:26 +02:00
|
|
|
}
|
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
for (d in configTypeDef.defaults) {
|
|
|
|
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
2016-04-19 22:41:26 +02:00
|
|
|
var newValue;
|
2016-02-28 00:13:19 +01:00
|
|
|
input = $("#node-config-input-"+d);
|
|
|
|
if (input.attr('type') === "checkbox") {
|
2016-04-19 22:41:26 +02:00
|
|
|
newValue = input.prop('checked');
|
2016-10-12 20:54:43 +02:00
|
|
|
} else if ("format" in configTypeDef.defaults[d] && configTypeDef.defaults[d].format !== "" && input[0].nodeName === "DIV") {
|
|
|
|
newValue = input.text();
|
2016-02-28 00:13:19 +01:00
|
|
|
} else {
|
2016-04-19 22:41:26 +02:00
|
|
|
newValue = input.val();
|
|
|
|
}
|
2016-06-29 22:32:39 +02:00
|
|
|
if (newValue != null && newValue !== editing_config_node[d]) {
|
2016-04-19 22:41:26 +02:00
|
|
|
if (editing_config_node._def.defaults[d].type) {
|
|
|
|
if (newValue == "_ADD_") {
|
|
|
|
newValue = "";
|
|
|
|
}
|
|
|
|
// Change to a related config node
|
|
|
|
var configNode = RED.nodes.node(editing_config_node[d]);
|
|
|
|
if (configNode) {
|
|
|
|
var users = configNode.users;
|
|
|
|
users.splice(users.indexOf(editing_config_node),1);
|
|
|
|
}
|
|
|
|
configNode = RED.nodes.node(newValue);
|
|
|
|
if (configNode) {
|
|
|
|
configNode.users.push(editing_config_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editing_config_node[d] = newValue;
|
2015-09-25 22:49:53 +02:00
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
editing_config_node.label = configTypeDef.label;
|
|
|
|
editing_config_node.z = scope;
|
|
|
|
|
|
|
|
if (scope) {
|
2016-04-19 22:41:26 +02:00
|
|
|
// Search for nodes that use this one that are no longer
|
|
|
|
// in scope, so must be removed
|
2016-02-28 00:13:19 +01:00
|
|
|
editing_config_node.users = editing_config_node.users.filter(function(n) {
|
|
|
|
var keep = true;
|
|
|
|
for (var d in n._def.defaults) {
|
|
|
|
if (n._def.defaults.hasOwnProperty(d)) {
|
|
|
|
if (n._def.defaults[d].type === editing_config_node.type &&
|
|
|
|
n[d] === editing_config_node.id &&
|
|
|
|
n.z !== scope) {
|
|
|
|
keep = false;
|
2016-04-19 22:41:26 +02:00
|
|
|
// Remove the reference to this node
|
|
|
|
// and revalidate
|
2016-02-28 00:13:19 +01:00
|
|
|
n[d] = null;
|
|
|
|
n.dirty = true;
|
|
|
|
n.changed = true;
|
|
|
|
validateNode(n);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
return keep;
|
|
|
|
});
|
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
if (configAdding) {
|
|
|
|
RED.nodes.add(editing_config_node);
|
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
if (configTypeDef.credentials) {
|
|
|
|
updateNodeCredentials(editing_config_node,configTypeDef.credentials,"node-config-input");
|
|
|
|
}
|
|
|
|
validateNode(editing_config_node);
|
2016-04-26 17:56:13 +02:00
|
|
|
var validatedNodes = {};
|
|
|
|
validatedNodes[editing_config_node.id] = true;
|
|
|
|
|
|
|
|
var userStack = editing_config_node.users.slice();
|
|
|
|
while(userStack.length > 0) {
|
|
|
|
var user = userStack.pop();
|
|
|
|
if (!validatedNodes[user.id]) {
|
|
|
|
validatedNodes[user.id] = true;
|
|
|
|
if (user.users) {
|
|
|
|
userStack = userStack.concat(user.users);
|
|
|
|
}
|
|
|
|
validateNode(user);
|
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
RED.view.redraw(true);
|
2016-05-30 00:51:20 +02:00
|
|
|
if (!configAdding) {
|
|
|
|
RED.events.emit("editor:save",editing_config_node);
|
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
RED.tray.close(function() {
|
2016-04-19 22:41:26 +02:00
|
|
|
updateConfigNodeSelect(configProperty,configType,editing_config_node.id,prefix);
|
2016-03-21 23:51:48 +01:00
|
|
|
});
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!adding) {
|
|
|
|
trayOptions.buttons.unshift({
|
|
|
|
class: 'leftButton',
|
2016-05-03 16:45:29 +02:00
|
|
|
text: RED._("editor.configDelete"), //'<i class="fa fa-trash"></i>',
|
2016-02-28 00:13:19 +01:00
|
|
|
click: function() {
|
|
|
|
var configProperty = name;
|
|
|
|
var configId = editing_config_node.id;
|
|
|
|
var configType = type;
|
|
|
|
var configTypeDef = RED.nodes.getType(configType);
|
|
|
|
|
2016-06-06 15:45:36 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
if (configTypeDef.ondelete) {
|
|
|
|
// Deprecated: never documented but used by some early nodes
|
|
|
|
console.log("Deprecated API warning: config node type ",configType," has an ondelete function - should be oneditdelete");
|
|
|
|
configTypeDef.ondelete.call(editing_config_node);
|
|
|
|
}
|
|
|
|
if (configTypeDef.oneditdelete) {
|
|
|
|
configTypeDef.oneditdelete.call(editing_config_node);
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
console.log("oneditdelete",editing_config_node.id,editing_config_node.type,err.toString());
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
2016-06-06 15:45:36 +02:00
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
var historyEvent = {
|
|
|
|
t:'delete',
|
|
|
|
nodes:[editing_config_node],
|
|
|
|
changes: {},
|
|
|
|
dirty: RED.nodes.dirty()
|
|
|
|
}
|
|
|
|
for (var i=0;i<editing_config_node.users.length;i++) {
|
|
|
|
var user = editing_config_node.users[i];
|
|
|
|
historyEvent.changes[user.id] = {
|
|
|
|
changed: user.changed,
|
|
|
|
valid: user.valid
|
|
|
|
};
|
|
|
|
for (var d in user._def.defaults) {
|
|
|
|
if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
|
|
|
|
historyEvent.changes[user.id][d] = configId
|
|
|
|
user[d] = "";
|
|
|
|
user.changed = true;
|
|
|
|
user.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
validateNode(user);
|
|
|
|
}
|
2016-05-30 00:51:20 +02:00
|
|
|
RED.nodes.remove(configId);
|
2016-02-28 00:13:19 +01:00
|
|
|
RED.nodes.dirty(true);
|
2016-05-17 10:16:58 +02:00
|
|
|
RED.view.redraw(true);
|
2016-02-28 00:13:19 +01:00
|
|
|
RED.history.push(historyEvent);
|
2016-03-21 23:51:48 +01:00
|
|
|
RED.tray.close(function() {
|
2016-04-19 22:41:26 +02:00
|
|
|
updateConfigNodeSelect(configProperty,configType,"",prefix);
|
2016-03-21 23:51:48 +01:00
|
|
|
});
|
2015-09-23 23:49:48 +02:00
|
|
|
}
|
|
|
|
});
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
|
2016-02-28 00:13:19 +01:00
|
|
|
RED.tray.show(trayOptions);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2016-07-28 14:27:34 +02:00
|
|
|
function defaultConfigNodeSort(A,B) {
|
|
|
|
if (A.__label__ < B.__label__) {
|
|
|
|
return -1;
|
|
|
|
} else if (A.__label__ > B.__label__) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-31 14:01:49 +02:00
|
|
|
|
|
|
|
function updateConfigNodeSelect(name,type,value,prefix) {
|
|
|
|
// if prefix is null, there is no config select to update
|
|
|
|
if (prefix) {
|
|
|
|
var button = $("#"+prefix+"-edit-"+name);
|
|
|
|
if (button.length) {
|
|
|
|
if (value) {
|
|
|
|
button.text(RED._("editor.configEdit"));
|
|
|
|
} else {
|
|
|
|
button.text(RED._("editor.configAdd"));
|
|
|
|
}
|
|
|
|
$("#"+prefix+"-"+name).val(value);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var select = $("#"+prefix+"-"+name);
|
|
|
|
var node_def = RED.nodes.getType(type);
|
|
|
|
select.children().remove();
|
|
|
|
|
|
|
|
var activeWorkspace = RED.nodes.workspace(RED.workspaces.active());
|
|
|
|
if (!activeWorkspace) {
|
|
|
|
activeWorkspace = RED.nodes.subflow(RED.workspaces.active());
|
|
|
|
}
|
|
|
|
|
|
|
|
var configNodes = [];
|
|
|
|
|
|
|
|
RED.nodes.eachConfig(function(config) {
|
|
|
|
if (config.type == type && (!config.z || config.z === activeWorkspace.id)) {
|
2016-11-22 13:57:08 +01:00
|
|
|
var label = RED.utils.getNodeLabel(config,config.id);
|
2016-07-28 14:27:34 +02:00
|
|
|
config.__label__ = label;
|
|
|
|
configNodes.push(config);
|
2016-05-31 14:01:49 +02:00
|
|
|
}
|
|
|
|
});
|
2016-07-28 14:27:34 +02:00
|
|
|
var configSortFn = defaultConfigNodeSort;
|
|
|
|
if (typeof node_def.sort == "function") {
|
|
|
|
configSortFn = node_def.sort;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
configNodes.sort(configSortFn);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+node_def.type+".sort",err);
|
|
|
|
}
|
2016-05-31 14:01:49 +02:00
|
|
|
|
|
|
|
configNodes.forEach(function(cn) {
|
2016-10-01 00:35:05 +02:00
|
|
|
select.append('<option value="'+cn.id+'"'+(value==cn.id?" selected":"")+'>'+RED.text.bidi.enforceTextDirectionWithUCC(cn.__label__)+'</option>');
|
2016-07-28 14:27:34 +02:00
|
|
|
delete cn.__label__;
|
2016-05-31 14:01:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
select.append('<option value="_ADD_"'+(value===""?" selected":"")+'>'+RED._("editor.addNewType", {type:type})+'</option>');
|
|
|
|
window.setTimeout(function() { select.change();},50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
function showEditSubflowDialog(subflow) {
|
|
|
|
var editing_node = subflow;
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.push(subflow);
|
2016-03-22 14:13:57 +01:00
|
|
|
RED.view.state(RED.state.EDITING);
|
|
|
|
var subflowEditor;
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
var trayOptions = {
|
2016-05-03 16:45:29 +02:00
|
|
|
title: getEditStackTitle(),
|
2013-09-05 16:02:48 +02:00
|
|
|
buttons: [
|
2016-05-03 16:45:29 +02:00
|
|
|
{
|
|
|
|
id: "node-dialog-cancel",
|
|
|
|
text: RED._("common.label.cancel"),
|
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
2013-09-05 16:02:48 +02:00
|
|
|
{
|
2016-03-22 14:13:57 +01:00
|
|
|
id: "node-dialog-ok",
|
2016-05-03 16:45:29 +02:00
|
|
|
class: "primary",
|
|
|
|
text: RED._("common.label.done"),
|
2013-09-05 16:02:48 +02:00
|
|
|
click: function() {
|
2016-03-22 14:13:57 +01:00
|
|
|
var i;
|
|
|
|
var changes = {};
|
|
|
|
var changed = false;
|
|
|
|
var wasDirty = RED.nodes.dirty();
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
var newName = $("#subflow-input-name").val();
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
if (newName != editing_node.name) {
|
|
|
|
changes['name'] = editing_node.name;
|
|
|
|
editing_node.name = newName;
|
|
|
|
changed = true;
|
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
var newDescription = subflowEditor.getValue();
|
2015-10-23 23:14:21 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
if (newDescription != editing_node.info) {
|
|
|
|
changes['info'] = editing_node.info;
|
|
|
|
editing_node.info = newDescription;
|
|
|
|
changed = true;
|
|
|
|
}
|
2018-03-20 21:39:46 +01:00
|
|
|
if (updateLabels(editing_node, changes, null)) {
|
2017-02-08 11:25:58 +01:00
|
|
|
changed = true;
|
|
|
|
}
|
2018-03-14 05:51:50 +01:00
|
|
|
var iconModule = $("#node-settings-icon-module-hidden").val();
|
|
|
|
var iconFile = $("#node-settings-icon-file-hidden").val();
|
|
|
|
var icon = (iconModule && iconFile) ? iconModule+"/"+iconFile : "";
|
|
|
|
if ((editing_node.icon === undefined && icon !== "node-red/subflow.png") ||
|
|
|
|
(editing_node.icon !== undefined && editing_node.icon !== icon)) {
|
|
|
|
changes.icon = editing_node.icon;
|
|
|
|
editing_node.icon = icon;
|
|
|
|
changed = true;
|
|
|
|
}
|
2015-10-23 23:14:21 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
RED.palette.refresh();
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
if (changed) {
|
2018-03-14 05:51:50 +01:00
|
|
|
var wasChanged = editing_node.changed;
|
|
|
|
editing_node.changed = true;
|
|
|
|
validateNode(editing_node);
|
2016-03-22 14:13:57 +01:00
|
|
|
var subflowInstances = [];
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type == "subflow:"+editing_node.id) {
|
|
|
|
subflowInstances.push({
|
|
|
|
id:n.id,
|
|
|
|
changed:n.changed
|
|
|
|
})
|
|
|
|
n.changed = true;
|
|
|
|
n.dirty = true;
|
|
|
|
updateNodeProperties(n);
|
2018-03-14 05:51:50 +01:00
|
|
|
validateNode(n);
|
2016-03-22 14:13:57 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
var historyEvent = {
|
|
|
|
t:'edit',
|
|
|
|
node:editing_node,
|
|
|
|
changes:changes,
|
|
|
|
dirty:wasDirty,
|
|
|
|
changed:wasChanged,
|
|
|
|
subflow: {
|
|
|
|
instances:subflowInstances
|
|
|
|
}
|
|
|
|
};
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
RED.history.push(historyEvent);
|
2015-03-19 11:49:56 +01:00
|
|
|
}
|
2016-03-22 14:13:57 +01:00
|
|
|
editing_node.dirty = true;
|
|
|
|
RED.tray.close();
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2017-02-08 11:25:58 +01:00
|
|
|
resize: function(dimensions) {
|
|
|
|
$(".editor-tray-content").height(dimensions.height - 78);
|
|
|
|
var form = $(".editor-tray-content form").height(dimensions.height - 78 - 40);
|
|
|
|
|
2016-03-24 00:22:36 +01:00
|
|
|
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
|
|
|
|
var editorRow = $("#dialog-form>div.node-text-editor-row");
|
|
|
|
var height = $("#dialog-form").height();
|
|
|
|
for (var i=0;i<rows.size();i++) {
|
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
}
|
|
|
|
height -= (parseInt($("#dialog-form").css("marginTop"))+parseInt($("#dialog-form").css("marginBottom")));
|
|
|
|
$(".node-text-editor").css("height",height+"px");
|
|
|
|
subflowEditor.resize();
|
2016-03-22 14:13:57 +01:00
|
|
|
},
|
|
|
|
open: function(tray) {
|
2017-02-08 11:25:58 +01:00
|
|
|
var trayFooter = tray.find(".editor-tray-footer");
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
|
|
|
trayBody.parent().css('overflow','hidden');
|
|
|
|
|
|
|
|
var stack = RED.stack.create({
|
|
|
|
container: trayBody,
|
|
|
|
singleExpanded: true
|
|
|
|
});
|
|
|
|
var nodeProperties = stack.add({
|
|
|
|
title: RED._("editor.nodeProperties"),
|
|
|
|
expanded: true
|
|
|
|
});
|
2017-04-07 00:17:06 +02:00
|
|
|
nodeProperties.content.addClass("editor-tray-content");
|
2017-02-08 11:25:58 +01:00
|
|
|
var portLabels = stack.add({
|
|
|
|
title: RED._("editor.portLabels")
|
|
|
|
});
|
2017-04-07 00:17:06 +02:00
|
|
|
portLabels.content.addClass("editor-tray-content");
|
2017-02-08 11:25:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-22 14:13:57 +01:00
|
|
|
if (editing_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
}
|
2017-02-08 11:25:58 +01:00
|
|
|
var dialogForm = buildEditForm(nodeProperties.content,"dialog-form","subflow-template");
|
2015-10-23 23:14:21 +02:00
|
|
|
subflowEditor = RED.editor.createEditor({
|
|
|
|
id: 'subflow-input-info-editor',
|
|
|
|
mode: 'ace/mode/markdown',
|
|
|
|
value: ""
|
|
|
|
});
|
2016-03-22 14:13:57 +01:00
|
|
|
|
2016-08-26 13:50:18 +02:00
|
|
|
$("#subflow-input-name").val(subflow.name);
|
|
|
|
RED.text.bidi.prepareInput($("#subflow-input-name"));
|
2016-05-03 16:45:29 +02:00
|
|
|
subflowEditor.getSession().setValue(subflow.info||"",-1);
|
2016-03-22 14:13:57 +01:00
|
|
|
var userCount = 0;
|
|
|
|
var subflowType = "subflow:"+editing_node.id;
|
|
|
|
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type === subflowType) {
|
|
|
|
userCount++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#subflow-dialog-user-count").html(RED._("subflow.subflowInstances", {count:userCount})).show();
|
2017-02-08 11:25:58 +01:00
|
|
|
|
|
|
|
buildLabelForm(portLabels.content,subflow);
|
2018-03-14 05:51:50 +01:00
|
|
|
validateIcon(subflow);
|
2017-02-08 11:25:58 +01:00
|
|
|
trayBody.i18n();
|
2015-10-23 23:14:21 +02:00
|
|
|
},
|
2016-03-22 14:13:57 +01:00
|
|
|
close: function() {
|
2015-05-26 22:52:23 +02:00
|
|
|
if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
|
|
|
|
RED.view.state(RED.state.DEFAULT);
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
RED.sidebar.info.refresh(editing_node);
|
2015-09-23 23:49:48 +02:00
|
|
|
RED.workspaces.refresh();
|
2017-06-26 15:23:48 +02:00
|
|
|
subflowEditor.destroy();
|
2016-05-03 16:45:29 +02:00
|
|
|
editStack.pop();
|
2015-05-26 22:52:23 +02:00
|
|
|
editing_node = null;
|
2015-10-23 23:14:21 +02:00
|
|
|
},
|
2016-03-22 14:13:57 +01:00
|
|
|
show: function() {
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2016-03-22 14:13:57 +01:00
|
|
|
}
|
|
|
|
RED.tray.show(trayOptions);
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2018-04-26 18:53:45 +02:00
|
|
|
function showTypeEditor(type, options) {
|
|
|
|
if (RED.editor.types.hasOwnProperty(type)) {
|
|
|
|
if (editStack.length > 0) {
|
|
|
|
options.parent = editStack[editStack.length-1].id;
|
2017-09-21 12:19:24 +02:00
|
|
|
}
|
2018-04-26 18:53:45 +02:00
|
|
|
editStack.push({type:type});
|
|
|
|
options.title = options.title || getEditStackTitle();
|
|
|
|
options.onclose = function() {
|
2017-09-20 11:30:07 +02:00
|
|
|
editStack.pop();
|
2017-06-11 22:19:46 +02:00
|
|
|
}
|
2018-04-26 18:53:45 +02:00
|
|
|
RED.editor.types[type].show(options);
|
|
|
|
} else {
|
|
|
|
console.log("Unknown type editor:",type);
|
2017-06-11 22:19:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
return {
|
2016-01-31 23:27:14 +01:00
|
|
|
init: function() {
|
|
|
|
RED.tray.init();
|
2016-12-04 23:59:43 +01:00
|
|
|
RED.actions.add("core:confirm-edit-tray", function() {
|
|
|
|
$("#node-dialog-ok").click();
|
|
|
|
$("#node-config-dialog-ok").click();
|
|
|
|
});
|
|
|
|
RED.actions.add("core:cancel-edit-tray", function() {
|
|
|
|
$("#node-dialog-cancel").click();
|
|
|
|
$("#node-config-dialog-cancel").click();
|
2016-05-03 16:45:29 +02:00
|
|
|
});
|
2018-04-26 18:53:45 +02:00
|
|
|
|
|
|
|
for (var type in RED.editor.types) {
|
|
|
|
if (RED.editor.types.hasOwnProperty(type)) {
|
|
|
|
RED.editor.types[type].init();
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
},
|
2018-04-26 18:53:45 +02:00
|
|
|
types: {},
|
2013-09-05 16:02:48 +02:00
|
|
|
edit: showEditDialog,
|
2014-01-25 23:31:43 +01:00
|
|
|
editConfig: showEditConfigNodeDialog,
|
2014-02-25 00:35:11 +01:00
|
|
|
editSubflow: showEditSubflowDialog,
|
2018-04-26 18:53:45 +02:00
|
|
|
editExpression: function(options) { showTypeEditor("_expression", options) },
|
|
|
|
editJSON: function(options) { showTypeEditor("_json", options) },
|
|
|
|
editMarkdown: function(options) { showTypeEditor("_markdown", options) },
|
|
|
|
editBuffer: function(options) { showTypeEditor("_buffer", options) },
|
|
|
|
buildEditForm: buildEditForm,
|
2013-09-05 16:02:48 +02:00
|
|
|
validateNode: validateNode,
|
2015-02-26 22:29:56 +01:00
|
|
|
updateNodeProperties: updateNodeProperties, // TODO: only exposed for edit-undo
|
2015-05-07 17:44:55 +02:00
|
|
|
|
2017-05-05 12:23:24 +02:00
|
|
|
|
2015-02-26 22:29:56 +01:00
|
|
|
createEditor: function(options) {
|
2017-09-20 11:30:07 +02:00
|
|
|
var editor = ace.edit(options.id||options.element);
|
2015-02-26 22:29:56 +01:00
|
|
|
editor.setTheme("ace/theme/tomorrow");
|
2015-05-07 22:12:46 +02:00
|
|
|
var session = editor.getSession();
|
2018-01-14 14:24:12 +01:00
|
|
|
session.on("changeAnnotation", function () {
|
|
|
|
var annotations = session.getAnnotations() || [];
|
|
|
|
var i = annotations.length;
|
|
|
|
var len = annotations.length;
|
|
|
|
while (i--) {
|
|
|
|
if (/doctype first\. Expected/.test(annotations[i].text)) { annotations.splice(i, 1); }
|
|
|
|
else if (/Unexpected End of file\. Expected/.test(annotations[i].text)) { annotations.splice(i, 1); }
|
|
|
|
}
|
|
|
|
if (len > annotations.length) { session.setAnnotations(annotations); }
|
|
|
|
});
|
2015-02-26 22:29:56 +01:00
|
|
|
if (options.mode) {
|
2015-05-07 22:12:46 +02:00
|
|
|
session.setMode(options.mode);
|
2015-02-26 22:29:56 +01:00
|
|
|
}
|
|
|
|
if (options.foldStyle) {
|
2015-05-07 22:12:46 +02:00
|
|
|
session.setFoldStyle(options.foldStyle);
|
2015-02-26 22:29:56 +01:00
|
|
|
} else {
|
2015-05-07 22:12:46 +02:00
|
|
|
session.setFoldStyle('markbeginend');
|
2015-02-26 22:29:56 +01:00
|
|
|
}
|
|
|
|
if (options.options) {
|
|
|
|
editor.setOptions(options.options);
|
|
|
|
} else {
|
|
|
|
editor.setOptions({
|
|
|
|
enableBasicAutocompletion:true,
|
|
|
|
enableSnippets:true
|
|
|
|
});
|
|
|
|
}
|
2017-05-05 12:23:24 +02:00
|
|
|
if (options.readOnly) {
|
|
|
|
editor.setOption('readOnly',options.readOnly);
|
2017-06-11 22:19:46 +02:00
|
|
|
editor.container.classList.add("ace_read-only");
|
2017-05-05 12:23:24 +02:00
|
|
|
}
|
|
|
|
if (options.hasOwnProperty('lineNumbers')) {
|
|
|
|
editor.renderer.setOption('showGutter',options.lineNumbers);
|
|
|
|
}
|
2015-02-26 22:29:56 +01:00
|
|
|
editor.$blockScrolling = Infinity;
|
2015-05-07 22:12:46 +02:00
|
|
|
if (options.value) {
|
|
|
|
session.setValue(options.value,-1);
|
|
|
|
}
|
2016-07-28 18:14:55 +02:00
|
|
|
if (options.globals) {
|
|
|
|
setTimeout(function() {
|
|
|
|
if (!!session.$worker) {
|
2018-01-14 14:24:12 +01:00
|
|
|
session.$worker.send("setOptions", [{globals: options.globals, esversion:6, sub:true, asi:true, maxerr:1000}]);
|
2016-07-28 18:14:55 +02:00
|
|
|
}
|
|
|
|
},100);
|
|
|
|
}
|
2015-02-26 22:29:56 +01:00
|
|
|
return editor;
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
})();
|