2013-09-05 16:02:48 +02:00
|
|
|
/**
|
2014-05-27 17:06:25 +02:00
|
|
|
* Copyright 2013, 2014 IBM Corp.
|
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() {
|
2013-09-05 16:02:48 +02:00
|
|
|
var editing_node = null;
|
|
|
|
// TODO: should IMPORT/EXPORT get their own dialogs?
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Validate a node
|
|
|
|
* @param node - the node being validated
|
|
|
|
* @returns {boolean} whether the node is valid. Sets node.dirty if needed
|
|
|
|
*/
|
|
|
|
function validateNode(node) {
|
|
|
|
var oldValue = node.valid;
|
|
|
|
node.valid = validateNodeProperties(node, node._def.defaults, node);
|
|
|
|
if (node._def._creds) {
|
|
|
|
node.valid = node.valid && validateNodeProperties(node, node._def.credentials, node._def._creds);
|
|
|
|
}
|
|
|
|
if (oldValue != node.valid) {
|
|
|
|
node.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
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]) {
|
|
|
|
valid = definition[property].validate.call(node,value);
|
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_") {
|
|
|
|
valid = false;
|
|
|
|
} else {
|
2013-11-18 22:17:29 +01:00
|
|
|
var v = RED.nodes.node(value).valid;
|
|
|
|
valid = (v==null || v);
|
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
|
|
|
|
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
|
|
|
|
* @returns {array} the links that were removed due to this update
|
|
|
|
*/
|
2013-09-05 16:02:48 +02:00
|
|
|
function updateNodeProperties(node) {
|
|
|
|
node.resize = true;
|
|
|
|
node.dirty = true;
|
|
|
|
var removedLinks = [];
|
2014-02-25 00:35:11 +01:00
|
|
|
if (node.ports) {
|
|
|
|
if (node.outputs < node.ports.length) {
|
|
|
|
while (node.outputs < node.ports.length) {
|
|
|
|
node.ports.pop();
|
|
|
|
}
|
|
|
|
RED.nodes.eachLink(function(l) {
|
|
|
|
if (l.source === node && l.sourcePort >= node.outputs) {
|
|
|
|
removedLinks.push(l);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} 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) {
|
2013-09-05 16:02:48 +02:00
|
|
|
RED.nodes.eachLink(function(l) {
|
2014-02-25 00:35:11 +01:00
|
|
|
if (l.target === node) {
|
|
|
|
removedLinks.push(l);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
});
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
$( "#dialog" ).dialog({
|
|
|
|
modal: true,
|
|
|
|
autoOpen: false,
|
2013-11-21 12:02:31 +01:00
|
|
|
closeOnEscape: false,
|
2013-09-05 16:02:48 +02:00
|
|
|
width: 500,
|
|
|
|
buttons: [
|
|
|
|
{
|
2014-09-08 15:41:39 +02:00
|
|
|
id: "node-dialog-ok",
|
2013-09-05 16:02:48 +02:00
|
|
|
text: "Ok",
|
|
|
|
click: function() {
|
|
|
|
if (editing_node) {
|
|
|
|
var changes = {};
|
|
|
|
var changed = false;
|
|
|
|
var wasDirty = RED.view.dirty();
|
2014-08-08 01:01:35 +02:00
|
|
|
var d;
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
if (editing_node._def.oneditsave) {
|
2013-10-12 22:54:07 +02:00
|
|
|
var oldValues = {};
|
2014-08-08 01:01:35 +02:00
|
|
|
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;
|
|
|
|
}
|
2013-10-12 22:54:07 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-19 21:31:42 +01:00
|
|
|
var rc = editing_node._def.oneditsave.call(editing_node);
|
|
|
|
if (rc === true) {
|
|
|
|
changed = true;
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-08-08 01:01:35 +02: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;
|
|
|
|
}
|
2013-10-12 22:54:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
if (editing_node._def.defaults) {
|
2014-08-08 01:01:35 +02:00
|
|
|
for (d in editing_node._def.defaults) {
|
|
|
|
if (editing_node._def.defaults.hasOwnProperty(d)) {
|
|
|
|
var input = $("#node-input-"+d);
|
|
|
|
var newValue;
|
|
|
|
if (input.attr('type') === "checkbox") {
|
|
|
|
newValue = input.prop('checked');
|
|
|
|
} else {
|
|
|
|
newValue = input.val();
|
|
|
|
}
|
|
|
|
if (newValue != null) {
|
|
|
|
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);
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
|
|
|
|
changes[d] = editing_node[d];
|
|
|
|
editing_node[d] = newValue;
|
|
|
|
changed = true;
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
if (editing_node._def.credentials) {
|
2014-05-07 20:19:08 +02:00
|
|
|
var prefix = 'node-input';
|
|
|
|
var credDefinition = editing_node._def.credentials;
|
2014-07-19 01:16:21 +02:00
|
|
|
var credsChanged = updateNodeCredentials(editing_node,credDefinition,prefix);
|
|
|
|
changed = changed || credsChanged;
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
var removedLinks = updateNodeProperties(editing_node);
|
|
|
|
if (changed) {
|
2013-12-19 22:34:25 +01:00
|
|
|
var wasChanged = editing_node.changed;
|
2013-11-18 22:17:29 +01:00
|
|
|
editing_node.changed = true;
|
2013-10-12 22:54:07 +02:00
|
|
|
RED.view.dirty(true);
|
2013-12-19 22:34:25 +01:00
|
|
|
RED.history.push({t:'edit',node:editing_node,changes:changes,links:removedLinks,dirty:wasDirty,changed:wasChanged});
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
editing_node.dirty = true;
|
|
|
|
validateNode(editing_node);
|
|
|
|
RED.view.redraw();
|
|
|
|
} else if (RED.view.state() == RED.state.EXPORT) {
|
|
|
|
if (/library/.test($( "#dialog" ).dialog("option","title"))) {
|
|
|
|
//TODO: move this to RED.library
|
|
|
|
var flowName = $("#node-input-filename").val();
|
|
|
|
if (!/^\s*$/.test(flowName)) {
|
2014-11-05 23:41:05 +01:00
|
|
|
$.ajax({
|
|
|
|
url:'library/flows/'+flowName,
|
|
|
|
type: "POST",
|
|
|
|
data: $("#node-input-filename").attr('nodes'),
|
|
|
|
contentType: "application/json; charset=utf-8"
|
|
|
|
}).done(function() {
|
2013-09-05 16:02:48 +02:00
|
|
|
RED.library.loadFlowLibrary();
|
|
|
|
RED.notify("Saved nodes","success");
|
|
|
|
});
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
} else if (RED.view.state() == RED.state.IMPORT) {
|
|
|
|
RED.view.importNodes($("#node-input-import").val());
|
|
|
|
}
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-09-08 15:41:39 +02:00
|
|
|
id: "node-dialog-cancel",
|
2013-09-05 16:02:48 +02:00
|
|
|
text: "Cancel",
|
|
|
|
click: function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(e,ui) {
|
|
|
|
if (editing_node) {
|
|
|
|
$(this).dialog('option',"sizeCache-"+editing_node.type,ui.size);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
open: function(e) {
|
|
|
|
RED.keyboard.disable();
|
|
|
|
if (editing_node) {
|
|
|
|
var size = $(this).dialog('option','sizeCache-'+editing_node.type);
|
|
|
|
if (size) {
|
|
|
|
$(this).dialog('option','width',size.width);
|
|
|
|
$(this).dialog('option','height',size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function(e) {
|
|
|
|
RED.keyboard.enable();
|
|
|
|
|
|
|
|
if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
|
2014-01-25 23:31:43 +01:00
|
|
|
RED.view.state(RED.state.DEFAULT);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
$( this ).dialog('option','height','auto');
|
|
|
|
$( this ).dialog('option','width','500');
|
2014-02-27 17:28:12 +01:00
|
|
|
if (editing_node) {
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
}
|
2014-02-26 23:58:44 +01:00
|
|
|
RED.sidebar.config.refresh();
|
2014-02-25 00:35:11 +01:00
|
|
|
|
|
|
|
var buttons = $( this ).dialog("option","buttons");
|
|
|
|
if (buttons.length == 3) {
|
|
|
|
$( this ).dialog("option","buttons",buttons.splice(1));
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
editing_node = null;
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
*/
|
|
|
|
function prepareConfigNodeSelect(node,property,type) {
|
|
|
|
var input = $("#node-input-"+property);
|
|
|
|
var node_def = RED.nodes.getType(type);
|
|
|
|
|
|
|
|
input.replaceWith('<select style="width: 60%;" id="node-input-'+property+'"></select>');
|
|
|
|
updateConfigNodeSelect(property,type,node[property]);
|
|
|
|
var select = $("#node-input-"+property);
|
2014-08-19 23:58:52 +02:00
|
|
|
select.after(' <a id="node-input-lookup-'+property+'" class="btn"><i class="fa fa-pencil"></i></a>');
|
2014-05-07 00:42:54 +02:00
|
|
|
$('#node-input-lookup-'+property).click(function(e) {
|
|
|
|
showEditConfigNodeDialog(property,type,select.find(":selected").val());
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
var label = "";
|
|
|
|
var configNode = RED.nodes.node(node[property]);
|
|
|
|
if (configNode && node_def.label) {
|
|
|
|
if (typeof node_def.label == "function") {
|
|
|
|
label = node_def.label.call(configNode);
|
|
|
|
} else {
|
|
|
|
label = node_def.label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input.val(label);
|
|
|
|
}
|
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)
|
|
|
|
*/
|
|
|
|
function preparePropertyEditor(node,property,prefix) {
|
|
|
|
var input = $("#"+prefix+"-"+property);
|
|
|
|
if (input.attr('type') === "checkbox") {
|
|
|
|
input.prop('checked',node[property]);
|
|
|
|
} else {
|
|
|
|
var val = node[property];
|
|
|
|
if (val == null) {
|
|
|
|
val = "";
|
|
|
|
}
|
|
|
|
input.val(val);
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2014-05-07 00:42:54 +02:00
|
|
|
$("#"+prefix+"-"+property).change(function() {
|
2014-05-16 09:34:23 +02:00
|
|
|
if (!validateNodeProperty(node, definition, property,this.value)) {
|
2014-05-07 00:42:54 +02:00
|
|
|
$(this).addClass("input-error");
|
|
|
|
} else {
|
|
|
|
$(this).removeClass("input-error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
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 {
|
|
|
|
preparePropertyEditor(credData, cred, prefix);
|
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-08-08 01:01:35 +02:00
|
|
|
for (cred in credDef) {
|
2014-07-19 01:16:21 +02:00
|
|
|
if (credDef.hasOwnProperty(cred)) {
|
2014-06-24 12:13:19 +02:00
|
|
|
$("#" + prefix + "-" + cred).change();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
}
|
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)
|
|
|
|
*/
|
|
|
|
function prepareEditDialog(node,definition,prefix) {
|
|
|
|
for (var d in definition.defaults) {
|
2014-08-08 01:01:35 +02:00
|
|
|
if (definition.defaults.hasOwnProperty(d)) {
|
|
|
|
if (definition.defaults[d].type) {
|
|
|
|
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
|
|
|
|
} else {
|
|
|
|
preparePropertyEditor(node,d,prefix);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
definition.oneditprepare.call(node);
|
|
|
|
}
|
|
|
|
for (var d in definition.defaults) {
|
2014-08-08 01:01:35 +02:00
|
|
|
if (definition.defaults.hasOwnProperty(d)) {
|
|
|
|
$("#"+prefix+"-"+d).change();
|
|
|
|
}
|
2014-07-19 01:16:21 +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
|
|
|
|
2014-05-07 00:42:54 +02:00
|
|
|
function showEditDialog(node) {
|
|
|
|
editing_node = node;
|
|
|
|
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";
|
|
|
|
var id = editing_node.type.substring(8);
|
|
|
|
var buttons = $( "#dialog" ).dialog("option","buttons");
|
|
|
|
buttons.unshift({
|
|
|
|
class: 'leftButton',
|
|
|
|
text: "Edit flow",
|
|
|
|
click: function() {
|
|
|
|
RED.view.showSubflow(id);
|
|
|
|
$("#node-dialog-ok").click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$( "#dialog" ).dialog("option","buttons",buttons);
|
|
|
|
}
|
|
|
|
$("#dialog-form").html($("script[data-template-name='"+type+"']").html());
|
2014-08-28 21:55:19 +02:00
|
|
|
$('<input type="text" style="display: none;" />').appendTo("#dialog-form");
|
2014-05-07 00:42:54 +02:00
|
|
|
prepareEditDialog(node,node._def,"node-input");
|
2014-02-25 00:35:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$( "#dialog" ).dialog("option","title","Edit "+type+" node").dialog( "open" );
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function showEditConfigNodeDialog(name,type,id) {
|
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);
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
var configNode = RED.nodes.node(id);
|
2014-05-07 00:42:54 +02:00
|
|
|
if (configNode == null) {
|
|
|
|
configNode = {
|
|
|
|
id: (1+Math.random()*4294967295).toString(16),
|
|
|
|
_def: node_def,
|
|
|
|
type: type
|
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) {
|
|
|
|
configNode[d] = node_def.defaults[d].value;
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
|
|
|
|
$("#dialog-config-form").html($("script[data-template-name='"+type+"']").html());
|
|
|
|
prepareEditDialog(configNode,node_def,"node-config-input");
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
var buttons = $( "#node-config-dialog" ).dialog("option","buttons");
|
2014-05-07 00:42:54 +02:00
|
|
|
if (adding) {
|
2013-09-05 16:02:48 +02:00
|
|
|
if (buttons.length == 3) {
|
|
|
|
buttons = buttons.splice(1);
|
|
|
|
}
|
|
|
|
buttons[0].text = "Add";
|
|
|
|
$("#node-config-dialog-user-count").html("").hide();
|
|
|
|
} else {
|
|
|
|
if (buttons.length == 2) {
|
|
|
|
buttons.unshift({
|
|
|
|
class: 'leftButton',
|
|
|
|
text: "Delete",
|
|
|
|
click: function() {
|
|
|
|
var configProperty = $(this).dialog('option','node-property');
|
|
|
|
var configId = $(this).dialog('option','node-id');
|
|
|
|
var configType = $(this).dialog('option','node-type');
|
|
|
|
var configNode = RED.nodes.node(configId);
|
|
|
|
var configTypeDef = RED.nodes.getType(configType);
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
if (configTypeDef.ondelete) {
|
|
|
|
configTypeDef.ondelete.call(RED.nodes.node(configId));
|
|
|
|
}
|
|
|
|
RED.nodes.remove(configId);
|
2014-08-08 01:01:35 +02:00
|
|
|
for (var i=0;i<configNode.users.length;i++) {
|
2013-09-05 16:02:48 +02:00
|
|
|
var user = configNode.users[i];
|
|
|
|
for (var d in user._def.defaults) {
|
2014-08-08 01:01:35 +02:00
|
|
|
if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
|
2013-09-05 16:02:48 +02:00
|
|
|
user[d] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
validateNode(user);
|
|
|
|
}
|
|
|
|
updateConfigNodeSelect(configProperty,configType,"");
|
|
|
|
RED.view.dirty(true);
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
RED.view.redraw();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
buttons[1].text = "Update";
|
|
|
|
$("#node-config-dialog-user-count").html(configNode.users.length+" node"+(configNode.users.length==1?" uses":"s use")+" this config").show();
|
|
|
|
}
|
|
|
|
$( "#node-config-dialog" ).dialog("option","buttons",buttons);
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
$( "#node-config-dialog" )
|
|
|
|
.dialog("option","node-adding",adding)
|
|
|
|
.dialog("option","node-property",name)
|
2014-05-07 00:42:54 +02:00
|
|
|
.dialog("option","node-id",configNode.id)
|
2013-09-05 16:02:48 +02:00
|
|
|
.dialog("option","node-type",type)
|
|
|
|
.dialog("option","title",(adding?"Add new ":"Edit ")+type+" config node")
|
|
|
|
.dialog( "open" );
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
function updateConfigNodeSelect(name,type,value) {
|
|
|
|
var select = $("#node-input-"+name);
|
2014-05-07 20:19:08 +02:00
|
|
|
var node_def = RED.nodes.getType(type);
|
2013-09-05 16:02:48 +02:00
|
|
|
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>');
|
|
|
|
}
|
|
|
|
});
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-08-08 01:01:35 +02:00
|
|
|
select.append('<option value="_ADD_"'+(value===""?" selected":"")+'>Add new '+type+'...</option>');
|
2013-11-17 18:49:32 +01:00
|
|
|
window.setTimeout(function() { select.change();},50);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
$( "#node-config-dialog" ).dialog({
|
|
|
|
modal: true,
|
|
|
|
autoOpen: false,
|
|
|
|
width: 500,
|
2013-11-21 12:02:31 +01:00
|
|
|
closeOnEscape: false,
|
2013-09-05 16:02:48 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2014-09-08 15:41:39 +02:00
|
|
|
id: "node-config-dialog-ok",
|
2013-09-05 16:02:48 +02:00
|
|
|
text: "Ok",
|
|
|
|
click: function() {
|
|
|
|
var configProperty = $(this).dialog('option','node-property');
|
|
|
|
var configId = $(this).dialog('option','node-id');
|
|
|
|
var configType = $(this).dialog('option','node-type');
|
|
|
|
var configAdding = $(this).dialog('option','node-adding');
|
|
|
|
var configTypeDef = RED.nodes.getType(configType);
|
2013-11-17 18:49:32 +01:00
|
|
|
var configNode;
|
2014-08-08 01:01:35 +02:00
|
|
|
var d;
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
if (configAdding) {
|
2013-11-17 18:49:32 +01:00
|
|
|
configNode = {type:configType,id:configId,users:[]};
|
2014-08-08 01:01:35 +02:00
|
|
|
for (d in configTypeDef.defaults) {
|
|
|
|
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
|
|
|
configNode[d] = $("#node-config-input-"+d).val();
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2013-11-17 18:49:32 +01:00
|
|
|
configNode.label = configTypeDef.label;
|
|
|
|
configNode._def = configTypeDef;
|
|
|
|
RED.nodes.add(configNode);
|
|
|
|
updateConfigNodeSelect(configProperty,configType,configNode.id);
|
2013-09-05 16:02:48 +02:00
|
|
|
} else {
|
2013-11-17 18:49:32 +01:00
|
|
|
configNode = RED.nodes.node(configId);
|
2014-08-08 01:01:35 +02:00
|
|
|
for (d in configTypeDef.defaults) {
|
|
|
|
if (configTypeDef.defaults.hasOwnProperty(d)) {
|
2014-09-01 10:11:10 +02:00
|
|
|
var input = $("#node-config-input-"+d);
|
|
|
|
if (input.attr('type') === "checkbox") {
|
|
|
|
configNode[d] = input.prop('checked');
|
|
|
|
} else {
|
|
|
|
configNode[d] = input.val();
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
updateConfigNodeSelect(configProperty,configType,configId);
|
|
|
|
}
|
2014-05-07 00:42:54 +02:00
|
|
|
if (configTypeDef.credentials) {
|
2014-07-19 01:16:21 +02:00
|
|
|
updateNodeCredentials(configNode,configTypeDef.credentials,"node-config-input");
|
2014-05-07 00:42:54 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
if (configTypeDef.oneditsave) {
|
|
|
|
configTypeDef.oneditsave.call(RED.nodes.node(configId));
|
|
|
|
}
|
2013-11-17 18:49:32 +01:00
|
|
|
validateNode(configNode);
|
2014-05-16 09:34:23 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
RED.view.dirty(true);
|
2014-05-16 09:34:23 +02:00
|
|
|
$(this).dialog("close");
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-09-08 15:41:39 +02:00
|
|
|
id: "node-config-dialog-cancel",
|
2013-09-05 16:02:48 +02:00
|
|
|
text: "Cancel",
|
|
|
|
click: function() {
|
|
|
|
var configType = $(this).dialog('option','node-type');
|
|
|
|
var configId = $(this).dialog('option','node-id');
|
|
|
|
var configAdding = $(this).dialog('option','node-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) {
|
|
|
|
configTypeDef.oneditcancel.call(cn,false);
|
|
|
|
} else {
|
|
|
|
configTypeDef.oneditcancel.call({id:configId},true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(e,ui) {
|
|
|
|
},
|
|
|
|
open: function(e) {
|
2014-01-25 23:31:43 +01:00
|
|
|
if (RED.view.state() != RED.state.EDITING) {
|
|
|
|
RED.keyboard.disable();
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
},
|
|
|
|
close: function(e) {
|
2014-04-08 16:32:58 +02:00
|
|
|
$("#dialog-config-form").html("");
|
2014-01-25 23:31:43 +01:00
|
|
|
if (RED.view.state() != RED.state.EDITING) {
|
|
|
|
RED.keyboard.enable();
|
|
|
|
}
|
2014-02-26 23:58:44 +01:00
|
|
|
RED.sidebar.config.refresh();
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
});
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
$( "#subflow-dialog" ).dialog({
|
|
|
|
modal: true,
|
|
|
|
autoOpen: false,
|
|
|
|
closeOnEscape: false,
|
|
|
|
width: 500,
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
class: 'leftButton',
|
|
|
|
text: "Delete",
|
|
|
|
click: function() {
|
|
|
|
var removedNodes = [];
|
|
|
|
var removedLinks = [];
|
|
|
|
var startDirty = RED.view.dirty();
|
|
|
|
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type == "subflow:"+editing_node.id) {
|
|
|
|
removedNodes.push(n);
|
|
|
|
}
|
|
|
|
if (n.z == editing_node.id) {
|
|
|
|
removedNodes.push(n);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var i=0;i<removedNodes.length;i++) {
|
|
|
|
var rmlinks = RED.nodes.remove(removedNodes[i].id);
|
|
|
|
removedLinks = removedLinks.concat(rmlinks);
|
|
|
|
}
|
|
|
|
|
|
|
|
RED.nodes.removeSubflow(editing_node);
|
|
|
|
|
|
|
|
RED.view.removeWorkspace(editing_node);
|
|
|
|
|
|
|
|
RED.history.push({
|
|
|
|
t:'delete',
|
|
|
|
nodes:removedNodes,
|
|
|
|
links:removedLinks,
|
|
|
|
subflow: editing_node,
|
|
|
|
dirty:startDirty
|
|
|
|
});
|
|
|
|
RED.view.dirty(true);
|
|
|
|
RED.view.redraw();
|
|
|
|
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "subflow-dialog-ok",
|
|
|
|
text: "Ok",
|
|
|
|
click: function() {
|
|
|
|
if (editing_node) {
|
|
|
|
var i;
|
|
|
|
var changes = {};
|
|
|
|
var changed = false;
|
|
|
|
var wasDirty = RED.view.dirty();
|
|
|
|
|
|
|
|
var newName = $("#subflow-input-name").val();
|
2014-11-07 12:22:00 +01:00
|
|
|
var newInCount = Number($("#subflow-input-inCount").val())||0;
|
|
|
|
var newOutCount = Number($("#subflow-input-outCount").val())||0;
|
2014-02-25 00:35:11 +01:00
|
|
|
|
|
|
|
var oldInCount = editing_node.in.length;
|
|
|
|
var oldOutCount = editing_node.out.length;
|
|
|
|
|
|
|
|
if (newName != editing_node.name) {
|
|
|
|
changes['name'] = editing_node.name;
|
|
|
|
editing_node.name = newName;
|
|
|
|
changed = true;
|
|
|
|
$("#btn-workspace-menu-"+editing_node.id.replace(".","-")).text("Subflow: "+newName);
|
|
|
|
}
|
|
|
|
|
|
|
|
var xpos = 40;
|
|
|
|
var addedOutputs = [];
|
|
|
|
var removedOutputs = [];
|
|
|
|
var addedInputs = [];
|
|
|
|
var removedInputs = [];
|
|
|
|
var removedLinks = [];
|
|
|
|
|
|
|
|
if (editing_node.in.length < newInCount) {
|
|
|
|
var l = editing_node.in.length;
|
|
|
|
for (i=l;i<newInCount;i++) {
|
2014-11-13 00:51:42 +01:00
|
|
|
var newInput = {type:"subflow",direction:"in",z:editing_node.id,i:i,x:xpos,y:70,id:RED.node.id()};
|
2014-02-25 00:35:11 +01:00
|
|
|
addedInputs.push(newInput);
|
|
|
|
editing_node.in.push(newInput);
|
|
|
|
xpos += 55;
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
} else if (editing_node.in.length > newInCount) {
|
|
|
|
removedInputs = editing_node.in.splice(newInCount);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (editing_node.out.length < newOutCount) {
|
|
|
|
for (i=editing_node.out.length;i<newOutCount;i++) {
|
2014-11-13 00:51:42 +01:00
|
|
|
var newOutput = {type:"subflow",direction:"out",z:editing_node.id,i:i,x:xpos,y:70,id:RED.node.id()};
|
2014-02-25 00:35:11 +01:00
|
|
|
addedOutputs.push(newOutput);
|
|
|
|
editing_node.out.push(newOutput);
|
|
|
|
xpos += 55;
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
} else if (editing_node.out.length > newOutCount) {
|
|
|
|
removedOutputs = editing_node.out.splice(newOutCount);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removedOutputs.length > 0 || removedInputs.length > 0) {
|
|
|
|
RED.nodes.eachLink(function(l) {
|
|
|
|
if (newInCount === 0 && l.source.type == "subflow" && l.source.z == editing_node.id) {
|
|
|
|
removedLinks.push(l);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (l.target.type == "subflow" && l.target.z == editing_node.id && l.target.i >= newOutCount) {
|
|
|
|
removedLinks.push(l);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
removedLinks.forEach(function(l) { RED.nodes.removeLink(l)});
|
|
|
|
}
|
|
|
|
RED.palette.refresh();
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type == "subflow:"+editing_node.id) {
|
|
|
|
n.changed = true;
|
|
|
|
n.inputs = editing_node.in.length;
|
|
|
|
n.outputs = editing_node.out.length;
|
|
|
|
removedLinks = removedLinks.concat(updateNodeProperties(n));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var wasChanged = editing_node.changed;
|
|
|
|
editing_node.changed = true;
|
|
|
|
RED.view.dirty(true);
|
|
|
|
var historyEvent = {
|
|
|
|
t:'edit',
|
|
|
|
node:editing_node,
|
|
|
|
changes:changes,
|
|
|
|
links:removedLinks,
|
|
|
|
dirty:wasDirty,
|
|
|
|
changed:wasChanged,
|
|
|
|
subflow: {
|
|
|
|
outputCount: oldOutCount,
|
|
|
|
inputCount: oldInCount,
|
|
|
|
outputs: removedOutputs,
|
|
|
|
inputs: removedInputs
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RED.history.push(historyEvent);
|
|
|
|
}
|
|
|
|
editing_node.dirty = true;
|
|
|
|
RED.view.redraw();
|
|
|
|
}
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "subflow-dialog-cancel",
|
|
|
|
text: "Cancel",
|
|
|
|
click: function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
editing_node = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
open: function(e) {
|
|
|
|
RED.keyboard.disable();
|
|
|
|
},
|
|
|
|
close: function(e) {
|
|
|
|
RED.keyboard.enable();
|
|
|
|
|
|
|
|
if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
|
|
|
|
RED.view.state(RED.state.DEFAULT);
|
|
|
|
}
|
|
|
|
RED.sidebar.info.refresh(editing_node);
|
|
|
|
editing_node = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function showEditSubflowDialog(subflow) {
|
|
|
|
editing_node = subflow;
|
|
|
|
RED.view.state(RED.state.EDITING);
|
|
|
|
$("#subflow-input-name").val(subflow.name);
|
|
|
|
$("#subflow-input-inCount").spinner({ min:0, max:1 }).val(subflow.in.length);
|
|
|
|
$("#subflow-input-outCount").spinner({ min:0 }).val(subflow.out.length);
|
|
|
|
var userCount = 0;
|
|
|
|
var subflowType = "subflow:"+editing_node.id;
|
|
|
|
|
|
|
|
RED.nodes.eachNode(function(n) {
|
|
|
|
if (n.type === subflowType) {
|
|
|
|
userCount++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$("#subflow-dialog-user-count").html("There "+(userCount==1?"is":"are")+" "+userCount+" instance"+(userCount==1?" ":"s")+" of this subflow").show();
|
|
|
|
$("#subflow-dialog").dialog("option","title","Edit flow "+subflow.name).dialog( "open" );
|
|
|
|
}
|
2014-05-07 20:19:08 +02:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
|
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
return {
|
|
|
|
edit: showEditDialog,
|
2014-01-25 23:31:43 +01:00
|
|
|
editConfig: showEditConfigNodeDialog,
|
2014-02-25 00:35:11 +01:00
|
|
|
editSubflow: showEditSubflowDialog,
|
2013-09-05 16:02:48 +02:00
|
|
|
validateNode: validateNode,
|
|
|
|
updateNodeProperties: updateNodeProperties // TODO: only exposed for edit-undo
|
|
|
|
}
|
2014-08-08 01:01:35 +02:00
|
|
|
})();
|