1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

Rewrite notifications with popover class

This commit is contained in:
Daniel Pan
2016-04-18 17:46:06 +08:00
parent 3909d14983
commit 6b0f05bd34
8 changed files with 185 additions and 304 deletions

View File

@@ -536,127 +536,6 @@ define([
});
},
initNoticePopup: function() {
var _this = this;
var msg_ct = $("#msg-count");
// for login page, and pages without 'header' such as 'file view' page.
if (msg_ct.length == 0) {
return false;
}
// original title
var orig_doc_title = document.title;
msg_ct.data('orig_doc_title', orig_doc_title); // for 'mark all read' in 'notice list' page
var reqUnreadNum = function() {
$.ajax({
url: _this.getUrl({name: 'get_unseen_notices_num'}),
dataType: 'json',
cache: false,
success: function(data) {
var count = data['count'],
num = $('.num', msg_ct);
num.html(count);
if (count > 0) {
num.removeClass('hide');
document.title = '(' + count + ')' + orig_doc_title;
} else {
num.addClass('hide');
document.title = orig_doc_title;
}
}
});
};
reqUnreadNum();
// request every 30s
setInterval(reqUnreadNum, 30*1000);
$('#notice-icon').click(function() {
var popup = $('#notice-popup');
popup.toggleClass('hide');
if (!popup.hasClass('hide')) {
$('.con', popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('.hd', popup).outerHeight() - 3});
var loading_tip = $('.loading-tip', popup),
notice_list = $('#notice-list');
notice_list.addClass('hide');
loading_tip.show();
$('.error', popup).addClass('hide');
$.ajax({
url: _this.getUrl({name: 'get_popup_notices'}),
dataType: 'json',
success: function(data) {
loading_tip.hide();
notice_list.html(data['notice_html']).removeClass('hide');
// set a notice to be read when <a> in it is clicked
$('.unread a', notice_list).click(function() {
var notice_id = $(this).parents('.unread').data('id');
var link_href = $(this).attr('href');
$.ajax({
url: _this.getUrl({name: 'set_notice_seen_by_id'}) + '?notice_id=' + encodeURIComponent(notice_id),
type: 'POST',
dataType: 'json',
beforeSend: _this.prepareCSRFToken,
success: function(data) {
location.href = link_href;
},
error: function() {
location.href = link_href;
}
});
return false;
});
$('.detail', notice_list).click(function() {
location.href = $('.brief a', $(this).parent()).attr('href');
});
},
error: function (xhr, textStatus, errorThrown) {
if (xhr.responseText) {
var error = $.parseJSON(xhr.responseText).error;
loading_tip.hide();
if ($('.error', popup).length == 0) {
loading_tip.after('<p class="error alc">' + error + '</p>');
} else {
$('.error', popup).removeClass('hide');
}
}
}
});
}
return false;
});
$(window).resize(function() {
var popup = $('#notice-popup');
if (!popup.hasClass('hide')) {
$('.con', popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('.hd', popup).outerHeight() - 3});
}
});
$('#notice-popup .close').click(function() {
$('#notice-popup').addClass('hide');
if ($('#notice-list .unread').length > 0) {
// set all unread notice to be read
$.ajax({
url: _this.getUrl({name: 'set_notices_seen'}),
type: 'POST',
dataType: 'json',
beforeSend: _this.prepareCSRFToken,
success: function() {
$('.num', msg_ct).html(0).addClass('hide');
document.title = orig_doc_title;
}
});
}
return false;
});
$(document).click(function(e) {
_this.closePopup(e, $('#notice-popup'), $('#notice-icon'));
});
},
closeTopNoticeBar: function () {
if (!app.pageOptions.cur_note) {
return false;