2019-02-13 20:06:14 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// update selected notiifcations
|
|
|
|
function SystemNotificationsMarkAsSeen() {
|
|
|
|
var WindowSize = $(window).height();
|
|
|
|
var NotificaitonSize = 75;
|
|
|
|
var NotificationsToUpdate = [];
|
|
|
|
|
|
|
|
_.each($('.system-notification[data-new="1"]'), function(el) {
|
|
|
|
var NotificationTopPosition = el.getBoundingClientRect().top;
|
|
|
|
if (NotificationTopPosition > 0 && NotificationTopPosition < (WindowSize - NotificaitonSize)) {
|
|
|
|
NotificationsToUpdate.push(el.dataset.systemNotificationId);
|
|
|
|
el.dataset.new = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (NotificationsToUpdate.length > 0) {
|
|
|
|
$.post('system_notifications/mark_as_seen', { notifications: JSON.stringify(NotificationsToUpdate) });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 20:07:29 +08:00
|
|
|
function bindSystemNotificationAjax() {
|
|
|
|
var SystemNotificationModal = null;
|
|
|
|
var SystemNotificationModalBody = null;
|
|
|
|
var SystemNotificationModalTitle = null;
|
|
|
|
|
|
|
|
SystemNotificationModal = $('#manage-module-system-notification-modal');
|
|
|
|
SystemNotificationModalBody = SystemNotificationModal.find('.modal-body');
|
|
|
|
SystemNotificationModalTitle = SystemNotificationModal.find('#manage-module-system-notification-modal-label');
|
|
|
|
|
|
|
|
$('.modal-system-notification')
|
|
|
|
.on('ajax:success', function(ev, data) {
|
|
|
|
var SystemNotification = $('.system-notification[data-system-notification-id=' + data.id + ']')[0];
|
|
|
|
SystemNotificationModalBody.html(data.modal_body);
|
|
|
|
SystemNotificationModalTitle.text(data.modal_title);
|
|
|
|
// Open modal
|
|
|
|
SystemNotificationModal.modal('show');
|
|
|
|
if (SystemNotification.dataset.unread === '1') {
|
|
|
|
$.post('system_notifications/' + data.id + '/mark_as_read');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-13 20:06:14 +08:00
|
|
|
function initSystemNotificationsButton() {
|
|
|
|
$('.btn-more-notifications')
|
|
|
|
.on('ajax:success', function(e, data) {
|
|
|
|
$(data.html).insertAfter($('.notifications-container .system-notification').last());
|
2019-02-15 20:07:29 +08:00
|
|
|
bindSystemNotificationAjax();
|
2019-02-13 20:06:14 +08:00
|
|
|
if (data.more_url) {
|
|
|
|
$(this).attr('href', data.more_url);
|
|
|
|
} else {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-15 20:07:29 +08:00
|
|
|
$(window).scroll(function() {
|
2019-02-13 20:06:14 +08:00
|
|
|
SystemNotificationsMarkAsSeen();
|
2019-02-15 20:07:29 +08:00
|
|
|
});
|
|
|
|
initSystemNotificationsButton();
|
|
|
|
SystemNotificationsMarkAsSeen();
|
|
|
|
bindSystemNotificationAjax();
|