diff --git a/app/assets/javascripts/searchResults.js b/app/assets/javascripts/searchResults.js index 9db735606..860a7e92d 100644 --- a/app/assets/javascripts/searchResults.js +++ b/app/assets/javascripts/searchResults.js @@ -14,10 +14,6 @@ } function afterShow(data) { - // TODO remove me - just showing that you should - // have access to the query variable from the search - // box. - //$('#show-query').text('Query is ' + query); } function search(evt) { @@ -98,9 +94,8 @@ data: '{"friend_id":"' + userId + '"}', processData: false, success: function(response) { - //alert($(this).parent().find('div[user-id=' + userId + '].search-connected')); + // toggle the pre-click and post-click divs $('div[user-id=' + userId + '].search-connected').show(); - //$(this).parent().find('div[user-id=' + userId + '].search-result').empty(); $('div[user-id=' + userId + '].search-result').hide(); }, error: app.ajaxError @@ -122,11 +117,7 @@ } function events() { - // not sure it should go here long-term, but wiring - // up the event handler for the search box in the sidebar. $('#searchForm').submit(search); - - $('#btn-connect-friend').on("click", sendFriendRequest); } this.initialize = function() { diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js new file mode 100644 index 000000000..e1ca1e9a0 --- /dev/null +++ b/app/assets/javascripts/sidebar.js @@ -0,0 +1,80 @@ +(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); \ No newline at end of file diff --git a/app/views/api_users/friend_index.rabl b/app/views/api_users/friend_index.rabl index 511a0d127..cfa21fade 100644 --- a/app/views/api_users/friend_index.rabl +++ b/app/views/api_users/friend_index.rabl @@ -1,3 +1,3 @@ object @user.friends -attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online, :photo_url \ No newline at end of file +attributes :id, :first_name, :last_name, :name, :location, :email, :online, :photo_url \ No newline at end of file diff --git a/app/views/clients/_sidebar.html.erb b/app/views/clients/_sidebar.html.erb index 896a10565..6d4ed5f7b 100644 --- a/app/views/clients/_sidebar.html.erb +++ b/app/views/clients/_sidebar.html.erb @@ -26,67 +26,10 @@
@@ -222,3 +165,17 @@ + + diff --git a/app/views/clients/index.html.erb b/app/views/clients/index.html.erb index 695b9ebd4..6f12e48d6 100644 --- a/app/views/clients/index.html.erb +++ b/app/views/clients/index.html.erb @@ -72,6 +72,9 @@ var header = new JK.Header(JK.app); header.initialize(); + var sidebar = new JK.Sidebar(JK.app); + sidebar.initialize(); + var homeScreen = new JK.HomeScreen(JK.app); homeScreen.initialize();