Skip to content

Commit f649c24

Browse files
fix to support locking flow tab (#799)
1 parent b4b9a83 commit f649c24

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

nodes/ui_base.html

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,40 @@
334334
var attemptedVendorLoad = false;
335335
var ensureDashboardNode;
336336

337+
var isTabLockSupported = ((typeof RED.workspaces.isLocked) === "function"); // check for new Node-RED version
338+
339+
function notifyLocked() {
340+
RED.notify("Can't change tab with nodes in locked tab");
341+
}
342+
343+
// check if specified tab is locked
344+
function isLockedTab(id) {
345+
if (!isTabLockSupported) {
346+
return false;
347+
}
348+
return (RED.workspaces.isLocked(id));
349+
}
350+
351+
// check if some node in tab placed on locked tab
352+
function isLocked(id) {
353+
if (!isTabLockSupported) {
354+
return false;
355+
}
356+
const tab = getTabDataFromNodes(id);
357+
const groups = tab.groups;
358+
for (let i = 0; i < groups.length; i++) {
359+
const group = groups[i];
360+
const widgets = group.widgets;
361+
for (let j = 0; j < widgets.length; j++) {
362+
const widget = RED.nodes.node(widgets[j].id);
363+
if (RED.workspaces.isLocked(widget.z)) {
364+
return true;
365+
}
366+
}
367+
}
368+
return false;
369+
}
370+
337371
var loadTinyColor = function(path) {
338372
$.ajax({ url: path,
339373
success: function (data) {
@@ -1908,6 +1942,12 @@
19081942
}
19091943
var editButton = $('<a href="#" class="nr-db-sb-tab-edit-button editor-button editor-button-small nr-db-sb-list-header-button"><i class="fa fa-pencil"></i> '+c_("layout.edit")+'</a>').appendTo(buttonGroup);
19101944
editButton.on('click',function(evt) {
1945+
if (isLocked(item.node.id)) {
1946+
evt.stopPropagation();
1947+
evt.preventDefault();
1948+
notifyLocked();
1949+
return;
1950+
}
19111951
RED.editor.editConfig("", item.type, item.node.id);
19121952
evt.stopPropagation();
19131953
evt.preventDefault();
@@ -1917,6 +1957,12 @@
19171957
if (item.type === 'ui_tab') {
19181958
var layoutButton = $('<a href="#" class="nr-db-sb-tab-edit-layout-button editor-button editor-button-small nr-db-sb-list-header-button"><i class="fa fa-pencil"></i> '+c_("layout.layout")+'</a>').appendTo(buttonGroup);
19191959
layoutButton.on('click',function(evt) {
1960+
if (isLocked(item.node.id)) {
1961+
evt.stopPropagation();
1962+
evt.preventDefault();
1963+
notifyLocked();
1964+
return;
1965+
}
19201966
var editTabName = item.node.name ? item.node.name : item.node.id;
19211967
var trayOptions = {
19221968
title: c_("layout.layout-editor") + " : " + editTabName,
@@ -2139,7 +2185,7 @@
21392185
},
21402186
close: function() {},
21412187
show: function() {}
2142-
}
2188+
};
21432189
RED.tray.show(trayOptions);
21442190
evt.stopPropagation();
21452191
evt.preventDefault();
@@ -2210,6 +2256,12 @@
22102256
var buttonGroup = $('<div>',{class:"nr-db-sb-list-header-button-group",id:groupNode.id}).appendTo(titleRow);
22112257
var spacerButton = $('<a href="#" class="editor-button editor-button-small nr-db-sb-list-header-button"><i class="fa fa-plus"></i> '+c_("layout.spacer")+'</a>').appendTo(buttonGroup);
22122258
spacerButton.on('click',function(evt) {
2259+
if (isLocked(item.node.id)) {
2260+
evt.stopPropagation();
2261+
evt.preventDefault();
2262+
notifyLocked();
2263+
return;
2264+
}
22132265
var spaceNode = {
22142266
_def: RED.nodes.getType("ui_spacer"),
22152267
type: "ui_spacer",
@@ -2282,12 +2334,23 @@
22822334
RED.view.redraw();
22832335
});
22842336
editButton.on('click',function(evt) {
2337+
if (isLockedTab(widgetNode.z)) {
2338+
evt.stopPropagation();
2339+
evt.preventDefault();
2340+
notifyLocked();
2341+
return;
2342+
}
22852343
RED.editor.edit(widgetNode);
22862344
evt.stopPropagation();
22872345
evt.preventDefault();
22882346
});
22892347
},
22902348
sortItems: function(items) {
2349+
if (isLocked(item.node.id)) {
2350+
$(ol).editableList("cancel");
2351+
notifyLocked();
2352+
return;
2353+
}
22912354
var historyEvents = [];
22922355
items.each(function(i,el) {
22932356
var node = el.data('data');
@@ -2336,6 +2399,12 @@
23362399
}
23372400
titleRow.click(titleToggle(groupNode.id,content,chevron));
23382401
editButton.on('click',function(evt) {
2402+
if (isLocked(item.node.id)) {
2403+
evt.stopPropagation();
2404+
evt.preventDefault();
2405+
notifyLocked();
2406+
return;
2407+
}
23392408
RED.editor.editConfig("", groupNode.type, groupNode.id);
23402409
evt.stopPropagation();
23412410
evt.preventDefault();
@@ -2391,6 +2460,12 @@
23912460
tabLists[item.node.id] = ol;
23922461

23932462
addGroupButton.click(function(evt) {
2463+
if (isLocked(item.node.id)) {
2464+
evt.stopPropagation();
2465+
evt.preventDefault();
2466+
notifyLocked();
2467+
return;
2468+
}
23942469
ol.editableList('addItem',{});
23952470
evt.stopPropagation();
23962471
evt.preventDefault();

0 commit comments

Comments
 (0)