wide/static/js/notification.js

68 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-01-01 05:06:33 +03:00
/*
* Copyright (c) 2014-2019, b3log.org & hacpai.com
2015-01-01 05:06:33 +03:00
*
2014-11-12 18:13:14 +03:00
* 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
2015-01-01 05:06:33 +03:00
*
2018-03-12 07:28:33 +03:00
* https://www.apache.org/licenses/LICENSE-2.0
2015-01-01 05:06:33 +03:00
*
2014-11-12 18:13:14 +03:00
* 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.
2015-01-01 05:06:33 +03:00
*/
2014-11-12 18:13:14 +03:00
2015-12-08 18:48:16 +03:00
/*
* @file notification.js
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Dec 8, 2015
*/
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-12-11 10:32:24 +03:00
var notificationWS = new ReconnectingWebSocket(config.channel + '/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 = '';
2014-11-20 06:30:18 +03:00
if (data.cmd && "init-notification" === data.cmd) {
2014-11-20 08:59:08 +03:00
console.log('[notification onmessage]' + e.data);
2014-11-20 06:30:18 +03:00
return;
}
2014-09-20 07:54:33 +04:00
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) {
2015-09-27 02:36:34 +03:00
console.log('[notification onerror]');
2014-09-19 13:58:29 +04:00
};
}
};