wide/static/js/notification.js

61 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-01-01 05:06:33 +03:00
/*
2015-01-18 08:59:10 +03:00
* Copyright (c) 2014-2015, b3log.org
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
*
2014-11-12 18:13:14 +03:00
* http://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
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
};
}
};