From 0afe98b399da61eb383fc042586d0e91ba454d66 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 31 May 2016 23:20:25 +0100 Subject: [PATCH] Move rename flow dialog to editor tray --- editor/js/nodes.js | 6 + editor/js/ui/tray.js | 8 +- editor/js/ui/workspaces.js | 189 +++++++++++++----------------- editor/sass/editor.scss | 2 +- editor/templates/index.mst | 15 --- red/api/locales/en-US/editor.json | 2 +- 6 files changed, 97 insertions(+), 125 deletions(-) diff --git a/editor/js/nodes.js b/editor/js/nodes.js index fe9314c6c..81fec9de1 100644 --- a/editor/js/nodes.js +++ b/editor/js/nodes.js @@ -272,6 +272,12 @@ RED.nodes = (function() { function addWorkspace(ws) { workspaces[ws.id] = ws; + ws._def = { + defaults: { + label: {value:""} + } + }; + workspacesOrder.push(ws.id); } function getWorkspace(id) { diff --git a/editor/js/ui/tray.js b/editor/js/ui/tray.js index 1f304dec8..e68e4273f 100644 --- a/editor/js/ui/tray.js +++ b/editor/js/ui/tray.js @@ -47,7 +47,13 @@ RED.tray = (function() { b.html(button.text); } if (button.click) { - b.click(button.click); + b.click((function(action) { + return function(evt) { + if (!$(this).hasClass('disabled')) { + action(evt); + } + }; + })(button.click)); } if (button.class) { b.addClass(button.class); diff --git a/editor/js/ui/workspaces.js b/editor/js/ui/workspaces.js index de349847d..cdf66f939 100644 --- a/editor/js/ui/workspaces.js +++ b/editor/js/ui/workspaces.js @@ -38,47 +38,91 @@ RED.workspaces = (function() { RED.nodes.dirty(true); } } - function deleteWorkspace(ws,force) { + function deleteWorkspace(ws) { if (workspace_tabs.count() == 1) { return; } - var nodes = []; - if (!force) { - nodes = RED.nodes.filterNodes({z:ws.id}); - } - if (force || nodes.length === 0) { - removeWorkspace(ws); - var historyEvent = RED.nodes.removeWorkspace(ws.id); - historyEvent.t = 'delete'; - historyEvent.dirty = RED.nodes.dirty(); - historyEvent.workspaces = [ws]; - RED.history.push(historyEvent); - RED.nodes.dirty(true); - RED.sidebar.config.refresh(); - } else { - $( "#node-dialog-delete-workspace" ).dialog('option','workspace',ws); - $( "#node-dialog-delete-workspace-content" ).text(RED._("workspace.delete",{label:ws.label})); - $( "#node-dialog-delete-workspace" ).dialog('open'); - } + removeWorkspace(ws); + var historyEvent = RED.nodes.removeWorkspace(ws.id); + historyEvent.t = 'delete'; + historyEvent.dirty = RED.nodes.dirty(); + historyEvent.workspaces = [ws]; + RED.history.push(historyEvent); + RED.nodes.dirty(true); + RED.sidebar.config.refresh(); } + function showRenameWorkspaceDialog(id) { - var ws = RED.nodes.workspace(id); - $( "#node-dialog-rename-workspace" ).dialog("option","workspace",ws); - - if (workspace_tabs.count() == 1) { - $( "#node-dialog-rename-workspace").next().find(".leftButton") - .prop('disabled',true) - .addClass("ui-state-disabled"); - } else { - $( "#node-dialog-rename-workspace").next().find(".leftButton") - .prop('disabled',false) - .removeClass("ui-state-disabled"); + var workspace = RED.nodes.workspace(id); + RED.view.state(RED.state.EDITING); + var trayOptions = { + title: RED._("workspace.editFlow",{name:workspace.label}), + buttons: [ + { + id: "node-dialog-delete", + class: 'leftButton'+((workspace_tabs.count() == 1)?" disabled":""), + text: RED._("common.label.delete"), //'', + click: function() { + deleteWorkspace(workspace); + RED.tray.close(); + } + }, + { + id: "node-dialog-cancel", + text: RED._("common.label.cancel"), + click: function() { + RED.tray.close(); + } + }, + { + id: "node-dialog-ok", + class: "primary", + text: RED._("common.label.done"), + click: function() { + var label = $( "#node-input-name" ).val(); + if (workspace.label != label) { + var changes = { + label:workspace.label + } + var historyEvent = { + t: "edit", + changes:changes, + node: workspace, + dirty: RED.nodes.dirty() + } + console.log(workspace); + RED.history.push(historyEvent); + workspace_tabs.renameTab(workspace.id,label); + RED.nodes.dirty(true); + RED.sidebar.config.refresh(); + $("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(label); + } + RED.tray.close(); + } + } + ], + open: function(tray) { + var trayBody = tray.find('.editor-tray-body'); + var dialogForm = $('
').appendTo(trayBody); + $('
'+ + ''+ + ''+ + '
').appendTo(dialogForm); + $('').prependTo(dialogForm); + dialogForm.submit(function(e) { e.preventDefault();}); + $("#node-input-name").val(workspace.label); + dialogForm.i18n(); + }, + close: function() { + if (RED.view.state() != RED.state.IMPORT_DRAGGING) { + RED.view.state(RED.state.DEFAULT); + } + } } - - $( "#node-input-workspace-name" ).val(ws.label); - $( "#node-dialog-rename-workspace" ).dialog("open"); + RED.tray.show(trayOptions); } + var workspace_tabs; function createWorkspaceTabs(){ workspace_tabs = RED.tabs.create({ @@ -120,80 +164,6 @@ RED.workspaces = (function() { }, minimumActiveTabWidth: 150 }); - - - $("#node-dialog-rename-workspace form" ).submit(function(e) { e.preventDefault();}); - $( "#node-dialog-rename-workspace" ).dialog({ - modal: true, - autoOpen: false, - width: 500, - title: RED._("workspace.renameSheet"), - buttons: [ - { - class: 'leftButton', - text: RED._("common.label.delete"), - click: function() { - var workspace = $(this).dialog('option','workspace'); - $( this ).dialog( "close" ); - deleteWorkspace(workspace); - } - }, - { - text: RED._("common.label.cancel"), - click: function() { - $( this ).dialog( "close" ); - } - }, - { - text: RED._("common.label.done"), - class: "primary", - 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); - RED.sidebar.config.refresh(); - $("#menu-item-workspace-menu-"+workspace.id.replace(".","-")).text(label); - } - $( this ).dialog( "close" ); - } - } - - ], - open: function(e) { - }, - close: function(e) { - } - }); - $( "#node-dialog-delete-workspace" ).dialog({ - modal: true, - autoOpen: false, - width: 500, - title: RED._("workspace.confirmDelete"), - buttons: [ - { - text: RED._("common.label.cancel"), - click: function() { - $( this ).dialog( "close" ); - } - }, - { - text: RED._("common.label.ok"), - class: "primary", - click: function() { - var workspace = $(this).dialog('option','workspace'); - deleteWorkspace(workspace,true); - $( this ).dialog( "close" ); - } - } - ], - open: function(e) { - }, - close: function(e) { - } - - }); } function init() { @@ -254,6 +224,11 @@ RED.workspaces = (function() { workspace_tabs.activateTab(id); }, refresh: function() { + RED.nodes.eachWorkspace(function(ws) { + workspace_tabs.renameTab(ws.id,ws.label); + $("#menu-item-workspace-menu-"+ws.id.replace(".","-")).text(ws.label); + + }) RED.nodes.eachSubflow(function(sf) { if (workspace_tabs.contains(sf.id)) { workspace_tabs.renameTab(sf.id,sf.name); diff --git a/editor/sass/editor.scss b/editor/sass/editor.scss index 4b245f2aa..c464769ee 100644 --- a/editor/sass/editor.scss +++ b/editor/sass/editor.scss @@ -86,7 +86,7 @@ } &:not(.primary) { background: none; - &:hover { + &:not(.disabled):hover { color: $editor-button-color-primary; } } diff --git a/editor/templates/index.mst b/editor/templates/index.mst index 549110160..b643a0199 100644 --- a/editor/templates/index.mst +++ b/editor/templates/index.mst @@ -129,21 +129,6 @@ -
-
-
- - -
-
-
-
-
-
-
-
-
-