2016-09-29 20:49:58 +08:00
|
|
|
(function(){
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* Loading overlay for search */
|
|
|
|
$("#search-bar").submit(function (){
|
|
|
|
if( $("#update-canvas") ){
|
|
|
|
$(document.body).spin(true);
|
|
|
|
setTimeout(function(){
|
|
|
|
$(".spinner").remove();
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
animateSpinner();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function loadDropdownNotifications() {
|
|
|
|
var button = $('#notifications-dropdown');
|
2016-10-05 22:48:40 +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) {
|
|
|
|
$('.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
|
|
|
|
|
|
|
var ul = $('.dropdown-menu.dropdown-notifications');
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadUnseenNotificationsNumber() {
|
|
|
|
var notificationCount = $('#count-notifications');
|
|
|
|
$.ajax({
|
|
|
|
url: notificationCount.attr('data-href'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
notificationCount.html('');
|
2016-10-03 14:20:23 +08:00
|
|
|
if ( data.notificationNmber > 0 ) {
|
|
|
|
notificationCount.html(data.notificationNmber);
|
|
|
|
notificationCount.show();
|
2016-10-05 17:50:57 +08:00
|
|
|
toggleNotificationBellPosition();
|
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
|
|
|
}
|
|
|
|
|
2016-10-05 17:50:57 +08:00
|
|
|
function toggleNotificationBellPosition() {
|
|
|
|
var notificationCount = $('#count-notifications');
|
|
|
|
var button = $('#notifications-dropdown');
|
|
|
|
|
|
|
|
if ( notificationCount.is(":hidden") ) {
|
|
|
|
button
|
|
|
|
.find('.fa-bell')
|
|
|
|
.css('position', 'relative');
|
|
|
|
} else {
|
|
|
|
button
|
|
|
|
.find('.fa-bell')
|
|
|
|
.css('position', 'absolute');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-11 17:40:14 +08:00
|
|
|
function initGlobalSwitchForm() {
|
|
|
|
var teamSwitch = $('#team-switch');
|
|
|
|
teamSwitch
|
2016-10-20 19:47:41 +08:00
|
|
|
.find('.dropdown-menu .change-team')
|
2016-10-17 20:47:09 +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-10-21 17:46:59 +08:00
|
|
|
function focusSearchInput() {
|
|
|
|
var searchIco = $('#search-ico');
|
|
|
|
searchIco
|
|
|
|
.on('shown.bs.dropdown', function() {
|
|
|
|
searchIco
|
|
|
|
.find('input.form-control')
|
|
|
|
.focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:49:58 +08:00
|
|
|
// init
|
|
|
|
loadDropdownNotifications();
|
|
|
|
loadUnseenNotificationsNumber();
|
2016-10-05 17:50:57 +08:00
|
|
|
toggleNotificationBellPosition();
|
2016-10-21 17:46:59 +08:00
|
|
|
focusSearchInput();
|
2016-10-11 17:40:14 +08:00
|
|
|
initGlobalSwitchForm();
|
2016-09-29 20:49:58 +08:00
|
|
|
})();
|