|
334 | 334 | var attemptedVendorLoad = false; |
335 | 335 | var ensureDashboardNode; |
336 | 336 |
|
| 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 | + |
337 | 371 | var loadTinyColor = function(path) { |
338 | 372 | $.ajax({ url: path, |
339 | 373 | success: function (data) { |
|
1908 | 1942 | } |
1909 | 1943 | 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); |
1910 | 1944 | editButton.on('click',function(evt) { |
| 1945 | + if (isLocked(item.node.id)) { |
| 1946 | + evt.stopPropagation(); |
| 1947 | + evt.preventDefault(); |
| 1948 | + notifyLocked(); |
| 1949 | + return; |
| 1950 | + } |
1911 | 1951 | RED.editor.editConfig("", item.type, item.node.id); |
1912 | 1952 | evt.stopPropagation(); |
1913 | 1953 | evt.preventDefault(); |
|
1917 | 1957 | if (item.type === 'ui_tab') { |
1918 | 1958 | 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); |
1919 | 1959 | layoutButton.on('click',function(evt) { |
| 1960 | + if (isLocked(item.node.id)) { |
| 1961 | + evt.stopPropagation(); |
| 1962 | + evt.preventDefault(); |
| 1963 | + notifyLocked(); |
| 1964 | + return; |
| 1965 | + } |
1920 | 1966 | var editTabName = item.node.name ? item.node.name : item.node.id; |
1921 | 1967 | var trayOptions = { |
1922 | 1968 | title: c_("layout.layout-editor") + " : " + editTabName, |
|
2139 | 2185 | }, |
2140 | 2186 | close: function() {}, |
2141 | 2187 | show: function() {} |
2142 | | - } |
| 2188 | + }; |
2143 | 2189 | RED.tray.show(trayOptions); |
2144 | 2190 | evt.stopPropagation(); |
2145 | 2191 | evt.preventDefault(); |
|
2210 | 2256 | var buttonGroup = $('<div>',{class:"nr-db-sb-list-header-button-group",id:groupNode.id}).appendTo(titleRow); |
2211 | 2257 | 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); |
2212 | 2258 | spacerButton.on('click',function(evt) { |
| 2259 | + if (isLocked(item.node.id)) { |
| 2260 | + evt.stopPropagation(); |
| 2261 | + evt.preventDefault(); |
| 2262 | + notifyLocked(); |
| 2263 | + return; |
| 2264 | + } |
2213 | 2265 | var spaceNode = { |
2214 | 2266 | _def: RED.nodes.getType("ui_spacer"), |
2215 | 2267 | type: "ui_spacer", |
|
2282 | 2334 | RED.view.redraw(); |
2283 | 2335 | }); |
2284 | 2336 | editButton.on('click',function(evt) { |
| 2337 | + if (isLockedTab(widgetNode.z)) { |
| 2338 | + evt.stopPropagation(); |
| 2339 | + evt.preventDefault(); |
| 2340 | + notifyLocked(); |
| 2341 | + return; |
| 2342 | + } |
2285 | 2343 | RED.editor.edit(widgetNode); |
2286 | 2344 | evt.stopPropagation(); |
2287 | 2345 | evt.preventDefault(); |
2288 | 2346 | }); |
2289 | 2347 | }, |
2290 | 2348 | sortItems: function(items) { |
| 2349 | + if (isLocked(item.node.id)) { |
| 2350 | + $(ol).editableList("cancel"); |
| 2351 | + notifyLocked(); |
| 2352 | + return; |
| 2353 | + } |
2291 | 2354 | var historyEvents = []; |
2292 | 2355 | items.each(function(i,el) { |
2293 | 2356 | var node = el.data('data'); |
|
2336 | 2399 | } |
2337 | 2400 | titleRow.click(titleToggle(groupNode.id,content,chevron)); |
2338 | 2401 | editButton.on('click',function(evt) { |
| 2402 | + if (isLocked(item.node.id)) { |
| 2403 | + evt.stopPropagation(); |
| 2404 | + evt.preventDefault(); |
| 2405 | + notifyLocked(); |
| 2406 | + return; |
| 2407 | + } |
2339 | 2408 | RED.editor.editConfig("", groupNode.type, groupNode.id); |
2340 | 2409 | evt.stopPropagation(); |
2341 | 2410 | evt.preventDefault(); |
|
2391 | 2460 | tabLists[item.node.id] = ol; |
2392 | 2461 |
|
2393 | 2462 | addGroupButton.click(function(evt) { |
| 2463 | + if (isLocked(item.node.id)) { |
| 2464 | + evt.stopPropagation(); |
| 2465 | + evt.preventDefault(); |
| 2466 | + notifyLocked(); |
| 2467 | + return; |
| 2468 | + } |
2394 | 2469 | ol.editableList('addItem',{}); |
2395 | 2470 | evt.stopPropagation(); |
2396 | 2471 | evt.preventDefault(); |
|
0 commit comments