");
isValid = false;
}
else {
$('#divGenre').removeClass("error");
}
// if (genres.length > MAX_GENRES) {
// errors.push(['#genre-list', "No more than " + MAX_GENRES + "genres are allowed."]);
// }
var intellectualPropertyChecked = $('#intellectual-property').is(':checked');
if (!intellectualPropertyChecked) {
$('#divIntellectualProperty .error-text').remove();
$('#divIntellectualProperty').addClass("error");
$('#divTerms').after("
You must accept the JamKazam Terms of Service.
");
isValid = false;
}
else {
$('#divIntellectualProperty').removeClass("error");
}
return isValid;
}
function submitForm(evt) {
evt.preventDefault();
var isValid = validateForm();
if (!isValid) {
// app.notify({
// title: "Validation Errors",
// text: JSON.stringify(formErrors)
// });
return false;
}
var data = {};
data.client_id = app.clientId;
data.description = $('#description').val();
data.as_musician = true;
data.legal_terms = true; // this overrides the default of 'on', which isn't satisfying our concept of boolean
data.intellectual_property = $('#intellectual-property').is(':checked');
data.genres = context.JK.GenreSelectorHelper.getSelectedGenres('#create-session-genre');
data.musician_access = $('#musician-access option:selected').val() === "true" ? true : false;
data.approval_required = $("input[name='musician-access-option']:checked").val() === "true" ? true : false;
data.fan_access = $('#fan-access option:selected').val() === "true" ? true : false;
data.fan_chat = $("input[name='fan-chat-option']:checked").val() === "true" ? true : false;
if ($('#band-list option:selected').val() !== '') {
data.band = $('#band-list option:selected').val();
}
// 1. If no previous session data, a single stereo track with the
// top instrument in the user's profile.
// 2. Otherwise, use the tracks from the last created session.
// Defaulting to 1st instrument in profile always at the moment.
data.tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
var jsonData = JSON.stringify(data);
console.log("session data=" + jsonData);
$('#btn-create-session').addClass('button-disabled');
$('#btn-create-session').bind('click', false);
var url = "/api/sessions";
$.ajax({
type: "POST",
dataType: "json",
contentType: 'application/json',
url: url,
processData:false,
data: jsonData,
success: function(response) {
var newSessionId = response.id;
createInvitations(newSessionId, function() {
context.location = '#/session/' + newSessionId;
});
// Re-loading the session settings will cause the form to reset with the right stuff in it.
// This is an extra xhr call, but it keeps things to a single codepath
loadSessionSettings();
$('#btn-create-session').removeClass('button-disabled');
$('#btn-create-session').unbind('click', false);
},
error: function() {
app.ajaxError(arguments);
$('#btn-create-session').removeClass('button-disabled');
$('#btn-create-session').unbind('click', false);
}
});
return false;
}
function createInvitations(sessionId, onComplete) {
var callCount = 0;
$('#selected-friends .invitation').each(function(index, invitation) {
callCount++;
var invite_id = $(invitation).attr('user-id');
var invite = {
music_session: sessionId,
receiver: invite_id
};
$.ajax({
type: "POST",
url: "/api/invitations",
data: invite
}).done(function(response) {
callCount--;
}).fail(app.ajaxError);
});
// TODO - this is the second time I've used this pattern.
// refactor to make a common utility for this.
function checker() {
if (callCount === 0) {
onComplete();
} else {
context.setTimeout(checker, 10);
}
}
checker();
}
function events() {
$('#btn-create-session').on("click", submitForm);
$('#selected-friends').on("click", ".invitation a", removeInvitation);
$('#musician-access').change(toggleMusicianAccess);
$('#fan-access').change(toggleFanAccess);
$('#btn-choose-friends').click(function() {
friendSelectorDialog.showDialog(selectedFriendIds);
});
$('#btn-email-invitation').click(function() {
$('#invitation-textarea-container').show();
$('#invitation-checkbox-container').hide();
$('#btn-send-invitation').show();
$('#btn-next-invitation').hide();
invitationDialog.showDialog();
});
$('#btn-gmail-invitation').click(function() {
$('#invitation-textarea-container').hide();
$('#invitation-checkbox-container').show();
$('#btn-send-invitation').hide();
$('#btn-next-invitation').show();
invitationDialog.showDialog();
$('#invitation-checkboxes').html('