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
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
var yourid = templates.get('yourid'),
|
|
|
|
|
theirid = templates.get('theirid'),
|
|
|
|
|
isFollowing = templates.get('isFollowing');
|
2013-08-30 12:04:35 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
var username = $('.account-username a').html();
|
2013-11-23 17:07:31 -05:00
|
|
|
app.enterRoom('user/' + theirid);
|
2013-07-30 18:30:43 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
app.addCommasToNumbers();
|
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() {
|
|
|
|
|
socket.emit('api:user.follow', {
|
|
|
|
|
uid: theirid
|
|
|
|
|
}, function(success) {
|
|
|
|
|
if (success) {
|
2013-12-02 14:40:34 -05:00
|
|
|
followBtn.addClasss('hide');
|
|
|
|
|
unfollowBtn.removeClass('hide');
|
2013-10-03 15:04:25 -04:00
|
|
|
app.alertSuccess('You are now following ' + username + '!');
|
|
|
|
|
} else {
|
|
|
|
|
app.alertError('There was an error following' + username + '!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
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() {
|
|
|
|
|
socket.emit('api:user.unfollow', {
|
|
|
|
|
uid: theirid
|
|
|
|
|
}, function(success) {
|
|
|
|
|
if (success) {
|
2013-12-02 14:40:34 -05:00
|
|
|
followBtn.removeClass('hide');
|
|
|
|
|
unfollowBtn.addClass('hide');
|
2013-10-03 15:04:25 -04:00
|
|
|
app.alertSuccess('You are no longer following ' + username + '!');
|
|
|
|
|
} else {
|
|
|
|
|
app.alertError('There was an error unfollowing ' + 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);
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
$('.user-recent-posts .topic-row').on('click', function() {
|
|
|
|
|
ajaxify.go($(this).attr('topic-url'));
|
|
|
|
|
});
|
2013-08-30 12:04:35 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
socket.on('api:user.isOnline', Account.handleUserOnline);
|
2013-08-28 22:08:46 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
socket.emit('api:user.isOnline', theirid, Account.handleUserOnline);
|
2013-08-28 22:08:46 -04:00
|
|
|
|
2013-10-03 15:04:25 -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-10-03 15:04:25 -04:00
|
|
|
});
|
2013-07-19 12:03:54 -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
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
Account.handleUserOnline = function(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');
|
2013-10-03 15:04:25 -04:00
|
|
|
} else {
|
|
|
|
|
onlineStatus.find('span span').text('offline');
|
2013-11-26 14:25:46 -05:00
|
|
|
onlineStatus.find('i').attr('class', 'fa fa-circle-o');
|
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;
|
|
|
|
|
});
|