2014-04-11 15:44:53 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* globals define, ajaxify, app, utils, socket, translator*/
|
|
|
|
|
|
2014-05-29 17:24:38 -04:00
|
|
|
define('forum/account/profile', ['forum/account/header'], function(header) {
|
2014-04-11 15:53:57 -04:00
|
|
|
var Account = {},
|
|
|
|
|
yourid,
|
|
|
|
|
theirid,
|
|
|
|
|
isFollowing;
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
Account.init = function() {
|
|
|
|
|
header.init();
|
2013-05-29 12:17:44 -04:00
|
|
|
|
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
|
|
|
|
2014-04-11 15:44:53 -04:00
|
|
|
app.enterRoom('user/' + theirid);
|
|
|
|
|
|
2014-04-11 15:53:57 -04:00
|
|
|
processPage();
|
2014-04-11 15:44:53 -04:00
|
|
|
|
2014-04-11 15:53:57 -04:00
|
|
|
updateButtons();
|
2014-04-11 15:44:53 -04:00
|
|
|
|
|
|
|
|
$('#follow-btn').on('click', function() {
|
|
|
|
|
return toggleFollow('follow');
|
|
|
|
|
});
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-04-11 15:44:53 -04:00
|
|
|
$('#unfollow-btn').on('click', function() {
|
|
|
|
|
return toggleFollow('unfollow');
|
|
|
|
|
});
|
2013-08-28 22:08:46 -04:00
|
|
|
|
2014-04-11 15:44:53 -04:00
|
|
|
$('#chat-btn').on('click', function() {
|
2014-04-11 15:53:57 -04:00
|
|
|
app.openChat($('.account-username').html(), theirid);
|
2013-09-03 13:19:51 -04:00
|
|
|
});
|
2014-04-11 15:44:53 -04:00
|
|
|
|
2014-09-06 22:08:55 -04:00
|
|
|
socket.removeListener('event:user_status_change', onUserStatusChange);
|
|
|
|
|
socket.on('event:user_status_change', onUserStatusChange);
|
2014-04-11 15:44:53 -04:00
|
|
|
|
2014-05-28 18:15:53 -04:00
|
|
|
if (yourid !== theirid) {
|
|
|
|
|
socket.emit('user.increaseViewCount', theirid);
|
|
|
|
|
}
|
2013-10-03 15:04:25 -04:00
|
|
|
};
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 15:44:53 -04:00
|
|
|
function toggleFollow(type) {
|
|
|
|
|
socket.emit('user.' + type, {
|
2014-04-11 15:53:57 -04:00
|
|
|
uid: theirid
|
2014-04-11 15:44:53 -04:00
|
|
|
}, 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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-06 22:08:55 -04:00
|
|
|
function onUserStatusChange(data) {
|
2013-10-03 15:04:25 -04:00
|
|
|
var onlineStatus = $('.account-online-status');
|
|
|
|
|
|
2014-03-28 13:02:13 -04:00
|
|
|
if(parseInt(ajaxify.variables.get('theirid'), 10) !== parseInt(data.uid, 10)) {
|
2014-01-31 15:13:52 -05:00
|
|
|
return;
|
2013-10-03 15:04:25 -04:00
|
|
|
}
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-11 15:44:53 -04:00
|
|
|
}
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
return Account;
|
2013-12-02 19:23:52 -05:00
|
|
|
});
|