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

Fixed problem with RED._ being unavailable to module code

This commit is contained in:
Allen Boone 2015-05-26 16:52:23 -04:00 committed by Nick O'Leary
parent 5ea68dafc4
commit cb1d18c7c8
4 changed files with 508 additions and 485 deletions

View File

@ -200,6 +200,7 @@ var RED = (function() {
RED.workspaces.init(); RED.workspaces.init();
RED.clipboard.init(); RED.clipboard.init();
RED.view.init(); RED.view.init();
RED.editor.init();
RED.deploy.init(RED.settings.theme("deployButton",null)); RED.deploy.init(RED.settings.theme("deployButton",null));

View File

@ -16,64 +16,70 @@
RED.clipboard = (function() { RED.clipboard = (function() {
// TODO: Fix issue where text outside an inner function cannot be NLS-enabled since RED._ is not available yet when that code is run
var dialog = $('<div id="clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>')
.appendTo("body")
.dialog({
modal: true,
autoOpen: false,
width: 500,
resizable: false,
buttons: [
{
id: "clipboard-dialog-ok",
text: "Ok", //RED._("dialog.ok"),
click: function() {
if (/Import/.test(dialog.dialog("option","title"))) {
RED.view.importNodes($("#clipboard-import").val());
}
$( this ).dialog( "close" );
}
},
{
id: "clipboard-dialog-cancel",
text: "Cancel", //RED._("dialog.cancel"),
click: function() {
$( this ).dialog( "close" );
}
},
{
id: "clipboard-dialog-close",
text: "Close", //RED._("dialog.close"),
click: function() {
$( this ).dialog( "close" );
}
}
],
open: function(e) {
$(this).parent().find(".ui-dialog-titlebar-close").hide();
RED.keyboard.disable();
},
close: function(e) {
RED.keyboard.enable();
}
});
var dialogContainer = dialog.children(".dialog-form"); var dialog;
var dialogContainer;
var exportNodesDialog;
var importNodesDialog;
var exportNodesDialog = '<div class="form-row">'+ function setupDialogs(){
'<label for="node-input-export" style="display: block; width:100%;"><i class="fa fa-clipboard"></i>'+'Nodes:' /*RED._("dialog.nodes")*/+'</label>'+ dialog = $('<div id="clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>')
'<textarea readonly style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-export" rows="5"></textarea>'+ .appendTo("body")
'</div>'+ .dialog({
'<div class="form-tips">'+ modal: true,
'Select the text above and copy to the clipboard with Ctrl-C.'+ autoOpen: false,
//RED._("dialog.selectToCopy")+ width: 500,
'</div>'; resizable: false,
buttons: [
var importNodesDialog = '<div class="form-row">'+ {
'<textarea style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-import" rows="5" placeholder="'+'Paste nodes here' /*RED._("dialog.pasteNodesHere")*/+'"></textarea>'+ id: "clipboard-dialog-ok",
'</div>'; text: RED._("dialog.ok"),
click: function() {
if (/Import/.test(dialog.dialog("option","title"))) {
RED.view.importNodes($("#clipboard-import").val());
}
$( this ).dialog( "close" );
}
},
{
id: "clipboard-dialog-cancel",
text: RED._("dialog.cancel"),
click: function() {
$( this ).dialog( "close" );
}
},
{
id: "clipboard-dialog-close",
text: RED._("dialog.close"),
click: function() {
$( this ).dialog( "close" );
}
}
],
open: function(e) {
$(this).parent().find(".ui-dialog-titlebar-close").hide();
RED.keyboard.disable();
},
close: function(e) {
RED.keyboard.enable();
}
});
dialogContainer = dialog.children(".dialog-form");
exportNodesDialog = '<div class="form-row">'+
'<label for="node-input-export" style="display: block; width:100%;"><i class="fa fa-clipboard"></i>'+RED._("dialog.nodes")+'</label>'+
'<textarea readonly style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-export" rows="5"></textarea>'+
'</div>'+
'<div class="form-tips">'+
RED._("dialog.selectToCopy")+
'</div>';
importNodesDialog = '<div class="form-row">'+
'<textarea style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-import" rows="5" placeholder="'+RED._("dialog.pasteNodesHere")+'"></textarea>'+
'</div>';
}
function validateImport() { function validateImport() {
var importInput = $("#clipboard-import"); var importInput = $("#clipboard-import");
var v = importInput.val(); var v = importInput.val();
@ -88,7 +94,7 @@ RED.clipboard = (function() {
$("#clipboard-dialog-ok").button("disable"); $("#clipboard-dialog-ok").button("disable");
} }
} }
function importNodes() { function importNodes() {
dialogContainer.empty(); dialogContainer.empty();
dialogContainer.append($(importNodesDialog)); dialogContainer.append($(importNodesDialog));
@ -132,6 +138,7 @@ RED.clipboard = (function() {
return { return {
init: function() { init: function() {
setupDialogs();
RED.view.on("selection-changed",function(selection) { RED.view.on("selection-changed",function(selection) {
if (!selection.nodes) { if (!selection.nodes) {
RED.menu.setDisabled("menu-item-export",true); RED.menu.setDisabled("menu-item-export",true);

View File

@ -168,184 +168,186 @@ RED.editor = (function() {
return removedLinks; return removedLinks;
} }
$( "#dialog" ).dialog({ function createDialog(){
modal: true, $( "#dialog" ).dialog({
autoOpen: false, modal: true,
dialogClass: "ui-dialog-no-close", autoOpen: false,
closeOnEscape: false, dialogClass: "ui-dialog-no-close",
minWidth: 500, closeOnEscape: false,
width: 'auto', minWidth: 500,
buttons: [ width: 'auto',
{ buttons: [
id: "node-dialog-ok", {
text: "Ok", // RED._("dialog.ok"), id: "node-dialog-ok",
click: function() { text: RED._("dialog.ok"),
if (editing_node) { click: function() {
var changes = {}; if (editing_node) {
var changed = false; var changes = {};
var wasDirty = RED.nodes.dirty(); var changed = false;
var d; var wasDirty = RED.nodes.dirty();
var d;
if (editing_node._def.oneditsave) { if (editing_node._def.oneditsave) {
var oldValues = {}; var oldValues = {};
for (d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) { if (editing_node._def.defaults.hasOwnProperty(d)) {
if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") { if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") {
oldValues[d] = editing_node[d]; oldValues[d] = editing_node[d];
} else { } else {
oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v; oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v;
}
} }
} }
} var rc = editing_node._def.oneditsave.call(editing_node);
var rc = editing_node._def.oneditsave.call(editing_node); if (rc === true) {
if (rc === true) { changed = true;
changed = true; }
}
for (d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) { if (editing_node._def.defaults.hasOwnProperty(d)) {
if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") { if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") {
if (oldValues[d] !== editing_node[d]) { if (oldValues[d] !== editing_node[d]) {
changes[d] = oldValues[d]; changes[d] = oldValues[d];
changed = true; changed = true;
} }
} else { } else {
if (JSON.stringify(oldValues[d]) !== JSON.stringify(editing_node[d])) { if (JSON.stringify(oldValues[d]) !== JSON.stringify(editing_node[d])) {
changes[d] = oldValues[d]; changes[d] = oldValues[d];
changed = true; changed = true;
}
} }
} }
} }
} }
}
if (editing_node._def.defaults) { if (editing_node._def.defaults) {
for (d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) { if (editing_node._def.defaults.hasOwnProperty(d)) {
var input = $("#node-input-"+d); var input = $("#node-input-"+d);
var newValue; var newValue;
if (input.attr('type') === "checkbox") { if (input.attr('type') === "checkbox") {
newValue = input.prop('checked'); newValue = input.prop('checked');
} else { } else {
newValue = input.val(); newValue = input.val();
} }
if (newValue != null) { if (newValue != null) {
if (editing_node[d] != newValue) {
if (d === "outputs" && (newValue.trim() === "" || isNaN(newValue))) { if (d === "outputs" && (newValue.trim() === "" || isNaN(newValue))) {
continue; continue;
} }
if (editing_node._def.defaults[d].type) { if (editing_node[d] != newValue) {
if (newValue == "_ADD_") { if (editing_node._def.defaults[d].type) {
newValue = ""; if (newValue == "_ADD_") {
} newValue = "";
// Change to a related config node }
var configNode = RED.nodes.node(editing_node[d]); // Change to a related config node
if (configNode) { var configNode = RED.nodes.node(editing_node[d]);
var users = configNode.users; if (configNode) {
users.splice(users.indexOf(editing_node),1); var users = configNode.users;
} users.splice(users.indexOf(editing_node),1);
configNode = RED.nodes.node(newValue); }
if (configNode) { configNode = RED.nodes.node(newValue);
configNode.users.push(editing_node); if (configNode) {
configNode.users.push(editing_node);
}
} }
changes[d] = editing_node[d];
editing_node[d] = newValue;
changed = true;
} }
changes[d] = editing_node[d];
editing_node[d] = newValue;
changed = true;
} }
} }
} }
} }
} if (editing_node._def.credentials) {
if (editing_node._def.credentials) { var prefix = 'node-input';
var prefix = 'node-input'; var credDefinition = editing_node._def.credentials;
var credDefinition = editing_node._def.credentials; var credsChanged = updateNodeCredentials(editing_node,credDefinition,prefix);
var credsChanged = updateNodeCredentials(editing_node,credDefinition,prefix); changed = changed || credsChanged;
changed = changed || credsChanged; }
}
var removedLinks = updateNodeProperties(editing_node); var removedLinks = updateNodeProperties(editing_node);
if (changed) { if (changed) {
var wasChanged = editing_node.changed; var wasChanged = editing_node.changed;
editing_node.changed = true; editing_node.changed = true;
RED.nodes.dirty(true); RED.nodes.dirty(true);
RED.history.push({t:'edit',node:editing_node,changes:changes,links:removedLinks,dirty:wasDirty,changed:wasChanged}); RED.history.push({t:'edit',node:editing_node,changes:changes,links:removedLinks,dirty:wasDirty,changed:wasChanged});
} }
editing_node.dirty = true; editing_node.dirty = true;
validateNode(editing_node); validateNode(editing_node);
RED.view.redraw(); RED.view.redraw();
} else if (/Export nodes to library/.test($( "#dialog" ).dialog("option","title"))) { } else if (/Export nodes to library/.test($( "#dialog" ).dialog("option","title"))) {
//TODO: move this to RED.library //TODO: move this to RED.library
var flowName = $("#node-input-filename").val(); var flowName = $("#node-input-filename").val();
if (!/^\s*$/.test(flowName)) { if (!/^\s*$/.test(flowName)) {
$.ajax({ $.ajax({
url:'library/flows/'+flowName, url:'library/flows/'+flowName,
type: "POST", type: "POST",
data: $("#node-input-filename").attr('nodes'), data: $("#node-input-filename").attr('nodes'),
contentType: "application/json; charset=utf-8" contentType: "application/json; charset=utf-8"
}).done(function() { }).done(function() {
RED.library.loadFlowLibrary(); RED.library.loadFlowLibrary();
RED.notify(RED._("editor.savedNodes"),"success"); RED.notify(RED._("editor.savedNodes"),"success");
}); });
}
} }
$( this ).dialog( "close" );
} }
$( this ).dialog( "close" ); },
{
id: "node-dialog-cancel",
text: RED._("dialog.cancel"),
click: function() {
if (editing_node && editing_node._def) {
if (editing_node._def.oneditcancel) {
editing_node._def.oneditcancel.call(editing_node);
}
}
$( this ).dialog( "close" );
}
}
],
resize: function(e,ui) {
if (editing_node) {
$(this).dialog('option',"sizeCache-"+editing_node.type,ui.size);
} }
}, },
{ open: function(e) {
id: "node-dialog-cancel", var minWidth = $(this).dialog('option','minWidth');
text: "Cancel", // RED._("dialog.cancel"), if ($(this).outerWidth() < minWidth) {
click: function() { $(this).dialog('option','width',minWidth);
if (editing_node && editing_node._def) { } else {
if (editing_node._def.oneditcancel) { $(this).dialog('option','width',$(this).outerWidth());
editing_node._def.oneditcancel.call(editing_node); }
} 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);
} }
$( this ).dialog( "close" );
} }
} },
], close: function(e) {
resize: function(e,ui) { RED.keyboard.enable();
if (editing_node) {
$(this).dialog('option',"sizeCache-"+editing_node.type,ui.size); if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
} RED.view.state(RED.state.DEFAULT);
},
open: function(e) {
var minWidth = $(this).dialog('option','minWidth');
if ($(this).outerWidth() < minWidth) {
$(this).dialog('option','width',minWidth);
} else {
$(this).dialog('option','width',$(this).outerWidth());
}
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);
} }
} $( this ).dialog('option','height','auto');
}, $( this ).dialog('option','width','auto');
close: function(e) { if (editing_node) {
RED.keyboard.enable(); RED.sidebar.info.refresh(editing_node);
}
RED.sidebar.config.refresh();
if (RED.view.state() != RED.state.IMPORT_DRAGGING) { var buttons = $( this ).dialog("option","buttons");
RED.view.state(RED.state.DEFAULT); if (buttons.length == 3) {
$( this ).dialog("option","buttons",buttons.splice(1));
}
editing_node = null;
} }
$( this ).dialog('option','height','auto'); });
$( this ).dialog('option','width','auto'); }
if (editing_node) {
RED.sidebar.info.refresh(editing_node);
}
RED.sidebar.config.refresh();
var buttons = $( this ).dialog("option","buttons");
if (buttons.length == 3) {
$( this ).dialog("option","buttons",buttons.splice(1));
}
editing_node = null;
}
});
/** /**
* Create a config-node select box for this property * Create a config-node select box for this property
@ -603,7 +605,7 @@ RED.editor = (function() {
var adding = (id == "_ADD_"); var adding = (id == "_ADD_");
var node_def = RED.nodes.getType(type); var node_def = RED.nodes.getType(type);
var configNode = RED.nodes.node(id); var configNode = RED.nodes.node(id);
var ns; var ns;
if (node_def.set.module === "node-red") { if (node_def.set.module === "node-red") {
ns = "node-red"; ns = "node-red";
@ -611,7 +613,7 @@ RED.editor = (function() {
ns = node_def.set.id; ns = node_def.set.id;
} }
if (configNode == null) { if (configNode == null) {
configNode = { configNode = {
id: (1+Math.random()*4294967295).toString(16), id: (1+Math.random()*4294967295).toString(16),
@ -630,8 +632,8 @@ RED.editor = (function() {
} }
return RED._.apply(null,args); return RED._.apply(null,args);
} }
} }
$("#dialog-config-form").html($("script[data-template-name='"+type+"']").html()); $("#dialog-config-form").html($("script[data-template-name='"+type+"']").html());
@ -739,204 +741,207 @@ RED.editor = (function() {
window.setTimeout(function() { select.change();},50); window.setTimeout(function() { select.change();},50);
} }
} }
// TODO: Cannot NLS enable until RED._ is exposed function createNodeConfigDialog(){
$( "#node-config-dialog" ).dialog({ $( "#node-config-dialog" ).dialog({
modal: true,
autoOpen: false,
dialogClass: "ui-dialog-no-close",
minWidth: 500,
width: 'auto',
closeOnEscape: false,
buttons: [
{
id: "node-config-dialog-ok",
text: RED._("dialog.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);
var configNode;
var d;
var input;
if (configAdding) {
configNode = {type:configType,id:configId,users:[]};
for (d in configTypeDef.defaults) {
if (configTypeDef.defaults.hasOwnProperty(d)) {
input = $("#node-config-input-"+d);
if (input.attr('type') === "checkbox") {
configNode[d] = input.prop('checked');
} else {
configNode[d] = input.val();
}
}
}
configNode.label = configTypeDef.label;
configNode._def = configTypeDef;
RED.nodes.add(configNode);
updateConfigNodeSelect(configProperty,configType,configNode.id);
} else {
configNode = RED.nodes.node(configId);
for (d in configTypeDef.defaults) {
if (configTypeDef.defaults.hasOwnProperty(d)) {
input = $("#node-config-input-"+d);
if (input.attr('type') === "checkbox") {
configNode[d] = input.prop('checked');
} else {
configNode[d] = input.val();
}
}
}
updateConfigNodeSelect(configProperty,configType,configId);
}
if (configTypeDef.credentials) {
updateNodeCredentials(configNode,configTypeDef.credentials,"node-config-input");
}
if (configTypeDef.oneditsave) {
configTypeDef.oneditsave.call(RED.nodes.node(configId));
}
validateNode(configNode);
for (var i=0;i<configNode.users.length;i++) {
var user = configNode.users[i];
validateNode(user);
}
RED.nodes.dirty(true);
$(this).dialog("close");
}
},
{
id: "node-config-dialog-cancel",
text: RED._("dialog.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) {
var minWidth = $(this).dialog('option','minWidth');
if ($(this).outerWidth() < minWidth) {
$(this).dialog('option','width',minWidth);
}
if (RED.view.state() != RED.state.EDITING) {
RED.keyboard.disable();
}
},
close: function(e) {
$(this).dialog('option','width','auto');
$(this).dialog('option','height','auto');
$("#dialog-config-form").html("");
if (RED.view.state() != RED.state.EDITING) {
RED.keyboard.enable();
}
RED.sidebar.config.refresh();
}
});
}
function createSubflowDialog(){
$( "#subflow-dialog" ).dialog({
modal: true, modal: true,
autoOpen: false, autoOpen: false,
dialogClass: "ui-dialog-no-close", dialogClass: "ui-dialog-no-close",
closeOnEscape: false,
minWidth: 500, minWidth: 500,
width: 'auto', width: 'auto',
closeOnEscape: false,
buttons: [ buttons: [
{ {
id: "node-config-dialog-ok", id: "subflow-dialog-ok",
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
var configProperty = $(this).dialog('option','node-property'); if (editing_node) {
var configId = $(this).dialog('option','node-id'); var i;
var configType = $(this).dialog('option','node-type'); var changes = {};
var configAdding = $(this).dialog('option','node-adding'); var changed = false;
var configTypeDef = RED.nodes.getType(configType); var wasDirty = RED.nodes.dirty();
var configNode;
var d;
var input;
if (configAdding) { var newName = $("#subflow-input-name").val();
configNode = {type:configType,id:configId,users:[]};
for (d in configTypeDef.defaults) { if (newName != editing_node.name) {
if (configTypeDef.defaults.hasOwnProperty(d)) { changes['name'] = editing_node.name;
input = $("#node-config-input-"+d); editing_node.name = newName;
if (input.attr('type') === "checkbox") { changed = true;
configNode[d] = input.prop('checked'); $("#menu-item-workspace-menu-"+editing_node.id.replace(".","-")).text(RED._("editor.subflow")+newName);
} else { }
configNode[d] = input.val();
RED.palette.refresh();
if (changed) {
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+editing_node.id) {
n.changed = true;
updateNodeProperties(n);
} }
} });
} var wasChanged = editing_node.changed;
configNode.label = configTypeDef.label; editing_node.changed = true;
configNode._def = configTypeDef; RED.nodes.dirty(true);
RED.nodes.add(configNode); var historyEvent = {
updateConfigNodeSelect(configProperty,configType,configNode.id); t:'edit',
} else { node:editing_node,
configNode = RED.nodes.node(configId); changes:changes,
for (d in configTypeDef.defaults) { dirty:wasDirty,
if (configTypeDef.defaults.hasOwnProperty(d)) { changed:wasChanged
input = $("#node-config-input-"+d); };
if (input.attr('type') === "checkbox") {
configNode[d] = input.prop('checked');
} else {
configNode[d] = input.val();
}
}
}
updateConfigNodeSelect(configProperty,configType,configId);
}
if (configTypeDef.credentials) {
updateNodeCredentials(configNode,configTypeDef.credentials,"node-config-input");
}
if (configTypeDef.oneditsave) {
configTypeDef.oneditsave.call(RED.nodes.node(configId));
}
validateNode(configNode);
for (var i=0;i<configNode.users.length;i++) {
var user = configNode.users[i];
validateNode(user);
}
RED.nodes.dirty(true); RED.history.push(historyEvent);
$(this).dialog("close");
}
},
{
id: "node-config-dialog-cancel",
text: "Cancel", // RED._("dialog.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);
}
} }
editing_node.dirty = true;
RED.view.redraw();
} }
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
},
{
id: "subflow-dialog-cancel",
text: RED._("dialog.cancel"),
click: function() {
$( this ).dialog( "close" );
editing_node = null;
}
} }
], ],
resize: function(e,ui) {
},
open: function(e) { open: function(e) {
RED.keyboard.disable();
var minWidth = $(this).dialog('option','minWidth'); var minWidth = $(this).dialog('option','minWidth');
if ($(this).outerWidth() < minWidth) { if ($(this).outerWidth() < minWidth) {
$(this).dialog('option','width',minWidth); $(this).dialog('option','width',minWidth);
} }
if (RED.view.state() != RED.state.EDITING) {
RED.keyboard.disable();
}
}, },
close: function(e) { close: function(e) {
$(this).dialog('option','width','auto'); RED.keyboard.enable();
$(this).dialog('option','height','auto');
$("#dialog-config-form").html(""); if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
if (RED.view.state() != RED.state.EDITING) { RED.view.state(RED.state.DEFAULT);
RED.keyboard.enable();
} }
RED.sidebar.config.refresh(); RED.sidebar.info.refresh(editing_node);
editing_node = null;
} }
}); });
$("#subflow-dialog form" ).submit(function(e) { e.preventDefault();});
$( "#subflow-dialog" ).dialog({ }
modal: true,
autoOpen: false,
dialogClass: "ui-dialog-no-close",
closeOnEscape: false,
minWidth: 500,
width: 'auto',
buttons: [
{
id: "subflow-dialog-ok",
text: "Ok", // RED._("dialog.ok"),
click: function() {
if (editing_node) {
var i;
var changes = {};
var changed = false;
var wasDirty = RED.nodes.dirty();
var newName = $("#subflow-input-name").val();
if (newName != editing_node.name) {
changes['name'] = editing_node.name;
editing_node.name = newName;
changed = true;
$("#menu-item-workspace-menu-"+editing_node.id.replace(".","-")).text(RED._("editor.subflow")+newName);
}
RED.palette.refresh();
if (changed) {
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+editing_node.id) {
n.changed = true;
updateNodeProperties(n);
}
});
var wasChanged = editing_node.changed;
editing_node.changed = true;
RED.nodes.dirty(true);
var historyEvent = {
t:'edit',
node:editing_node,
changes:changes,
dirty:wasDirty,
changed:wasChanged
};
RED.history.push(historyEvent);
}
editing_node.dirty = true;
RED.view.redraw();
}
$( this ).dialog( "close" );
}
},
{
id: "subflow-dialog-cancel",
text: "Cancel", // RED._("dialog.cancel")
click: function() {
$( this ).dialog( "close" );
editing_node = null;
}
}
],
open: function(e) {
RED.keyboard.disable();
var minWidth = $(this).dialog('option','minWidth');
if ($(this).outerWidth() < minWidth) {
$(this).dialog('option','width',minWidth);
}
},
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;
}
});
$("#subflow-dialog form" ).submit(function(e) { e.preventDefault();});
function showEditSubflowDialog(subflow) { function showEditSubflowDialog(subflow) {
@ -951,7 +956,7 @@ RED.editor = (function() {
userCount++; userCount++;
} }
}); });
$("#subflow-dialog-user-count").html(RED._("editor.subflowInstances", {count:userCount})).show(); $("#subflow-dialog-user-count").html(RED._("editor.subflowInstances", {count:userCount})).show();
$("#subflow-dialog").dialog("option","title",RED._("editor.editFlow")+subflow.name).dialog( "open" ); $("#subflow-dialog").dialog("option","title",RED._("editor.editFlow")+subflow.name).dialog( "open" );
} }
@ -959,6 +964,11 @@ RED.editor = (function() {
return { return {
init: function(){
createDialog();
createNodeConfigDialog();
createSubflowDialog();
},
edit: showEditDialog, edit: showEditDialog,
editConfig: showEditConfigNodeDialog, editConfig: showEditConfigNodeDialog,
editSubflow: showEditSubflowDialog, editSubflow: showEditSubflowDialog,

View File

@ -78,120 +78,125 @@ RED.workspaces = (function() {
$( "#node-dialog-rename-workspace" ).dialog("open"); $( "#node-dialog-rename-workspace" ).dialog("open");
} }
var workspace_tabs = RED.tabs.create({ var workspace_tabs;
id: "workspace-tabs", function createWorkspaceTabs(){
onchange: function(tab) { workspace_tabs = RED.tabs.create({
if (tab.type == "subflow") { id: "workspace-tabs",
$("#workspace-toolbar").show(); onchange: function(tab) {
} else { if (tab.type == "subflow") {
$("#workspace-toolbar").hide(); $("#workspace-toolbar").show();
} } else {
var event = { $("#workspace-toolbar").hide();
old: activeWorkspace
}
activeWorkspace = tab.id;
event.workspace = activeWorkspace;
eventHandler.emit("change",event);
},
ondblclick: function(tab) {
if (tab.type != "subflow") {
showRenameWorkspaceDialog(tab.id);
} else {
RED.editor.editSubflow(RED.nodes.subflow(tab.id));
}
},
onadd: function(tab) {
RED.menu.addItem("menu-item-workspace",{
id:"menu-item-workspace-menu-"+tab.id.replace(".","-"),
label:tab.label,
onselect:function() {
workspace_tabs.activateTab(tab.id);
} }
}); var event = {
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1); old: activeWorkspace
}, }
onremove: function(tab) { activeWorkspace = tab.id;
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1); event.workspace = activeWorkspace;
RED.menu.removeItem("menu-item-workspace-menu-"+tab.id.replace(".","-"));
} eventHandler.emit("change",event);
}); },
ondblclick: function(tab) {
$("#node-dialog-rename-workspace form" ).submit(function(e) { e.preventDefault();}); if (tab.type != "subflow") {
$( "#node-dialog-rename-workspace" ).dialog({ showRenameWorkspaceDialog(tab.id);
modal: true, } else {
autoOpen: false, RED.editor.editSubflow(RED.nodes.subflow(tab.id));
width: 500,
title: "Rename sheet", // RED._("dialog.renameSheet"),
buttons: [
{
class: 'leftButton',
text: "Delete", // RED._("dialog.delete"),
click: function() {
var workspace = $(this).dialog('option','workspace');
$( this ).dialog( "close" );
deleteWorkspace(workspace);
} }
}, },
{ onadd: function(tab) {
text: "Ok", // RED._("dialog.ok"), RED.menu.addItem("menu-item-workspace",{
click: function() { id:"menu-item-workspace-menu-"+tab.id.replace(".","-"),
var workspace = $(this).dialog('option','workspace'); label:tab.label,
var label = $( "#node-input-workspace-name" ).val(); onselect:function() {
if (workspace.label != label) { workspace_tabs.activateTab(tab.id);
workspace_tabs.renameTab(workspace.id,label);
RED.nodes.dirty(true);
$("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(label);
// TODO: update entry in menu
} }
$( this ).dialog( "close" ); });
} RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1);
}, },
{ onremove: function(tab) {
text: "Cancel", // RED._("dialog.cancel"), RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1);
click: function() { RED.menu.removeItem("menu-item-workspace-menu-"+tab.id.replace(".","-"));
$( this ).dialog( "close" );
}
} }
], });
open: function(e) {
RED.keyboard.disable();
}, $("#node-dialog-rename-workspace form" ).submit(function(e) { e.preventDefault();});
close: function(e) { $( "#node-dialog-rename-workspace" ).dialog({
RED.keyboard.enable(); modal: true,
} autoOpen: false,
}); width: 500,
$( "#node-dialog-delete-workspace" ).dialog({ title: RED._("dialog.renameSheet"),
modal: true, buttons: [
autoOpen: false, {
width: 500, class: 'leftButton',
title: "Confirm delete", // RED._("dialog.confirmDelete"), text: RED._("dialog.delete"),
buttons: [ click: function() {
{ var workspace = $(this).dialog('option','workspace');
text: "Ok", // RED._("dialog.ok"), $( this ).dialog( "close" );
click: function() { deleteWorkspace(workspace);
var workspace = $(this).dialog('option','workspace'); }
deleteWorkspace(workspace,true); },
$( this ).dialog( "close" ); {
text: RED._("dialog.ok"),
click: function() {
var workspace = $(this).dialog('option','workspace');
var label = $( "#node-input-workspace-name" ).val();
if (workspace.label != label) {
workspace_tabs.renameTab(workspace.id,label);
RED.nodes.dirty(true);
$("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(label);
// TODO: update entry in menu
}
$( this ).dialog( "close" );
}
},
{
text: RED._("dialog.cancel"),
click: function() {
$( this ).dialog( "close" );
}
} }
],
open: function(e) {
RED.keyboard.disable();
}, },
{ close: function(e) {
text: "Cancel", // RED._("dialog.cancel"), RED.keyboard.enable();
click: function() { }
$( this ).dialog( "close" ); });
} $( "#node-dialog-delete-workspace" ).dialog({
modal: true,
autoOpen: false,
width: 500,
title: RED._("dialog.confirmDelete"),
buttons: [
{
text: RED._("dialog.ok"),
click: function() {
var workspace = $(this).dialog('option','workspace');
deleteWorkspace(workspace,true);
$( this ).dialog( "close" );
}
},
{
text: RED._("dialog.cancel"),
click: function() {
$( this ).dialog( "close" );
}
}
],
open: function(e) {
RED.keyboard.disable();
},
close: function(e) {
RED.keyboard.enable();
} }
],
open: function(e) {
RED.keyboard.disable();
},
close: function(e) {
RED.keyboard.enable();
}
}); });
}
function init() { function init() {
createWorkspaceTabs();
$('#btn-workspace-add-tab').on("click",function(e) {addWorkspace(); e.preventDefault()}); $('#btn-workspace-add-tab').on("click",function(e) {addWorkspace(); e.preventDefault()});
RED.sidebar.on("resize",workspace_tabs.resize); RED.sidebar.on("resize",workspace_tabs.resize);