2019-04-12 15:17:14 +08:00
|
|
|
/* globals animateSpinner PerfectScrollbar */
|
2018-08-02 17:25:14 +08:00
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
(function() {
|
2016-09-29 20:49:58 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
/* Init about modal */
|
|
|
|
$("[data-trigger='about-modal']").on('click', function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
$('[data-role=about-modal]').modal('show');
|
|
|
|
});
|
|
|
|
|
2016-09-29 20:49:58 +08:00
|
|
|
/* Loading overlay for search */
|
2018-07-19 23:56:42 +08:00
|
|
|
$('#search-bar').submit(function() {
|
|
|
|
if ($('#update-canvas')) {
|
2016-09-29 20:49:58 +08:00
|
|
|
$(document.body).spin(true);
|
2018-07-19 23:56:42 +08:00
|
|
|
setTimeout(function() {
|
|
|
|
$('.spinner').remove();
|
2016-09-29 20:49:58 +08:00
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
animateSpinner();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function loadDropdownNotifications() {
|
|
|
|
var button = $('#notifications-dropdown');
|
2018-07-19 23:56:42 +08:00
|
|
|
var noRecentText = $('.dropdown-notifications .notifications-no-recent');
|
2016-09-29 20:49:58 +08:00
|
|
|
button
|
|
|
|
.on('click', function() {
|
2016-10-05 22:48:40 +08:00
|
|
|
noRecentText.hide();
|
2016-09-29 20:49:58 +08:00
|
|
|
$.ajax({
|
|
|
|
url: button.attr('data-href'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
2016-10-03 14:20:23 +08:00
|
|
|
beforeSend: animateSpinner($('.notifications-dropdown-header'), true),
|
2016-09-29 20:49:58 +08:00
|
|
|
success: function(data) {
|
2018-07-19 23:56:42 +08:00
|
|
|
var ul = $('.dropdown-menu.dropdown-notifications');
|
|
|
|
|
2016-09-29 20:49:58 +08:00
|
|
|
$('.notifications-dropdown-header')
|
|
|
|
.nextAll('li.notification')
|
|
|
|
.remove();
|
|
|
|
$('.notifications-dropdown-header')
|
|
|
|
.after(data.html);
|
2016-10-03 14:27:13 +08:00
|
|
|
animateSpinner($('.notifications-dropdown-header'), false);
|
2016-10-05 22:48:40 +08:00
|
|
|
if (ul.children('.notification').length === 0) {
|
|
|
|
noRecentText.show();
|
|
|
|
}
|
2016-09-29 20:49:58 +08:00
|
|
|
}
|
|
|
|
});
|
2016-10-04 02:31:00 +08:00
|
|
|
$('#count-notifications').hide();
|
2016-10-05 17:50:57 +08:00
|
|
|
toggleNotificationBellPosition();
|
2016-09-29 20:49:58 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:08:59 +08:00
|
|
|
function loadUnseenNotificationsNumber(element = 'notifications', icon = '.fa-bell') {
|
|
|
|
var notificationCount = $('#count-' + element);
|
2016-09-29 20:49:58 +08:00
|
|
|
$.ajax({
|
|
|
|
url: notificationCount.attr('data-href'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
notificationCount.html('');
|
2018-07-19 23:56:42 +08:00
|
|
|
if (data.notificationNmber > 0) {
|
2016-10-03 14:20:23 +08:00
|
|
|
notificationCount.html(data.notificationNmber);
|
|
|
|
notificationCount.show();
|
2019-02-19 18:08:59 +08:00
|
|
|
toggleNotificationBellPosition(element, icon);
|
2016-10-03 14:20:23 +08:00
|
|
|
} else {
|
2016-10-03 14:27:13 +08:00
|
|
|
notificationCount.hide();
|
2016-10-03 14:20:23 +08:00
|
|
|
}
|
2016-09-29 20:49:58 +08:00
|
|
|
}
|
|
|
|
});
|
2016-07-21 19:11:15 +08:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:08:59 +08:00
|
|
|
function toggleNotificationBellPosition(element = 'notifications', icon = '.fa-bell') {
|
|
|
|
var notificationCount = $('#count-' + element);
|
|
|
|
var button = $('#' + element + '-dropdown');
|
2016-10-05 17:50:57 +08:00
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
if (notificationCount.is(':hidden')) {
|
2016-10-05 17:50:57 +08:00
|
|
|
button
|
2019-02-19 18:08:59 +08:00
|
|
|
.find(icon)
|
2016-10-05 17:50:57 +08:00
|
|
|
.css('position', 'relative');
|
|
|
|
} else {
|
|
|
|
button
|
2019-02-19 18:08:59 +08:00
|
|
|
.find(icon)
|
2016-10-05 17:50:57 +08:00
|
|
|
.css('position', 'absolute');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 17:40:14 +08:00
|
|
|
function initGlobalSwitchForm() {
|
|
|
|
var teamSwitch = $('#team-switch');
|
2019-04-12 15:17:14 +08:00
|
|
|
var dropDownMenu = teamSwitch.find('.dropdown-menu');
|
|
|
|
var dropDownHeight;
|
2019-04-17 15:50:54 +08:00
|
|
|
var teamContainter = teamSwitch.find('.team-container')[0];
|
|
|
|
var ps;
|
|
|
|
|
|
|
|
if (typeof teamContainter === 'undefined') return;
|
|
|
|
|
|
|
|
ps = new PerfectScrollbar(teamContainter, { scrollYMarginOffset: 5 });
|
2019-04-12 15:17:14 +08:00
|
|
|
teamSwitch.click(() => {
|
|
|
|
dropDownHeight = dropDownMenu.height();
|
|
|
|
if (teamSwitch.find('.new-team').length === 0) {
|
|
|
|
teamSwitch.find('.edit_user').css('height', '100%');
|
|
|
|
}
|
|
|
|
dropDownMenu.css('height', (dropDownHeight + 'px'));
|
|
|
|
setTimeout(() => {
|
|
|
|
ps.update();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
teamSwitch.find('.ps__rail-y').click((e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2016-10-11 17:40:14 +08:00
|
|
|
teamSwitch
|
2016-10-20 19:47:41 +08:00
|
|
|
.find('.dropdown-menu .change-team')
|
2018-07-19 23:56:42 +08:00
|
|
|
.on('click', function() {
|
2017-01-25 19:12:27 +08:00
|
|
|
$('#user_current_team_id')
|
2016-10-17 20:47:09 +08:00
|
|
|
.val($(this).attr('data-id'));
|
2016-10-11 17:40:14 +08:00
|
|
|
|
|
|
|
teamSwitch
|
|
|
|
.find('form')
|
|
|
|
.submit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:49:58 +08:00
|
|
|
// init
|
|
|
|
loadDropdownNotifications();
|
|
|
|
loadUnseenNotificationsNumber();
|
2016-10-05 17:50:57 +08:00
|
|
|
toggleNotificationBellPosition();
|
2016-10-11 17:40:14 +08:00
|
|
|
initGlobalSwitchForm();
|
2019-02-19 18:08:59 +08:00
|
|
|
|
|
|
|
// System notifications
|
|
|
|
|
|
|
|
function loadDropdownSystemNotifications() {
|
|
|
|
var button = $('#system-notifications-dropdown');
|
2019-02-20 20:15:16 +08:00
|
|
|
var noRecentText = $('.system-notifications-no-recent');
|
2019-02-19 18:08:59 +08:00
|
|
|
button
|
|
|
|
.on('click', function() {
|
|
|
|
noRecentText.hide();
|
2019-02-21 23:15:13 +08:00
|
|
|
$('.dropdown-system-notifications .system-notification').remove();
|
2019-02-19 18:08:59 +08:00
|
|
|
$.ajax({
|
|
|
|
url: button.attr('data-href'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
beforeSend: animateSpinner($('.system-notifications-dropdown-header'), true),
|
|
|
|
success: function(data) {
|
2019-02-20 20:15:16 +08:00
|
|
|
var ul = $('.dropdown-system-notifications');
|
2019-02-19 18:08:59 +08:00
|
|
|
$('.system-notifications-dropdown-header')
|
|
|
|
.nextAll('.system-notification')
|
|
|
|
.remove();
|
|
|
|
$('.system-notifications-dropdown-header')
|
|
|
|
.after(data.html);
|
|
|
|
animateSpinner($('.system-notifications-dropdown-header'), false);
|
2019-02-20 20:15:16 +08:00
|
|
|
if (ul.find('.system-notification').length === 0) {
|
2019-02-19 18:08:59 +08:00
|
|
|
noRecentText.show();
|
|
|
|
}
|
|
|
|
bindSystemNotificationAjax();
|
2019-02-21 23:15:13 +08:00
|
|
|
SystemNotificationsMarkAsSeen();
|
2019-02-19 18:08:59 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#count-system-notifications').hide();
|
|
|
|
toggleNotificationBellPosition('system-notifications', '.fa-gift');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// init
|
|
|
|
loadDropdownSystemNotifications();
|
|
|
|
loadUnseenNotificationsNumber('system-notifications', '.fa-gift');
|
|
|
|
})();
|