wide/static/js/notification.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-11-12 18:13:14 +03:00
/*
* Copyright (c) 2014, B3log
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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-11-06 06:58:55 +03:00
bottomGroup.tabs.setCurrent("notification");
2014-09-19 13:58:29 +04:00
$(".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 + ')');
};
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);
};
}
};