wide/static/js/notification.js

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-09-15 14:03:52 +04:00
var notification = {
2014-09-20 07:54:33 +04:00
init: function () {
$(".notification-count").click(function () {
2014-09-19 13:58:29 +04:00
wide.bottomWindowTab.setCurrent("notification");
$(".bottom-window-group .notification").focus();
$(this).hide();
});
this._initWS();
},
2014-09-20 07:54:33 +04:00
_initWS: function () {
2014-10-23 09:07:48 +04:00
var notificationWS = new ReconnectingWebSocket(config.channel.shell + '/notification/ws?sid=' + config.wideSessionId);
2014-09-15 14:03:52 +04:00
2014-09-20 07:54:33 +04:00
notificationWS.onopen = function () {
2014-09-19 13:58:29 +04:00
console.log('[notification onopen] connected');
};
2014-09-20 07:54:33 +04:00
notificationWS.onmessage = function (e) {
var data = JSON.parse(e.data),
$notification = $('.bottom-window-group .notification > table'),
notificationHTML = '';
notificationHTML += '<tr><td class="severity">' + data.severity
+ '</td><td class="message">' + data.message
+ '</td><td class="type">' + data.type + '</td></tr>';
$notification.append(notificationHTML);
$(".notification-count").show();
2014-09-19 13:58:29 +04:00
};
2014-09-20 07:54:33 +04:00
notificationWS.onclose = function (e) {
2014-09-19 13:58:29 +04:00
console.log('[notification onclose] disconnected (' + e.code + ')');
delete notificationWS;
};
2014-09-20 07:54:33 +04:00
notificationWS.onerror = function (e) {
2014-09-19 13:58:29 +04:00
console.log('[notification onerror] ' + e);
};
}
};