From 7544241316621980e0b3439213314e558d54af7f Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 4 Oct 2021 10:31:46 +0100 Subject: [PATCH] Allow RED.notify.update to modify any notification setting Fixes #3162 --- .../editor-client/src/js/ui/notifications.js | 77 +++++++++++++++---- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/notifications.js b/packages/node_modules/@node-red/editor-client/src/js/ui/notifications.js index e252570d6..057bfe1fc 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/notifications.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/notifications.js @@ -45,6 +45,22 @@ RED.notifications = (function() { var persistentNotifications = {}; + var shade = (function() { + var shadeUsers = 0; + return { + show: function() { + shadeUsers++; + $("#red-ui-full-shade").show(); + }, + hide: function() { + shadeUsers--; + if (shadeUsers === 0) { + $("#red-ui-full-shade").hide(); + } + } + } + })(); + var currentNotifications = []; var c = 0; function notify(msg,type,fixed,timeout) { @@ -54,6 +70,10 @@ RED.notifications = (function() { fixed = options.fixed; timeout = options.timeout; type = options.type; + } else { + options.type = type; + options.fixed = fixed; + options.timeout = options.timeout; } if (options.id && persistentNotifications.hasOwnProperty(options.id)) { @@ -62,7 +82,7 @@ RED.notifications = (function() { } if (options.modal) { - $("#red-ui-full-shade").show(); + shade.show(); } if (currentNotifications.length > 4) { @@ -79,6 +99,8 @@ RED.notifications = (function() { var n = document.createElement("div"); n.id="red-ui-notification-"+c; n.className = "red-ui-notification"; + n.options = options; + n.fixed = fixed; if (type) { n.className = "red-ui-notification red-ui-notification-"+type; @@ -115,7 +137,6 @@ RED.notifications = (function() { }) } - $("#red-ui-notifications").append(n); if (!RED.notifications.hide) { $(n).slideDown(300); @@ -141,8 +162,8 @@ RED.notifications = (function() { } else { nn.parentNode.removeChild(nn); } - if (options.modal) { - $("#red-ui-full-shade").hide(); + if (nn.options.modal) { + shade.hide(); } }; })(); @@ -173,7 +194,7 @@ RED.notifications = (function() { n.update = (function() { var nn = n; - return function(msg,options) { + return function(msg,newOptions) { if (typeof msg === "string") { if (!/

/i.test(msg)) { msg = "

"+msg+"

"; @@ -182,16 +203,31 @@ RED.notifications = (function() { } else { $(nn).empty().append(msg); } - var timeout; - if (typeof options === 'number') { - timeout = options; - } else if (options !== undefined) { - if (!options.fixed) { - timeout = options.timeout || 5000; + var newTimeout; + if (typeof newOptions === 'number') { + newTimeout = newOptions; + nn.options.timeout = newTimeout; + } else if (newOptions !== undefined) { + + if (!options.modal && newOptions.modal) { + nn.options.modal = true; + shade.show(); + } else if (options.modal && newOptions.modal === false) { + nn.options.modal = false; + shade.hide(); } - if (options.buttons) { + + var newType = newOptions.hasOwnProperty('type')?newOptions.type:type; + if (newType) { + n.className = "red-ui-notification red-ui-notification-"+newType; + } + + if (!newOptions.fixed) { + newTimeout = (newOptions.hasOwnProperty('timeout')?newOptions.timeout:timeout)||5000; + } + if (newOptions.buttons) { var buttonSet = $('
').appendTo(nn) - options.buttons.forEach(function(buttonDef) { + newOptions.buttons.forEach(function(buttonDef) { var b = $('