diff --git a/ruby/lib/jam_ruby/constants/limits.rb b/ruby/lib/jam_ruby/constants/limits.rb
index 5d5e409d0..52e2036f1 100644
--- a/ruby/lib/jam_ruby/constants/limits.rb
+++ b/ruby/lib/jam_ruby/constants/limits.rb
@@ -2,7 +2,7 @@ module Limits
# band genres
MIN_GENRES_PER_BAND = 1
- MAX_GENRES_PER_BAND = 1
+ MAX_GENRES_PER_BAND = 3
# recording genres
MIN_GENRES_PER_RECORDING = 1
diff --git a/web/app/assets/javascripts/band_setup.js b/web/app/assets/javascripts/band_setup.js
index e642dcb3c..83358a970 100644
--- a/web/app/assets/javascripts/band_setup.js
+++ b/web/app/assets/javascripts/band_setup.js
@@ -3,11 +3,14 @@
"use strict";
context.JK = context.JK || {};
- // TODO: MUCH OF THIS CLASS IS REPEATED IN createSession.js - REFACTOR
+
+ // TODO: MUCH OF THIS CLASS IS REPEATED IN THE FOLLOWING FILES:
+ // createSession.js
+ // accounts_profiles.js
+
context.JK.BandSetupScreen = function(app) {
var logger = context.JK.logger;
var rest = context.JK.Rest();
- var band = {};
var friendSelectorDialog = null;
var autoComplete = null;
var userNames = [];
@@ -19,26 +22,89 @@
}
- function formatGenres(genres) {
- var formattedGenres = '';
- if (genres) {
- for (var i=0; i < genres.length; i++) {
- var genre = genres[i];
- formattedGenres += genre.description;
- if (i < genres.length -1) {
- formattedGenres += ', ';
- }
- }
- }
- return formattedGenres;
+ // function formatGenres(genres) {
+ // var formattedGenres = '';
+ // if (genres) {
+ // for (var i=0; i < genres.length; i++) {
+ // var genre = genres[i];
+ // formattedGenres += genre.description;
+ // if (i < genres.length -1) {
+ // formattedGenres += ', ';
+ // }
+ // }
+ // }
+ // return formattedGenres;
+ // }
+
+ function getSelectedGenres() {
+ var genres = [];
+ $('input[type=checkbox]:checked', '#band-genres').each(function(i) {
+ var genre = $(this).val();
+ genres.push(genre);
+ });
+ logger.debug("genres.length=" + genres.length);
+ return genres;
+ }
+
+ function validateForm() {
+ var isValid = true;
+ // name
+
+ // country
+
+ // state
+
+ // city
+
+ // genres (no more than 3)
+
+ // description
+
+
+ return isValid;
}
function createBand() {
+ if (validateForm()) {
+ var band = {};
+ band.name = $("#band-name").val();
+ band.website = $("#band-website").val();
+ band.biography = $("#band-biography").val();
+ band.city = $("#band-city").val();
+ band.state = $("#band-state").val();
+ band.country = $("#band-country").val();
+ band.genres = getSelectedGenres();
+ rest.createBand(band).done(function(response) {
+ createBandInvitations(response.id, function() {
+ context.location = "#/bandProfile/" + response.id;
+ });
+ });
+ }
}
- function createBandInvitation() {
+ function createBandInvitations(bandId, onComplete) {
+ var callCount = 0;
+ var totalInvitations = 0;
+ $('#selected-band-invitees .invitation').each(function(index, invitation) {
+ callCount++;
+ totalInvitations++;
+ var userId = $(invitation).attr('user-id');
+ rest.createBandInvitation(bandId, userId)
+ .done(function(response) {
+ callCount--;
+ }).fail(app.ajaxError);
+ });
+ function checker() {
+ if (callCount === 0) {
+ onComplete();
+ } else {
+ context.setTimeout(checker, 10);
+ }
+ }
+ checker();
+ return totalInvitations;
}
function beforeShow(data) {
@@ -49,6 +115,12 @@
}
function afterShow(data) {
+ loadFriends();
+ loadGenres();
+ loadCountries();
+ }
+
+ function loadFriends() {
$.ajax({
type: "GET",
url: "/api/users/" + context.JK.currentUserId + "/friends",
@@ -75,6 +147,32 @@
$(".autocomplete").width("150px");
}
+ function loadGenres() {
+ rest.getGenres().done(function(response) {
+ $.each(response, function(index, val) {
+ var genreTemplate = $('#template-band-setup-genres').html();
+ var genreHtml = context.JK.fillTemplate(genreTemplate, {
+ id: val.id,
+ description: val.description
+ });
+
+ $('#band-genres').append(genreHtml);
+ });
+ });
+ }
+
+ function loadCountries() {
+
+ }
+
+ function loadStates(country) {
+
+ }
+
+ function loadCities(state) {
+
+ }
+
function friendSelectorCallback(newSelections) {
var keys = Object.keys(newSelections);
for (var i=0; i < keys.length; i++) {
@@ -133,6 +231,18 @@
$('#btn-band-choose-friends').click(function() {
friendSelectorDialog.showDialog(selectedFriendIds);
});
+
+ $('#band-country').on('change', function(evt) {
+ evt.stopPropagation();
+ loadStates(this.value);
+ return false;
+ });
+
+ $('#band-state').on('change', function(evt) {
+ evt.stopPropagation();
+ loadCities(this.value);
+ return false;
+ });
}
function initialize(friendSelectorDialogInstance) {
diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js
index 0d698c4b6..1768dfd4d 100644
--- a/web/app/assets/javascripts/jam_rest.js
+++ b/web/app/assets/javascripts/jam_rest.js
@@ -66,6 +66,36 @@
});
}
+ function createBandInvitation(bandId, userId) {
+ var bandInvitation = {
+ band_id: bandId,
+ user_id: userId
+ };
+
+ return $.ajax({
+ type: "POST",
+ dataType: "json",
+ url: '/api/bands/' + bandId + "/invitations",
+ contentType: 'application/json',
+ processData: false,
+ data: JSON.stringify(bandInvitation)
+ });
+ }
+
+ function updateBandInvitation(bandId) {
+ var bandInvitation = {};
+ bandInvitation.band_id = bandId;
+ bandInvitation.user_id = userId;
+ return $.ajax({
+ type: "POST",
+ dataType: "json",
+ url: '/api/bands/' + bandId + "/invitations",
+ contentType: 'application/json',
+ processData: false,
+ data: JSON.stringify(bandInvitation)
+ });
+ }
+
function getSession(id) {
var url = "/api/sessions/" + id;
return $.ajax({
@@ -131,6 +161,13 @@
});
}
+ function getGenres(options) {
+ return $.ajax('/api/genres', {
+ data: { },
+ dataType: 'json'
+ });
+ }
+
function updateAvatar(options) {
var id = getId(options);
@@ -396,6 +433,7 @@
this.getCountries = getCountries;
this.getIsps = getIsps;
this.getInstruments = getInstruments;
+ this.getGenres = getGenres;
this.updateAvatar = updateAvatar;
this.deleteAvatar = deleteAvatar;
this.getFilepickerPolicy = getFilepickerPolicy;
@@ -418,6 +456,10 @@
this.stopRecording = stopRecording;
this.getRecording = getRecording;
this.putTrackSyncChange = putTrackSyncChange;
+ this.createBand = createBand;
+ this.updateBand = updateBand;
+ this.createBandInvitation = createBandInvitation;
+ this.updateBandInvitation = updateBandInvitation;
return this;
};
diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js
index 82c03e0cf..fb16c59bb 100644
--- a/web/app/assets/javascripts/profile.js
+++ b/web/app/assets/javascripts/profile.js
@@ -490,6 +490,8 @@
}
else {
+ addMoreBandsLink();
+
$.each(response, function(index, val) {
// build band member HTML
@@ -540,16 +542,20 @@
configureBandFollowingButton(following, val.id);
});
- if (context.JK.currentUserId === userId) {
- var moreBandsHtml = $('#template-more-bands').html();
- $("#profile-bands").append(moreBandsHtml);
- }
+ addMoreBandsLink();
}
},
error: app.ajaxError
});
}
+ function addMoreBandsLink() {
+ if (context.JK.currentUserId === userId) {
+ var moreBandsHtml = $('#template-more-bands').html();
+ $("#profile-bands").append(moreBandsHtml);
+ }
+ }
+
function formatGenres(genres) {
var formattedGenres = '';
if (genres) {
diff --git a/web/app/controllers/api_bands_controller.rb b/web/app/controllers/api_bands_controller.rb
index d01bff216..ad75323da 100644
--- a/web/app/controllers/api_bands_controller.rb
+++ b/web/app/controllers/api_bands_controller.rb
@@ -153,7 +153,7 @@ class ApiBandsController < ApiController
end
def invitation_create
- @invitation = BandInvitation.save(params[:invitation_id],
+ @invitation = BandInvitation.save(nil,
params[:id],
params[:user_id],
current_user.id,
diff --git a/web/app/views/clients/_bandProfile.html.erb b/web/app/views/clients/_bandProfile.html.erb
index 6228fd0a1..ef791def1 100644
--- a/web/app/views/clients/_bandProfile.html.erb
+++ b/web/app/views/clients/_bandProfile.html.erb
@@ -90,7 +90,7 @@
{biography}
PROFILE
FOLLOW
- CONNECT
+
diff --git a/web/app/views/clients/_band_setup.html.erb b/web/app/views/clients/_band_setup.html.erb
index c29920c29..581178ef5 100644
--- a/web/app/views/clients/_band_setup.html.erb
+++ b/web/app/views/clients/_band_setup.html.erb
@@ -29,31 +29,37 @@