mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add notification button to title bar
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
RED.notify = (function() {
|
||||
RED.notifications = (function() {
|
||||
|
||||
/*
|
||||
// Example usage for a modal dialog with buttons
|
||||
@@ -39,9 +39,11 @@ RED.notify = (function() {
|
||||
});
|
||||
*/
|
||||
|
||||
var persistentNotifications = {};
|
||||
|
||||
var currentNotifications = [];
|
||||
var c = 0;
|
||||
return function(msg,type,fixed,timeout) {
|
||||
function notify(msg,type,fixed,timeout) {
|
||||
var options = {};
|
||||
if (type !== null && typeof type === 'object') {
|
||||
options = type;
|
||||
@@ -99,6 +101,12 @@ RED.notify = (function() {
|
||||
}
|
||||
nn.closed = true;
|
||||
currentNotifications.splice(currentNotifications.indexOf(nn),1);
|
||||
if (options.id) {
|
||||
delete persistentNotifications[options.id];
|
||||
if (Object.keys(persistentNotifications).length === 0) {
|
||||
notificationButtonWrapper.hide();
|
||||
}
|
||||
}
|
||||
$(nn).slideUp(300, function() {
|
||||
nn.parentNode.removeChild(nn);
|
||||
});
|
||||
@@ -107,6 +115,26 @@ RED.notify = (function() {
|
||||
}
|
||||
};
|
||||
})();
|
||||
n.hideNotification = (function() {
|
||||
var nn = n;
|
||||
return function() {
|
||||
if (nn.closed) {
|
||||
return
|
||||
}
|
||||
nn.hidden = true;
|
||||
$(nn).slideUp(300);
|
||||
}
|
||||
})();
|
||||
n.showNotification = (function() {
|
||||
var nn = n;
|
||||
return function() {
|
||||
if (nn.closed || !nn.hidden) {
|
||||
return
|
||||
}
|
||||
nn.hidden = false;
|
||||
$(nn).slideDown(300);
|
||||
}
|
||||
})();
|
||||
|
||||
n.update = (function() {
|
||||
var nn = n;
|
||||
@@ -137,6 +165,9 @@ RED.notify = (function() {
|
||||
} else {
|
||||
window.clearTimeout(nn.timeoutid);
|
||||
}
|
||||
if (nn.hidden) {
|
||||
nn.showNotification();
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
||||
@@ -152,7 +183,45 @@ RED.notify = (function() {
|
||||
n.timeoutid = window.setTimeout(n.close,timeout||5000);
|
||||
}
|
||||
currentNotifications.push(n);
|
||||
if (options.id) {
|
||||
persistentNotifications[options.id] = n;
|
||||
notificationButtonWrapper.show();
|
||||
}
|
||||
c+=1;
|
||||
return n;
|
||||
}
|
||||
|
||||
RED.notify = notify;
|
||||
|
||||
|
||||
function hidePersistent() {
|
||||
for(var i in persistentNotifications) {
|
||||
if (persistentNotifications.hasOwnProperty(i)) {
|
||||
persistentNotifications[i].hideNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
function showPersistent() {
|
||||
for(var i in persistentNotifications) {
|
||||
if (persistentNotifications.hasOwnProperty(i)) {
|
||||
persistentNotifications[i].showNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var notificationButtonWrapper;
|
||||
|
||||
return {
|
||||
init: function() {
|
||||
notificationButtonWrapper = $('<li>'+
|
||||
'<a id="btn-notifications" class="button" href="#">'+
|
||||
'<i class="fa fa-warning"></i>'+
|
||||
'</a>'+
|
||||
'</li>').prependTo(".header-toolbar").hide();
|
||||
$('#btn-notifications').click(function() {
|
||||
showPersistent();
|
||||
})
|
||||
},
|
||||
notify: notify
|
||||
}
|
||||
})();
|
||||
|
Reference in New Issue
Block a user