VRFS-876 allow user to remove band members

This commit is contained in:
Brian Smith 2013-12-07 20:45:24 -05:00
parent c49406d467
commit 5856c5d176
4 changed files with 43 additions and 6 deletions

View File

@ -5,6 +5,7 @@
context.JK = context.JK || {};
context.JK.BandProfileScreen = function(app) {
var logger = context.JK.logger;
var rest = context.JK.Rest();
var bandId;
var isMember = false;
var band = {};
@ -59,7 +60,7 @@
configureBandFollowingButton(true);
}
else {
configureMemberFollowingButton(true);
configureMemberFollowingButton(true, id);
}
},
error: app.ajaxError
@ -350,7 +351,6 @@
}
function bindPendingMembers() {
$("#band-profile-members").append("<br/><br/><h2><b>Pending Band Invitations</b></h2>");
var url = "/api/bands/" + bandId + "/musicians?pending=true";
$.ajax({
type: "GET",
@ -359,7 +359,10 @@
async: false,
processData:false,
success: function(response) {
bindMusicians(response);
if (response && response.length > 0) {
$("#band-profile-members").append("<br/><br/><h2><b>Pending Band Invitations</b></h2>");
bindMusicians(response);
}
},
error: app.ajaxError
});
@ -400,12 +403,34 @@
var following = isFollowingMember(musician.id);
configureMemberFollowingButton(following, musician.id);
configureRemoveMemberButton(musician.id);
// TODO: wire up Friend button click handler
// var friend = isFriend(musician.id);
// configureMemberFriendButton(friend, musician.id);
});
}
function configureRemoveMemberButton(userId) {
var $divMember = $('div[user-id=' + userId + ']', '#band-profile-members');
var $btnRemoveMember = $divMember.find('#btn-remove-member');
if (isMember) {
$btnRemoveMember.show();
$btnRemoveMember.unbind("click");
$btnRemoveMember.click(function() {
rest.removeBandMember(bandId, userId)
.done(function() {
$divMember.remove();
})
.fail(app.ajaxError);
});
}
else {
$btnRemoveMember.hide();
}
}
// TODO: refactor
// checks if person viewing the profile is also a band member
function setIsMember() {
@ -441,12 +466,10 @@
if (isMember) {
$("#btn-follow-band").hide();
$("#btn-edit-band-members").show();
$("#btn-edit-band-profile").show();
}
else {
$("#btn-follow-band").show();
$("#btn-edit-band-members").hide();
$("#btn-edit-band-profile").hide();
}

View File

@ -115,6 +115,17 @@
});
}
function removeBandMember(bandId, userId) {
var url = "/api/bands/" + bandId + "/musicians/" + userId;
return $.ajax({
type: "DELETE",
dataType: "json",
url: url,
async: false,
processData:false
});
}
function getSession(id) {
var url = "/api/sessions/" + id;
return $.ajax({
@ -484,6 +495,7 @@
this.getBand = getBand;
this.createBandInvitation = createBandInvitation;
this.updateBandInvitation = updateBandInvitation;
this.removeBandMember = removeBandMember;
return this;
};

View File

@ -65,7 +65,9 @@ class ApiBandsController < ApiController
def musician_destroy
unless params[:id].blank? || params[:user_id].blank?
BandMusician.delete_all "(band_id = '#{params[:id]}' AND user_id = '#{params[:user_id]}')"
end
render :json => {}, :status => 202
end
###################### FOLLOWERS ########################

View File

@ -19,7 +19,6 @@
<div class="right">
<a id="btn-follow-band" class="button-orange">FOLLOW</a>
<a id="btn-edit-band-profile" class="button-orange">EDIT PROFILE</a>
<a id="btn-edit-band-members" class="button-orange">EDIT MEMBERS</a>
</div>
<br clear="all" /><br />
@ -92,6 +91,7 @@
{biography}<br /><br />
<a class="button-orange smallbutton m0" href="{profile_url}">PROFILE</a>&nbsp;&nbsp;
<a id="btn-follow-member" class="button-orange smallbutton m0">FOLLOW</a>&nbsp;&nbsp;
<a id="btn-remove-member" class="button-orange smallbutton m0">REMOVE MEMBER</a>&nbsp;&nbsp;
<a id="btn-friend-member" style="display:none;" class="button-orange smallbutton m0">CONNECT</a>
</div>
</div>