80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.Sidebar = function(app) {
|
|
var logger = context.JK.logger;
|
|
|
|
function populateFriendsPanel() {
|
|
|
|
var url = "/api/users/" + context.JK.currentUserId + "/friends"
|
|
$.ajax({
|
|
type: "GET",
|
|
dataType: "json",
|
|
contentType: 'application/json',
|
|
url: url,
|
|
processData: false,
|
|
success: function(response) {
|
|
$.each(response, function(index, val) {
|
|
|
|
var css = val.online ? '' : 'offline';
|
|
|
|
// fill in template for Connect pre-click
|
|
var template = $('#template-friend-panel').html();
|
|
var searchResultHtml = context.JK.fillTemplate(template, {
|
|
userId: val.id,
|
|
cssClass: css,
|
|
avatar_url: context.JK.resolveAvatarUrl(val.photo_url),
|
|
userName: val.name,
|
|
status: val.online ? 'Available' : 'Offline',
|
|
extra_info: '',
|
|
info_image_url: ''
|
|
});
|
|
|
|
$('#sidebar-friend-list').append(searchResultHtml);
|
|
});
|
|
|
|
// set friend count
|
|
$('#sidebar-friend-count').html(response.length);
|
|
},
|
|
error: app.ajaxError
|
|
});
|
|
|
|
return false;
|
|
}
|
|
|
|
function sendFriendRequest(evt) {
|
|
evt.stopPropagation();
|
|
var userId = $(this).parent().attr('user-id');
|
|
|
|
//$(this).parent().empty();
|
|
|
|
var url = "/api/users/" + context.JK.currentUserId + "/friend_requests";
|
|
$.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
contentType: 'application/json',
|
|
url: url,
|
|
data: '{"friend_id":"' + userId + '"}',
|
|
processData: false,
|
|
success: function(response) {
|
|
// toggle the pre-click and post-click divs
|
|
$('div[user-id=' + userId + '].search-connected').show();
|
|
$('div[user-id=' + userId + '].search-result').hide();
|
|
},
|
|
error: app.ajaxError
|
|
});
|
|
}
|
|
|
|
function events() {
|
|
populateFriendsPanel();
|
|
}
|
|
|
|
this.initialize = function() {
|
|
events();
|
|
};
|
|
|
|
};
|
|
|
|
})(window,jQuery); |