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

98 lines
2.5 KiB
JavaScript
Raw Normal View History

define(['forum/accountheader'], function(header) {
var Account = {};
Account.init = function() {
header.init();
var yourid = templates.get('yourid'),
theirid = templates.get('theirid'),
isFollowing = templates.get('isFollowing');
2013-08-30 12:04:35 -04:00
$(document).ready(function() {
var username = $('.account-username a').html();
app.enterRoom('user/' + theirid);
app.addCommasToNumbers();
$('.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('You are now following ' + 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('You are no longer following ' + 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
socket.on('event:new_post', function(data) {
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
$('.user-recent-posts').prepend(html);
2013-11-26 19:09:32 -05:00
$('.user-recent-posts span.timeago').timeago();
});
});
};
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 (data.online) {
onlineStatus.find('span span').text('online');
2013-11-26 14:25:46 -05:00
onlineStatus.find('i').attr('class', 'fa fa-circle');
} else {
onlineStatus.find('span span').text('offline');
2013-11-26 14:25:46 -05:00
onlineStatus.find('i').attr('class', 'fa fa-circle-o');
}
};
return Account;
2013-12-02 19:23:52 -05:00
});