mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
[notice popup] rewrote initNoticePopup in common.js
This commit is contained in:
@@ -94,6 +94,7 @@ define([
|
|||||||
|
|
||||||
case 'private_share_dir': return siteRoot + 'share/ajax/private-share-dir/';
|
case 'private_share_dir': return siteRoot + 'share/ajax/private-share-dir/';
|
||||||
case 'private_share_file': return siteRoot + 'share/ajax/private-share-file/';
|
case 'private_share_file': return siteRoot + 'share/ajax/private-share-file/';
|
||||||
|
|
||||||
case 'get_popup_notices': return siteRoot + 'ajax/get_popup_notices/';
|
case 'get_popup_notices': return siteRoot + 'ajax/get_popup_notices/';
|
||||||
case 'set_notices_seen': return siteRoot + 'ajax/set_notices_seen/';
|
case 'set_notices_seen': return siteRoot + 'ajax/set_notices_seen/';
|
||||||
case 'get_unseen_notices_num': return siteRoot + 'ajax/unseen-notices-count/';
|
case 'get_unseen_notices_num': return siteRoot + 'ajax/unseen-notices-count/';
|
||||||
@@ -336,99 +337,116 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
initNoticePopup: function() {
|
initNoticePopup: function() {
|
||||||
var _this = this,
|
var msg_ct = $("#msg-count");
|
||||||
notice_popup = $('#notice-popup'),
|
|
||||||
loading_tip = $('#notice-popup .loading-tip'),
|
|
||||||
notice_icon = $('#notice-icon'),
|
|
||||||
notice_list = $('#notice-list'),
|
|
||||||
msg_count = $('#msg-count'),
|
|
||||||
num = $('#msg-count .num'),
|
|
||||||
orig_doc_title = document.title,
|
|
||||||
countUnseenNotices = function() {
|
|
||||||
// for login page, and pages without 'header' such as 'file view' page.
|
// for login page, and pages without 'header' such as 'file view' page.
|
||||||
if (msg_count.length == 0) {
|
if (msg_ct.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var success_callback = function(data) {
|
// original title
|
||||||
var count = data['count'];
|
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) {
|
if (count > 0) {
|
||||||
num.removeClass('hide');
|
num.removeClass('hide');
|
||||||
num.html(count);
|
|
||||||
document.title = '(' + count + ')' + orig_doc_title;
|
document.title = '(' + count + ')' + orig_doc_title;
|
||||||
} else {
|
} else {
|
||||||
num.addClass('hide');
|
num.addClass('hide');
|
||||||
document.title = orig_doc_title;
|
document.title = orig_doc_title;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
_this.ajaxGet({
|
|
||||||
'get_url': _this.getUrl({name: 'get_unseen_notices_num'}),
|
|
||||||
'after_op_success': success_callback
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
reqUnreadNum();
|
||||||
|
// request every 30s
|
||||||
|
setInterval(reqUnreadNum, 30*1000);
|
||||||
|
|
||||||
countUnseenNotices();
|
$('#notice-icon').click(function() {
|
||||||
setInterval(countUnseenNotices, 30*1000);
|
var popup = $('#notice-popup');
|
||||||
|
popup.toggleClass('hide');
|
||||||
|
|
||||||
notice_icon.on('click', function() {
|
if (!popup.hasClass('hide')) {
|
||||||
if (notice_popup.hasClass('hide')) {
|
$('.con', popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('.hd', popup).outerHeight() - 3});
|
||||||
notice_popup.removeClass('hide');
|
var loading_tip = $('.loading-tip', popup),
|
||||||
var success_callback = function(data) {
|
notice_list = $('#notice-list');
|
||||||
loading_tip.hide();
|
notice_list.addClass('hide');
|
||||||
notice_list.html(data['notice_html']).show();
|
loading_tip.show();
|
||||||
$(document).click(function(e) {
|
$('.error', popup).addClass('hide');
|
||||||
_this.closePopup(e, notice_popup, notice_icon);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.unread a', notice_list).click(function() {
|
|
||||||
var notice_id = $(this).parents('.unread').data('id'),
|
|
||||||
link_href = $(this).attr('href');
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: _this.getUrl({name: 'set_notice_seen_by_id'}) + '?notice_id=' + e(notice_id),
|
url: _this.getUrl({name: 'get_popup_notices'}),
|
||||||
dataType: 'json',
|
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),
|
||||||
|
dataType:'json',
|
||||||
|
success: function(data) {
|
||||||
location.href = link_href;
|
location.href = link_href;
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
location.href = link_href;
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.detail', notice_list).click(function() {
|
$('.detail', notice_list).click(function() {
|
||||||
location.href = $('.brief a', $(this).parent()).attr('href');
|
location.href = $('.brief a', $(this).parent()).attr('href');
|
||||||
});
|
});
|
||||||
|
},
|
||||||
};
|
error: function (xhr, textStatus, errorThrown) {
|
||||||
|
if (xhr.responseText) {
|
||||||
_this.ajaxGet({
|
var error = $.parseJSON(xhr.responseText).error;
|
||||||
'get_url': _this.getUrl({name: 'get_popup_notices'}),
|
loading_tip.hide();
|
||||||
'after_op_success': success_callback
|
if ($('.error', popup).length == 0) {
|
||||||
});
|
loading_tip.after('<p class="error alc">' + error + '</p>');
|
||||||
} else {
|
} else {
|
||||||
notice_popup.addClass('hide');
|
$('.error', popup).removeClass('hide');
|
||||||
loading_tip.show();
|
}
|
||||||
notice_list.hide();
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
$('.close', notice_popup).on('click', function() {
|
|
||||||
notice_popup.addClass('hide');
|
|
||||||
loading_tip.show();
|
|
||||||
notice_list.hide();
|
|
||||||
if ($('li', notice_list).hasClass('unread')) {
|
|
||||||
var success_callback = function(data) {
|
|
||||||
num.html(0).hide();
|
|
||||||
document.title = orig_doc_title;
|
|
||||||
};
|
|
||||||
_this.ajaxGet({
|
|
||||||
'get_url': _this.getUrl({name: 'set_notices_seen'}),
|
|
||||||
'after_op_success': success_callback
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).resize(function() {
|
$(window).resize(function() {
|
||||||
if (!notice_popup.hasClass('hide')) {
|
var popup = $('#notice-popup');
|
||||||
$('.con', notice_popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('.hd', notice_popup).outerHeight() - 3});
|
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'}),
|
||||||
|
dataType: 'json',
|
||||||
|
success: function() {
|
||||||
|
$('.num', msg_ct).html(0).addClass('hide');
|
||||||
|
document.title = orig_doc_title;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).click(function(e) {
|
||||||
|
_this.closePopup(e, $('#notice-popup'), $('#notice-icon'));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
fileSizeFormat: function(bytes, precision) {
|
fileSizeFormat: function(bytes, precision) {
|
||||||
|
Reference in New Issue
Block a user