Files
NodeBB/public/src/forum/account/profile.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
/* globals define, ajaxify, app, utils, socket, translator*/
define('forum/account/profile', ['forum/account/header'], function(header) {
2014-04-11 15:53:57 -04:00
var Account = {},
yourid,
theirid,
isFollowing;
Account.init = function() {
header.init();
2014-04-11 15:53:57 -04:00
yourid = ajaxify.variables.get('yourid');
theirid = ajaxify.variables.get('theirid');
isFollowing = ajaxify.variables.get('isFollowing');
2013-08-30 12:04:35 -04:00
app.enterRoom('user/' + theirid);
2014-04-11 15:53:57 -04:00
processPage();
2014-04-11 15:53:57 -04:00
updateButtons();
$('#follow-btn').on('click', function() {
return toggleFollow('follow');
});
$('#unfollow-btn').on('click', function() {
return toggleFollow('unfollow');
});
2013-08-28 22:08:46 -04:00
$('#chat-btn').on('click', function() {
2014-04-11 15:53:57 -04:00
app.openChat($('.account-username').html(), theirid);
});
socket.removeListener('event:user_status_change', onUserStatusChange);
socket.on('event:user_status_change', onUserStatusChange);
if (yourid !== theirid) {
socket.emit('user.increaseViewCount', theirid);
}
};
2013-09-03 13:11:34 -04:00
2014-04-11 15:53:57 -04:00
function processPage() {
2014-09-01 13:29:49 -04:00
$('.user-recent-posts img, .post-signature img').addClass('img-responsive');
2014-04-11 15:53:57 -04:00
}
function updateButtons() {
2014-05-23 22:55:54 -04:00
var isSelfOrNotLoggedIn = yourid === theirid || parseInt(yourid, 10) === 0;
2014-04-11 15:53:57 -04:00
$('#follow-btn').toggleClass('hide', isFollowing || isSelfOrNotLoggedIn);
$('#unfollow-btn').toggleClass('hide', !isFollowing || isSelfOrNotLoggedIn);
$('#chat-btn').toggleClass('hide', isSelfOrNotLoggedIn);
}
function toggleFollow(type) {
socket.emit('user.' + type, {
2014-04-11 15:53:57 -04:00
uid: theirid
}, function(err) {
if(err) {
return app.alertError(err.message);
}
$('#follow-btn').toggleClass('hide', type === 'follow');
$('#unfollow-btn').toggleClass('hide', type === 'unfollow');
app.alertSuccess('[[global:alert.' + type + ', ' + $('.account-username').html() + ']]');
});
return false;
}
function onUserStatusChange(data) {
var onlineStatus = $('.account-online-status');
if(parseInt(ajaxify.variables.get('theirid'), 10) !== parseInt(data.uid, 10)) {
2014-01-31 15:13:52 -05:00
return;
}
2014-01-31 15:13:52 -05:00
2014-02-23 21:50:02 -05:00
translator.translate('[[global:' + data.status + ']]', function(translated) {
onlineStatus.attr('class', 'account-online-status fa fa-circle status ' + data.status)
.attr('title', translated)
.attr('data-original-title', translated);
});
}
return Account;
2013-12-02 19:23:52 -05:00
});