VRFS-689 band creation works (minus avatar, form validations, and band invite notifications)
This commit is contained in:
parent
205d90e25b
commit
ff4c25285e
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
{biography}<br /><br />
|
||||
<a class="button-orange smallbutton m0" href="{profile_url}">PROFILE</a>
|
||||
<a id="btn-follow-member" class="button-orange smallbutton m0">FOLLOW</a>
|
||||
<a id="btn-friend-member" class="button-orange smallbutton m0">CONNECT</a>
|
||||
<a id="btn-friend-member" style="display:none;" class="button-orange smallbutton m0">CONNECT</a>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -29,31 +29,37 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td valign="middle" width="33%">Band Name:<br />
|
||||
<input id="band-name" type="text" value="" class="w80"><br />
|
||||
<input id="band-name" type="text" maxlength="1024" value="" class="w80"><br />
|
||||
</td>
|
||||
<td valign="middle" width="33%">Web Site:<br />
|
||||
<input id="web-site" type="text" value="" class="w80">
|
||||
<input id="band-website" type="text" maxlength="4000" value="" class="w80">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="middle">Country:<br />
|
||||
<select class="w80"><option value="US">United States</option></select><br /><br />
|
||||
<select id="band-country" class="w80">
|
||||
<option value="US">United States</option>
|
||||
</select><br /><br />
|
||||
</td>
|
||||
<td valign="middle">State/Region:<br />
|
||||
<select class="w80"><option>Texas</option></select><br /><br />
|
||||
<select id="band-state" class="w80">
|
||||
<option value="TX">TX</option>
|
||||
</select><br /><br />
|
||||
</td>
|
||||
<td valign="middle">City:<br />
|
||||
<select id="" class="w80"><option>Austin</option></select><br /><br />
|
||||
<select id="band-city" class="w80">
|
||||
<option value="Austin">Austin</option>
|
||||
</select><br /><br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">Genres:<br />
|
||||
<div class="band-setup-genres w90">
|
||||
<table id="band-setup-genres" width="100%" cellpadding="0" cellspacing="6"></table>
|
||||
<table id="band-genres" width="100%" cellpadding="10" cellspacing="6"></table>
|
||||
</div>
|
||||
</td>
|
||||
<td valign="top" colspan="2">Description / Bio:<br />
|
||||
<textarea class="band-setup-bio w90"></textarea>
|
||||
<textarea id="band-biography" class="band-setup-bio w90" maxlength="4000"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -112,7 +118,7 @@
|
|||
</div>
|
||||
|
||||
<script type="text/template" id="template-band-setup-genres">
|
||||
<tr><td><input type="checkbox" />{genre}</td></tr>
|
||||
<tr><td><input value="{id}" type="checkbox" />{description}</td></tr>
|
||||
</script>
|
||||
|
||||
<script type="text/template" id="template-band-invitation">
|
||||
|
|
|
|||
Loading…
Reference in New Issue