93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
(function(context,$) {
|
|
/** Javascript for managing the (account dropdown) */
|
|
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.UserDropdown = function(app) {
|
|
|
|
var logger = context.JK.logger;
|
|
var rest = new JK.Rest();
|
|
var userMe = null;
|
|
var invitationDialog = null;
|
|
|
|
function menuHoverIn() {
|
|
$('ul.shortcuts', this).show();
|
|
}
|
|
|
|
function menuHoverOut() {
|
|
$('ul.shortcuts', this).hide();
|
|
}
|
|
|
|
function events() {
|
|
$('.userinfo').hoverIntent(menuHoverIn, menuHoverOut);
|
|
|
|
$('.userinfo .invite-friends .menuheader').on('click', function(e) {
|
|
$(this).closest('li').css('height', 'auto').find('ul').toggle();
|
|
e.stopPropagation();
|
|
return false;
|
|
});
|
|
|
|
$('.invite-friends .google-invite a').on('click', function(e) {
|
|
invitationDialog.showGoogleDialog();
|
|
});
|
|
|
|
$('.invite-friends .email-invite a').on('click', function(e) {
|
|
invitationDialog.showEmailDialog();
|
|
});
|
|
|
|
$('#header-avatar').on('avatar_changed', function(event, newAvatarUrl) {
|
|
updateAvatar(newAvatarUrl);
|
|
event.preventDefault();
|
|
return false;
|
|
})
|
|
}
|
|
|
|
function loadMe() {
|
|
$.ajax({
|
|
url: '/api/users/' + context.JK.currentUserId
|
|
}).done(function(r) {
|
|
userMe = r;
|
|
// TODO - Setting global variable for local user.
|
|
context.JK.userMe = r;
|
|
updateHeader();
|
|
handleWhatsNext(userMe);
|
|
}).fail(app.ajaxError);
|
|
}
|
|
|
|
function updateHeader() {
|
|
$('#user').html(userMe.name);
|
|
showAvatar();
|
|
}
|
|
|
|
function handleWhatsNext(userProfile) {
|
|
if(gon.isNativeClient && userProfile.show_whats_next) {
|
|
app.layout.showDialog('whatsNext');
|
|
}
|
|
}
|
|
|
|
|
|
// initially show avatar
|
|
function showAvatar() {
|
|
var photoUrl = context.JK.resolveAvatarUrl(userMe.photo_url);
|
|
$('#header-avatar').attr('src', photoUrl);
|
|
}
|
|
|
|
// handle update avatar event
|
|
function updateAvatar(avatar_url) {
|
|
var photoUrl = context.JK.resolveAvatarUrl(avatar_url);
|
|
var avatar = $(new Image());
|
|
avatar.attr('src', photoUrl + '?cache_bust=' + new Date().getTime());
|
|
avatar.attr('alt', "Avatar");
|
|
avatar.attr('id', 'header-avatar');
|
|
$('#header-avatar').replaceWith(avatar);
|
|
}
|
|
|
|
this.initialize = function(invitationDialogInstance) {
|
|
events();
|
|
invitationDialog = invitationDialogInstance;
|
|
loadMe();
|
|
}
|
|
}
|
|
})(window,jQuery); |