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

Prevent deleting the final tab

This commit is contained in:
Nicholas O'Leary 2013-10-28 20:48:25 +00:00
parent 419b044a12
commit a8f5d6b9ee
2 changed files with 29 additions and 2 deletions

View File

@ -90,7 +90,10 @@ RED.tabs = function() {
}, },
activateTab: activateTab, activateTab: activateTab,
resize: updateTabWidths resize: updateTabWidths,
count: function() {
return ul.find("li.red-ui-tab").size();
}
} }
} }

View File

@ -106,12 +106,15 @@ RED.view = function() {
$('#btn-workspace-edit').on("click",function() { $('#btn-workspace-edit').on("click",function() {
showRenameWorkspaceDialog(activeWorkspace); showRenameWorkspaceDialog(activeWorkspace);
}); });
$('#btn-workspace-delete').on("click",function() { $('#btn-workspace-delete').on("click",function() {
deleteWorkspace(activeWorkspace); deleteWorkspace(activeWorkspace);
}); });
function deleteWorkspace(id) { function deleteWorkspace(id) {
if (workspace_tabs.count() == 1) {
return;
}
var ws = RED.nodes.workspace(id); var ws = RED.nodes.workspace(id);
$( "#node-dialog-delete-workspace" ).dialog('option','workspace',ws); $( "#node-dialog-delete-workspace" ).dialog('option','workspace',ws);
$( "#node-dialog-delete-workspace-name" ).text(ws.label); $( "#node-dialog-delete-workspace-name" ).text(ws.label);
@ -1008,6 +1011,17 @@ RED.view = function() {
function showRenameWorkspaceDialog(id) { function showRenameWorkspaceDialog(id) {
var ws = RED.nodes.workspace(id); var ws = RED.nodes.workspace(id);
$( "#node-dialog-rename-workspace" ).dialog("option","workspace",ws); $( "#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");
}
$( "#node-input-workspace-name" ).val(ws.label); $( "#node-input-workspace-name" ).val(ws.label);
$( "#node-dialog-rename-workspace" ).dialog("open"); $( "#node-dialog-rename-workspace" ).dialog("open");
} }
@ -1093,10 +1107,20 @@ RED.view = function() {
addWorkspace: function(ws) { addWorkspace: function(ws) {
workspace_tabs.addTab(ws); workspace_tabs.addTab(ws);
workspace_tabs.resize(); workspace_tabs.resize();
if (workspace_tabs.count() == 1) {
$('#btn-workspace-delete').parent().addClass("disabled");
} else {
$('#btn-workspace-delete').parent().removeClass("disabled");
}
}, },
removeWorkspace: function(ws) { removeWorkspace: function(ws) {
workspace_tabs.removeTab(ws.id); workspace_tabs.removeTab(ws.id);
$('#workspace-menu-list a[href="#'+ws.id+'"]').parent().remove(); $('#workspace-menu-list a[href="#'+ws.id+'"]').parent().remove();
if (workspace_tabs.count() == 1) {
$('#btn-workspace-delete').parent().addClass("disabled");
} else {
$('#btn-workspace-delete').parent().removeClass("disabled");
}
}, },
getWorkspace: function() { getWorkspace: function() {
return activeWorkspace; return activeWorkspace;