From 45542b7a1d6e8c1f431964f2f8dc3cef9f5841a6 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 26 Nov 2014 04:32:06 +0000 Subject: [PATCH] VRFS-1442 band profile, members editing; change notifyAlert to default to 1 button; added band_admin attribute to band members --- web/app/assets/javascripts/bandProfile.js | 43 ++++++++++++++++----- web/app/assets/javascripts/jamkazam.js | 2 +- web/app/assets/javascripts/layout.js | 3 +- web/app/assets/javascripts/profile.js | 14 ++++++- web/app/controllers/api_bands_controller.rb | 4 +- web/app/views/api_bands/musician_index.rabl | 4 ++ web/app/views/clients/_bandProfile.html.erb | 24 +++++++----- web/app/views/clients/_profile.html.erb | 5 ++- 8 files changed, 74 insertions(+), 25 deletions(-) diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 3066efe85..dff8c01fd 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -20,6 +20,9 @@ // hide until we know if 'isMember' $("#btn-follow-band").hide(); $("#btn-edit-band-profile").hide(); + $("#btn-edit-band-info").hide(); + $("#btn-edit-band-members").hide(); + $("#btn-edit-band-delete").hide(); resetForm(); events(); @@ -141,10 +144,16 @@ if (isMember) { $("#btn-follow-band").hide(); $("#btn-edit-band-profile").show(); + $("#btn-edit-band-info").show(); + $("#btn-edit-band-members").show(); + $("#btn-edit-band-delete").show(); } else { $("#btn-follow-band").show(); $("#btn-edit-band-profile").hide(); + $("#btn-edit-band-info").hide(); + $("#btn-edit-band-members").hide(); + $("#btn-edit-band-delete").hide(); } if ($('#band-profile-about-link').hasClass('active')) { @@ -247,6 +256,7 @@ rest.getBandFollowers(bandId) .done(function(response) { $.each(response, function(index, val) { + // var template = $('#template-profile-social').html(); var template = $('#template-band-profile-social').html(); var followerHtml = context.JK.fillTemplate(template, { userId: val.id, @@ -354,10 +364,11 @@ instrumentLogoHtml += ' '; } } - + var bandAdmin = musician.band_admin; var template = $('#template-band-profile-members').html(); var memberHtml = context.JK.fillTemplate(template, { userId: musician.id, + band_admin: bandAdmin, profile_url: "/client#/profile/" + musician.id, avatar_url: context.JK.resolveAvatarUrl(musician.photo_url), name: musician.name, @@ -374,7 +385,7 @@ // wire up Follow button click handler configureMemberFollowingButton(musician.is_following, musician.id); - configureRemoveMemberButton(musician.id, isPending); + configureRemoveMemberButton(musician.id, isPending, bandAdmin); // TODO: wire up Friend button click handler // var friend = isFriend(musician.id); @@ -382,21 +393,30 @@ }); } - function configureRemoveMemberButton(userId, isPending) { - + function configureRemoveMemberButton(userId, isPending, bandAdmin) { var $divMember = $('div[user-id=' + userId + ']', '#band-profile-members'); var $btnRemoveMember = $divMember.find('#btn-remove-member'); - if (isMember && !isPending) { + if (isMember && !isPending && !bandAdmin) { $btnRemoveMember.show(); $btnRemoveMember.unbind("click"); $btnRemoveMember.click(function() { - rest.removeBandMember(bandId, userId) + var confirmMemberDeleteTxt; + if (userId == context.JK.currentUserId) + confirmMemberDeleteTxt = 'Are you sure you want to delete yourself from the band?'; + else + confirmMemberDeleteTxt = 'Are you sure you want to delete this member from the band?'; + var confirmDialog = new context.JK.ConfirmDialog(app, "DELETE", confirmMemberDeleteTxt, "Edit Band Membership", + function() { + app.layout.closeDialog('confirm'); + rest.removeBandMember(bandId, userId) .done(function() { - $divMember.remove(); + $divMember.remove(); }) .fail(app.ajaxError); - - return false; + }); + confirmDialog.initialize(); + context.JK.app.layout.showDialog('confirm'); + return false; }); } else { @@ -433,7 +453,10 @@ $('#band-profile-social-link').unbind('click').click(renderSocial); $("#btn-edit-band-profile").unbind('click').click(function() { - //$('div[layout-id="band/setup"] .hdn-band-id').val(bandId); + context.location = "/client#/band/setup/" + bandId + '/step1'; + return false; + }); + $("#btn-edit-band-info").unbind('click').click(function() { context.location = "/client#/band/setup/" + bandId + '/step1'; return false; }); diff --git a/web/app/assets/javascripts/jamkazam.js b/web/app/assets/javascripts/jamkazam.js index ba3d4e25b..b3ab70e8f 100644 --- a/web/app/assets/javascripts/jamkazam.js +++ b/web/app/assets/javascripts/jamkazam.js @@ -202,7 +202,7 @@ * title property and a text property. */ this.notify = function (message, descriptor) { - this.layout.notify(message, descriptor); + this.layout.notify(message, descriptor, true); }; /** Shows an alert notification. Expects text, title */ diff --git a/web/app/assets/javascripts/layout.js b/web/app/assets/javascripts/layout.js index 7bf5abfd2..c37301b38 100644 --- a/web/app/assets/javascripts/layout.js +++ b/web/app/assets/javascripts/layout.js @@ -867,7 +867,8 @@ // this allows clients to just specify the important action button without having to repeat the cancel descripton everywhere if (buttons.length === 1) { - buttons.push(cancelButton); + // jkolyer: changed default to remove cancel as this is used as an alert, not a confirmation (see ConfirmDialog) + // buttons.push(cancelButton); } var $notify = $('[layout="notify"]'); diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 6f76d65f8..edd6187d2 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -14,7 +14,6 @@ var profileScreen = null; var textMessageDialog = null; var feed = null; - var isBandMember = false; var instrument_logo_map = context.JK.getInstrumentIconMap24(); @@ -609,6 +608,7 @@ addMoreBandsLink(); $.each(response, function (index, val) { + var isBandMember = false; // build band member HTML var musicianHtml = ''; @@ -628,6 +628,9 @@ instrumentLogoHtml += ' '; } } + if (!isBandMember) + isBandMember = musician.id === context.JK.currentUserId; + // this template is in _findSession.html.erb var musicianTemplate = $('#template-musician-info').html(); musicianHtml += context.JK.fillTemplate(musicianTemplate, { @@ -645,6 +648,8 @@ bandId: val.id, biography: val.biography, profile_url: "/client#/bandProfile/" + val.id, + band_edit_url: "/client#/band/setup/" + val.id + '/step1', + band_member_url: "/client#/band/setup/" + val.id + '/step2', avatar_url: context.JK.resolveBandAvatarUrl(val.photo_url), name: val.name, location: val.location, @@ -656,6 +661,13 @@ }); $('#profile-bands').append(bandHtml); + + $('.profile-band-link-member-true').each(function(idx) { + isBandMember ? $(this).show() : $(this).hide(); + }); + $('.profile-band-link-member-false').each(function(idx) { + isBandMember ? $(this).hide() : $(this).show(); + }); // wire up Band Follow button click handler configureBandFollowingButton(val.is_following, val.id); diff --git a/web/app/controllers/api_bands_controller.rb b/web/app/controllers/api_bands_controller.rb index e3fcfedbc..6f518fa4d 100644 --- a/web/app/controllers/api_bands_controller.rb +++ b/web/app/controllers/api_bands_controller.rb @@ -54,7 +54,7 @@ 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]}')" + BandMusician.delete_all "(band_id = '#{params[:id]}' AND user_id = '#{params[:user_id]}' AND admin = 'f')" end render :json => {}, :status => 202 end @@ -236,4 +236,4 @@ class ApiBandsController < ApiController raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR end end -end \ No newline at end of file +end diff --git a/web/app/views/api_bands/musician_index.rabl b/web/app/views/api_bands/musician_index.rabl index f47fe7f5e..cfb95ab15 100644 --- a/web/app/views/api_bands/musician_index.rabl +++ b/web/app/views/api_bands/musician_index.rabl @@ -2,6 +2,10 @@ collection @musicians attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :follower_count, :following_count, :recording_count, :session_count, :biography +node :band_admin do |musician| + 't' == musician.band_admin ? true : false +end + node :instruments do |musician| unless musician.instruments.nil? || musician.instruments.size == 0 child :musician_instruments => :instruments do diff --git a/web/app/views/clients/_bandProfile.html.erb b/web/app/views/clients/_bandProfile.html.erb index 12baf47fa..4ba9ada50 100644 --- a/web/app/views/clients/_bandProfile.html.erb +++ b/web/app/views/clients/_bandProfile.html.erb @@ -19,9 +19,7 @@
FOLLOW - PROFILE - EDIT BAND - INVITE MEMBERS + EDIT PROFILE


@@ -54,7 +52,13 @@
-

+
+ EDIT + INVITE + DELETE +
+

+


@@ -71,7 +75,7 @@
-
+

Followers

@@ -85,7 +89,7 @@
diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index 74070c8fd..62d23c977 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -206,7 +206,10 @@