2019-02-13 20:06:14 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// update selected notiifcations
|
2019-02-21 23:15:13 +08:00
|
|
|
function SystemNotificationsMarkAsSeen() {
|
|
|
|
if ($('.system-notification[data-new="1"]').length > 0) {
|
|
|
|
$.post('/system_notifications/mark_as_seen');
|
2019-02-13 20:06:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-02-21 23:15:13 +08:00
|
|
|
var SystemNotification = $('.system-notification[data-system-notification-id=' + data.id + ']');
|
2019-02-15 20:07:29 +08:00
|
|
|
SystemNotificationModalBody.html(data.modal_body);
|
|
|
|
SystemNotificationModalTitle.text(data.modal_title);
|
2019-02-21 23:15:13 +08:00
|
|
|
$('.dropdown.system-notifications').removeClass('open');
|
2019-02-15 20:07:29 +08:00
|
|
|
// Open modal
|
|
|
|
SystemNotificationModal.modal('show');
|
2019-02-21 23:15:13 +08:00
|
|
|
if (SystemNotification[0].dataset.unread === '1') {
|
|
|
|
$.each(SystemNotification, (index, e) => { e.dataset.unread = '0'; });
|
|
|
|
SystemNotification.find('.status-icon').addClass('seen');
|
2019-02-20 20:15:16 +08:00
|
|
|
$.post('/system_notifications/' + data.id + '/mark_as_read');
|
2019-02-15 20:07:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-13 20:06:14 +08:00
|
|
|
function initSystemNotificationsButton() {
|
2019-04-12 17:58:47 +08:00
|
|
|
$('.btn-more-system-notifications')
|
2019-02-13 20:06:14 +08:00
|
|
|
.on('ajax:success', function(e, data) {
|
2019-02-21 23:15:13 +08:00
|
|
|
$(data.html).insertAfter($('.system-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
|
|
|
initSystemNotificationsButton();
|
|
|
|
SystemNotificationsMarkAsSeen();
|
|
|
|
bindSystemNotificationAjax();
|