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,8 +16,14 @@
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>') var dialog;
var dialogContainer;
var exportNodesDialog;
var importNodesDialog;
function setupDialogs(){
dialog = $('<div id="clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>')
.appendTo("body") .appendTo("body")
.dialog({ .dialog({
modal: true, modal: true,
@ -27,7 +33,7 @@ RED.clipboard = (function() {
buttons: [ buttons: [
{ {
id: "clipboard-dialog-ok", id: "clipboard-dialog-ok",
text: "Ok", //RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
if (/Import/.test(dialog.dialog("option","title"))) { if (/Import/.test(dialog.dialog("option","title"))) {
RED.view.importNodes($("#clipboard-import").val()); RED.view.importNodes($("#clipboard-import").val());
@ -37,14 +43,14 @@ RED.clipboard = (function() {
}, },
{ {
id: "clipboard-dialog-cancel", id: "clipboard-dialog-cancel",
text: "Cancel", //RED._("dialog.cancel"), text: RED._("dialog.cancel"),
click: function() { click: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
}, },
{ {
id: "clipboard-dialog-close", id: "clipboard-dialog-close",
text: "Close", //RED._("dialog.close"), text: RED._("dialog.close"),
click: function() { click: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
@ -59,20 +65,20 @@ RED.clipboard = (function() {
} }
}); });
var dialogContainer = dialog.children(".dialog-form"); dialogContainer = dialog.children(".dialog-form");
var exportNodesDialog = '<div class="form-row">'+ exportNodesDialog = '<div class="form-row">'+
'<label for="node-input-export" style="display: block; width:100%;"><i class="fa fa-clipboard"></i>'+'Nodes:' /*RED._("dialog.nodes")*/+'</label>'+ '<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>'+ '<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>'+
'<div class="form-tips">'+ '<div class="form-tips">'+
'Select the text above and copy to the clipboard with Ctrl-C.'+ RED._("dialog.selectToCopy")+
//RED._("dialog.selectToCopy")+
'</div>'; '</div>';
var importNodesDialog = '<div class="form-row">'+ 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>'+ '<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>'; '</div>';
}
function validateImport() { function validateImport() {
var importInput = $("#clipboard-import"); var importInput = $("#clipboard-import");
@ -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,6 +168,7 @@ RED.editor = (function() {
return removedLinks; return removedLinks;
} }
function createDialog(){
$( "#dialog" ).dialog({ $( "#dialog" ).dialog({
modal: true, modal: true,
autoOpen: false, autoOpen: false,
@ -178,7 +179,7 @@ RED.editor = (function() {
buttons: [ buttons: [
{ {
id: "node-dialog-ok", id: "node-dialog-ok",
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
if (editing_node) { if (editing_node) {
var changes = {}; var changes = {};
@ -230,10 +231,10 @@ RED.editor = (function() {
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[d] != newValue) {
if (editing_node._def.defaults[d].type) { if (editing_node._def.defaults[d].type) {
if (newValue == "_ADD_") { if (newValue == "_ADD_") {
newValue = ""; newValue = "";
@ -294,7 +295,7 @@ RED.editor = (function() {
}, },
{ {
id: "node-dialog-cancel", id: "node-dialog-cancel",
text: "Cancel", // RED._("dialog.cancel"), text: RED._("dialog.cancel"),
click: function() { click: function() {
if (editing_node && editing_node._def) { if (editing_node && editing_node._def) {
if (editing_node._def.oneditcancel) { if (editing_node._def.oneditcancel) {
@ -346,6 +347,7 @@ RED.editor = (function() {
editing_node = null; editing_node = null;
} }
}); });
}
/** /**
* Create a config-node select box for this property * Create a config-node select box for this property
@ -740,7 +742,7 @@ RED.editor = (function() {
} }
} }
// TODO: Cannot NLS enable until RED._ is exposed function createNodeConfigDialog(){
$( "#node-config-dialog" ).dialog({ $( "#node-config-dialog" ).dialog({
modal: true, modal: true,
autoOpen: false, autoOpen: false,
@ -751,7 +753,7 @@ RED.editor = (function() {
buttons: [ buttons: [
{ {
id: "node-config-dialog-ok", id: "node-config-dialog-ok",
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
var configProperty = $(this).dialog('option','node-property'); var configProperty = $(this).dialog('option','node-property');
var configId = $(this).dialog('option','node-id'); var configId = $(this).dialog('option','node-id');
@ -811,7 +813,7 @@ RED.editor = (function() {
}, },
{ {
id: "node-config-dialog-cancel", id: "node-config-dialog-cancel",
text: "Cancel", // RED._("dialog.cancel"), text: RED._("dialog.cancel"),
click: function() { click: function() {
var configType = $(this).dialog('option','node-type'); var configType = $(this).dialog('option','node-type');
var configId = $(this).dialog('option','node-id'); var configId = $(this).dialog('option','node-id');
@ -854,7 +856,9 @@ RED.editor = (function() {
RED.sidebar.config.refresh(); RED.sidebar.config.refresh();
} }
}); });
}
function createSubflowDialog(){
$( "#subflow-dialog" ).dialog({ $( "#subflow-dialog" ).dialog({
modal: true, modal: true,
autoOpen: false, autoOpen: false,
@ -865,7 +869,7 @@ RED.editor = (function() {
buttons: [ buttons: [
{ {
id: "subflow-dialog-ok", id: "subflow-dialog-ok",
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
if (editing_node) { if (editing_node) {
var i; var i;
@ -912,7 +916,7 @@ RED.editor = (function() {
}, },
{ {
id: "subflow-dialog-cancel", id: "subflow-dialog-cancel",
text: "Cancel", // RED._("dialog.cancel") text: RED._("dialog.cancel"),
click: function() { click: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
editing_node = null; editing_node = null;
@ -937,6 +941,7 @@ RED.editor = (function() {
} }
}); });
$("#subflow-dialog form" ).submit(function(e) { e.preventDefault();}); $("#subflow-dialog form" ).submit(function(e) { e.preventDefault();});
}
function showEditSubflowDialog(subflow) { function showEditSubflowDialog(subflow) {
@ -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,7 +78,9 @@ RED.workspaces = (function() {
$( "#node-dialog-rename-workspace" ).dialog("open"); $( "#node-dialog-rename-workspace" ).dialog("open");
} }
var workspace_tabs = RED.tabs.create({ var workspace_tabs;
function createWorkspaceTabs(){
workspace_tabs = RED.tabs.create({
id: "workspace-tabs", id: "workspace-tabs",
onchange: function(tab) { onchange: function(tab) {
if (tab.type == "subflow") { if (tab.type == "subflow") {
@ -117,16 +119,17 @@ RED.workspaces = (function() {
} }
}); });
$("#node-dialog-rename-workspace form" ).submit(function(e) { e.preventDefault();}); $("#node-dialog-rename-workspace form" ).submit(function(e) { e.preventDefault();});
$( "#node-dialog-rename-workspace" ).dialog({ $( "#node-dialog-rename-workspace" ).dialog({
modal: true, modal: true,
autoOpen: false, autoOpen: false,
width: 500, width: 500,
title: "Rename sheet", // RED._("dialog.renameSheet"), title: RED._("dialog.renameSheet"),
buttons: [ buttons: [
{ {
class: 'leftButton', class: 'leftButton',
text: "Delete", // RED._("dialog.delete"), text: RED._("dialog.delete"),
click: function() { click: function() {
var workspace = $(this).dialog('option','workspace'); var workspace = $(this).dialog('option','workspace');
$( this ).dialog( "close" ); $( this ).dialog( "close" );
@ -134,7 +137,7 @@ RED.workspaces = (function() {
} }
}, },
{ {
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
var workspace = $(this).dialog('option','workspace'); var workspace = $(this).dialog('option','workspace');
var label = $( "#node-input-workspace-name" ).val(); var label = $( "#node-input-workspace-name" ).val();
@ -148,7 +151,7 @@ RED.workspaces = (function() {
} }
}, },
{ {
text: "Cancel", // RED._("dialog.cancel"), text: RED._("dialog.cancel"),
click: function() { click: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
@ -165,10 +168,10 @@ RED.workspaces = (function() {
modal: true, modal: true,
autoOpen: false, autoOpen: false,
width: 500, width: 500,
title: "Confirm delete", // RED._("dialog.confirmDelete"), title: RED._("dialog.confirmDelete"),
buttons: [ buttons: [
{ {
text: "Ok", // RED._("dialog.ok"), text: RED._("dialog.ok"),
click: function() { click: function() {
var workspace = $(this).dialog('option','workspace'); var workspace = $(this).dialog('option','workspace');
deleteWorkspace(workspace,true); deleteWorkspace(workspace,true);
@ -176,7 +179,7 @@ RED.workspaces = (function() {
} }
}, },
{ {
text: "Cancel", // RED._("dialog.cancel"), text: RED._("dialog.cancel"),
click: function() { click: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
@ -190,8 +193,10 @@ RED.workspaces = (function() {
} }
}); });
}
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);