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

96 lines
2.5 KiB
JavaScript
Raw Normal View History

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