2013-10-03 15:04:25 -04:00
|
|
|
define(['forum/accountheader'], function(header) {
|
|
|
|
|
var Account = {};
|
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-03-28 13:02:13 -04:00
|
|
|
var yourid = ajaxify.variables.get('yourid'),
|
|
|
|
|
theirid = ajaxify.variables.get('theirid'),
|
|
|
|
|
isFollowing = ajaxify.variables.get('isFollowing');
|
2013-08-30 12:04:35 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
$(document).ready(function() {
|
2014-02-07 16:58:56 -05:00
|
|
|
var username = $('.account-username').html();
|
2013-11-23 17:07:31 -05:00
|
|
|
app.enterRoom('user/' + theirid);
|
2013-07-30 18:30:43 -04:00
|
|
|
|
2014-03-31 14:43:44 -04:00
|
|
|
utils.addCommasToNumbers($('.account .formatted-number'));
|
|
|
|
|
utils.makeNumbersHumanReadable($('.account .human-readable-number'));
|
2013-11-23 17:18:26 -05:00
|
|
|
$('.user-recent-posts img').addClass('img-responsive');
|
2013-07-30 18:30:43 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
var followBtn = $('#follow-btn');
|
|
|
|
|
var unfollowBtn = $('#unfollow-btn');
|
2013-12-02 14:40:34 -05:00
|
|
|
var chatBtn = $('#chat-btn');
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2013-10-11 14:29:34 -04:00
|
|
|
if (yourid !== theirid && yourid !== "0") {
|
2013-10-03 15:04:25 -04:00
|
|
|
if (isFollowing) {
|
2013-12-02 14:40:34 -05:00
|
|
|
followBtn.addClass('hide');
|
|
|
|
|
unfollowBtn.removeClass('hide');
|
2013-07-30 18:30:43 -04:00
|
|
|
} else {
|
2013-12-02 14:40:34 -05:00
|
|
|
followBtn.removeClass('hide');
|
|
|
|
|
unfollowBtn.addClass('hide');
|
2013-07-30 18:30:43 -04:00
|
|
|
}
|
2013-12-02 14:40:34 -05:00
|
|
|
chatBtn.removeClass('hide');
|
2013-10-03 15:04:25 -04:00
|
|
|
} else {
|
2013-12-02 14:40:34 -05:00
|
|
|
followBtn.addClass('hide');
|
|
|
|
|
unfollowBtn.addClass('hide');
|
|
|
|
|
chatBtn.addClass('hide');
|
2013-10-03 15:04:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
followBtn.on('click', function() {
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('user.follow', {
|
2013-10-03 15:04:25 -04:00
|
|
|
uid: theirid
|
2014-01-16 18:06:19 -05:00
|
|
|
}, function(err) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return app.alertError('There was an error following' + username + '!');
|
2013-10-03 15:04:25 -04:00
|
|
|
}
|
2014-01-16 18:06:19 -05:00
|
|
|
|
|
|
|
|
followBtn.addClass('hide');
|
|
|
|
|
unfollowBtn.removeClass('hide');
|
2014-01-30 13:30:49 -05:00
|
|
|
app.alertSuccess('[[global:alert.follow, ' + username + ']]');
|
2013-10-03 15:04:25 -04:00
|
|
|
});
|
|
|
|
|
return false;
|
2013-07-30 18:30:43 -04:00
|
|
|
});
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
unfollowBtn.on('click', function() {
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('user.unfollow', {
|
2013-10-03 15:04:25 -04:00
|
|
|
uid: theirid
|
2014-01-16 18:06:19 -05:00
|
|
|
}, function(err) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return app.alertError('There was an error unfollowing ' + username + '!');
|
2013-10-03 15:04:25 -04:00
|
|
|
}
|
2014-01-16 18:06:19 -05:00
|
|
|
|
|
|
|
|
followBtn.removeClass('hide');
|
|
|
|
|
unfollowBtn.addClass('hide');
|
2014-01-30 13:30:49 -05:00
|
|
|
app.alertSuccess('[[global:alert.unfollow, ' + username + ']]');
|
2013-10-03 15:04:25 -04:00
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2013-08-30 12:04:35 -04:00
|
|
|
|
2013-12-02 14:40:34 -05:00
|
|
|
chatBtn.on('click', function() {
|
|
|
|
|
app.openChat(username, theirid);
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.on('user.isOnline', Account.handleUserOnline);
|
2013-08-28 22:08:46 -04:00
|
|
|
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('user.isOnline', theirid, Account.handleUserOnline);
|
2013-08-28 22:08:46 -04:00
|
|
|
|
2013-09-03 13:19:51 -04:00
|
|
|
});
|
2013-10-03 15:04:25 -04:00
|
|
|
};
|
2013-09-03 13:11:34 -04:00
|
|
|
|
2014-01-16 17:52:46 -05:00
|
|
|
Account.handleUserOnline = function(err, 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);
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-03 15:04:25 -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
|
|
|
});
|