* fixing the refresh of sidebar friends when friend request accepted

This commit is contained in:
Seth Call 2014-03-26 17:31:51 +00:00
parent d365054237
commit ba43244b69
4 changed files with 21 additions and 41 deletions

View File

@ -19,6 +19,7 @@
var user = null;
var sending = false;
var friendRequest = null;
var sidebar = null;
function reset() {
sending = false;
@ -52,6 +53,7 @@
rest.acceptFriendRequest(buildAcceptRequest())
.done(function() {
app.layout.closeDialog('accept-friend-request')
sidebar.refreshFriends();
})
.fail(function(jqXHR) {
app.notifyServerError(jqXHR, 'Unable to Accept Friend Request');
@ -167,7 +169,7 @@
reset();
}
function initialize() {
function initialize(sidebarInstance) {
var dialogBindings = {
'beforeShow' : beforeShow,
'afterHide': afterHide
@ -176,6 +178,7 @@
app.bindDialog('accept-friend-request', dialogBindings);
sidebar = sidebarInstance;
$dialog = $('#accept-friend-request-dialog');
$dialogContents = $dialog.find('.dialog-inner');
$notFriendsTemplate = $('#template-friend-request-not-friends');

View File

@ -22,48 +22,20 @@
emptySearchResults();
}
function refreshFriends() {
rest.getFriends().
done(function(response) {
friends = response;
updateFriendList(response);
// set friend count
$('#sidebar-friend-count').html(response.length);
})
}
function initializeFriendsPanel() {
/////////////////////////////////////////////////////////////
// THIS IS TEST CODE TO GENERATE BACK TO BACK NOTIFICATIONS
// app.notify({
// "title": "TEST 1",
// "text": "Test 1",
// "icon_url": context.JK.resolveAvatarUrl("")
// });
// app.notify({
// "title": "TEST 2",
// "text": "Test 2",
// "icon_url": context.JK.resolveAvatarUrl("")
// });
// app.notify({
// "title": "TEST 3",
// "text": "Test 3",
// "icon_url": context.JK.resolveAvatarUrl("")
// });
/////////////////////////////////////////////////////////////
$('#sidebar-search-header').hide();
var url = "/api/users/" + context.JK.currentUserId + "/friends"
$.ajax({
type: "GET",
dataType: "json",
contentType: 'application/json',
url: url,
processData: false,
success: function(response) {
friends = response;
updateFriendList(response);
// set friend count
$('#sidebar-friend-count').html(response.length);
},
error: app.ajaxError
});
refreshFriends();
return false;
}
@ -1182,5 +1154,7 @@
invitationDialog = invitationDialogInstance;
textMessageDialog = textMessageDialogInstance;
};
this.refreshFriends = refreshFriends;
}
})(window,jQuery);

View File

@ -135,7 +135,6 @@
textMessageDialog.initialize();
var acceptFriendRequestDialog = new JK.AcceptFriendRequestDialog(JK.app);
acceptFriendRequestDialog.initialize();
var localRecordingsDialog = new JK.LocalRecordingsDialog(JK.app);
localRecordingsDialog.initialize();
@ -155,6 +154,7 @@
header.initialize();
var sidebar = new JK.Sidebar(JK.app);
acceptFriendRequestDialog.initialize(sidebar);
sidebar.initialize(invitationDialog, textMessageDialog);
var homeScreen = new JK.HomeScreen(JK.app);

View File

@ -30,6 +30,9 @@ describe "Accept Friend Request", :js => true, :type => :feature, :capybara_feat
page.should_not have_selector('h1', text: 'friend request')
friend_request.reload
friend_request.status.should == 'accept'
# make sure the friend list is refreshed
find("[layout-id=\"panelFriends\"] .friend-name[user-id=\"#{@user2.id}\"]", visible: false)
end
it "already accepted" do