VRFS-291 Add Track dialog

This commit is contained in:
Brian Smith 2013-05-22 07:48:37 -04:00
parent 9b7f418fdf
commit e4ebbc4ac4
6 changed files with 60 additions and 31 deletions

View File

@ -96,13 +96,11 @@
// load Unused Inputs
context.JK.loadOptions($('#template-option').html(), $('#add-track2-unused'), unusedAudioInputChannels, "device_id", "name", -1);
// load Track 2 config details if necessary
// load Track 2 Input(s)
context.JK.loadOptions($('#template-option').html(), $('#add-track2-input'), track2AudioInputChannels, "device_id", "name", -1);
// load Track 2 Instrument
var current_instrument = context.jamClient.TrackGetInstrument(2);
context.JK.loadOptions($('#template-option').html(), $('#add-track2-instrument'), instrument_array, "id", "description", current_instrument);
context.JK.loadOptions($('#template-option').html(), $('#add-track2-instrument'), instrument_array, "id", "description", -1);
}
function initDialogData() {
@ -133,11 +131,11 @@
}
function saveSettings() {
if (!validateAudioSettings(false)) {
if (!validateSettings()) {
return;
}
saveAudioSettings();
saveTrack();
$('div[layout-id="add-track"]').hide();
@ -147,7 +145,7 @@
sessionModel.refreshCurrentSession();
}
function saveAudioSettings() {
function saveTrack() {
// TRACK 2 INPUTS
$("#add-track2-input > option").each(function() {
logger.debug("Saving track 2 input = " + this.value);
@ -155,21 +153,26 @@
});
// TRACK 2 INSTRUMENT
instrumentVal = $('#add-track2-instrument').val();
instrumentText = $('#add-track2-instrument > option:selected').text().toLowerCase();
var instrumentVal = $('#add-track2-instrument').val();
var instrumentText = $('#add-track2-instrument > option:selected').text().toLowerCase();
logger.debug("Saving track 2 instrument = " + instrumentVal);
context.jamClient.TrackSetInstrument(ASSIGNMENT.TRACK2, instrumentVal);
// UPDATE SERVER
logger.debug("Updating track " + myTracks[1].trackId + " with instrument " + instrumentText);
logger.debug("Adding track with instrument " + instrumentText);
var data = {};
// use the first track's connection_id (not sure why we need this on the track data model)
logger.debug("myTracks[0].connection_id=" + myTracks[0].connection_id);
data.connection_id = myTracks[0].connection_id;
data.instrument_id = instrumentText;
sessionModel.updateTrack(myTracks[1].trackId, sessionId, data);
data.sound = "stereo";
sessionModel.addTrack(sessionId, data);
context.jamClient.TrackSaveAssignments();
}
function validateAudioSettings() {
function validateSettings() {
var isValid = true;
var noTrackErrMsg = 'You must assign at least one input port to each of your tracks. Please update your settings to correct this. If you want to delete a track, please return to the session screen and delete the track by clicking the "x" box in the upper right-hand corner of the track.';
var noInstrumentErrMsg = 'You must specify what instrument is being played for each track. Please update your settings to correct this.';
@ -182,7 +185,7 @@
isValid = false;
}
if (isValid && $('#add-track2-instrument > option').size() === 0) {
if (isValid && $('#add-track2-instrument > option:selected').length === 0) {
errMsg = noInstrumentErrMsg;
isValid = false;
}
@ -190,7 +193,6 @@
if (!isValid) {
context.JK.showErrorDialog(app, errMsg);
}
return isValid;
}

View File

@ -636,7 +636,7 @@
}
if (isValid) {
if ($('#track1-instrument > option').size() === 0) {
if ($('#track1-instrument > option:selected').length === 0) {
errMsg = noInstrumentErrMsg;
isValid = false;
}
@ -649,7 +649,7 @@
isValid = false;
}
if (isValid && $('#track2-instrument > option').size() === 0) {
if (isValid && $('#track2-instrument > option:selected').length === 0) {
errMsg = noInstrumentErrMsg;
isValid = false;
}

View File

@ -226,6 +226,7 @@
// Default trackData to participant + no Mixer state.
var trackData = {
trackId: track.id,
connection_id: track.connection_id,
clientId: participant.client_id,
name: name,
instrumentIcon: instrumentIcon,
@ -449,21 +450,7 @@
function deleteTrack(evt) {
var trackId = $(evt.currentTarget).attr("track-id");
if (trackId) {
$.ajax({
type: "DELETE",
url: "/api/sessions/" + sessionId + "/tracks/" + trackId,
success: function(response) {
// TODO: if in recording, more cleanup to do???
// refresh Session screen
sessionModel.refreshCurrentSession();
},
error: function(jqXHR, textStatus, errorThrown) {
logger.error("Error deleting track " + trackId);
}
});
}
sessionModel.deleteTrack(trackId);
}
function _toggleVisualMuteControl($control, muting) {

View File

@ -210,6 +210,23 @@
return foundParticipant;
}
function addTrack(sessionId, data) {
logger.debug("track data = " + JSON.stringify(data));
var url = "/api/sessions/" + sessionId + "/tracks";
$.ajax({
type: "POST",
dataType: "json",
contentType: 'application/json',
url: url,
data: JSON.stringify(data),
processData:false,
success: function(response) {
logger.debug("Successfully added track (" + JSON.stringify(data) + ")");
},
error: ajaxError
});
}
function updateTrack(sessionId, trackId, data) {
var url = "/api/sessions/" + sessionId + "/tracks/" + trackId;
$.ajax({
@ -226,6 +243,24 @@
});
}
function deleteTrack(trackId) {
if (trackId) {
$.ajax({
type: "DELETE",
url: "/api/sessions/" + sessionId + "/tracks/" + trackId,
success: function(response) {
// TODO: if in recording, more cleanup to do???
// refresh Session screen
refreshCurrentSession();
},
error: function(jqXHR, textStatus, errorThrown) {
logger.error("Error deleting track " + trackId);
}
});
}
}
/**
* Make the server calls to join the current user to
* the session provided.
@ -297,7 +332,9 @@
this.refreshCurrentSession = refreshCurrentSession;
this.subscribe = subscribe;
this.participantForClientId = participantForClientId;
this.addTrack = addTrack;
this.updateTrack = updateTrack;
this.deleteTrack = deleteTrack;
};
})(window,jQuery);

View File

@ -131,10 +131,13 @@ class ApiMusicSessionsController < ApiController
end
def track_create
puts "TRACK CONNECTION ID = #{params[:connection_id]}"
@track = Track.save(nil,
params[:connection_id],
params[:instrument_id],
params[:sound])
puts "TRACK CONNECTION ID = #{@track.connection_id}"
respond_with @track, responder: ApiResponder, :status => 201, :location => api_session_track_detail_url(@track.connection.music_session, @track)
end

View File

@ -15,7 +15,7 @@ child(:connections => :participants) {
end
child(:tracks => :tracks) {
attributes :id, :instrument_id, :sound
attributes :id, :connection_id, :instrument_id, :sound
}
}