235 lines
7.1 KiB
JavaScript
235 lines
7.1 KiB
JavaScript
(function (context, $) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.AccountAudioProfile = function (app) {
|
|
|
|
var EVENTS = context.JK.EVENTS;
|
|
var gearUtils = context.JK.GearUtils;
|
|
var logger = context.JK.logger;
|
|
var rest = context.JK.Rest();
|
|
var self = this;
|
|
var userId;
|
|
|
|
function beforeShow(data) {
|
|
userId = data.id;
|
|
|
|
registerFtueSuccess();
|
|
}
|
|
|
|
function afterShow(data) {
|
|
resetForm();
|
|
renderAudioProfileScreen();
|
|
}
|
|
|
|
function beforeHide() {
|
|
unregisterFtueSuccess();
|
|
}
|
|
|
|
function renderAudioProfileScreen() {
|
|
if (!gon.isNativeClient) {
|
|
// app.layout.showDialog('launch-app-dialog', {d1: 'gear'});
|
|
context.JK.guardAgainstBrowser(app, {d1: 'gear'});
|
|
}
|
|
else {
|
|
populateAccountAudio()
|
|
}
|
|
}
|
|
|
|
function populateAccountAudio() {
|
|
var profiles = gearUtils.getProfiles();
|
|
|
|
context._.each(profiles, function(profile) {
|
|
profile.active_text = profile.current ? '(active)' : '';
|
|
});
|
|
|
|
// If you are in the FTUE, and you close the client and/or it crashes
|
|
// then you will have 'FTUE' (incomplete) profiles. This is the only time
|
|
// the user might see them, so we clean them before they get to see it
|
|
var cleansedProfiles = [];
|
|
context._.each(profiles, function(profile) {
|
|
if(profile.id.indexOf('FTUE') == 0) {
|
|
context.jamClient.TrackDeleteProfile(profile.id);
|
|
}
|
|
else {
|
|
cleansedProfiles.push(profile)
|
|
}
|
|
});
|
|
|
|
var template = context._.template($('#template-account-audio').html(), {is_admin: context.JK.currentUserAdmin, profiles: cleansedProfiles}, {variable: 'data'});
|
|
|
|
appendAudio(template);
|
|
}
|
|
|
|
function appendAudio(template) {
|
|
$('#account-audio-content-scroller table tbody').replaceWith(template);
|
|
}
|
|
|
|
function resetForm() {
|
|
}
|
|
|
|
function handleDeleteAudioProfile(audioProfileId) {
|
|
logger.debug("deleting audio profile: " + audioProfileId);
|
|
|
|
context.jamClient.TrackDeleteProfile(audioProfileId);
|
|
|
|
// redraw after deletion of profile
|
|
populateAccountAudio();
|
|
}
|
|
|
|
function handleLoopbackAudioProfile(audioProfileId) {
|
|
|
|
if(audioProfileId != context.jamClient.FTUEGetMusicProfileName()) {
|
|
var result = context.jamClient.FTUELoadAudioConfiguration(audioProfileId);
|
|
|
|
if(!result) {
|
|
logger.error("unable to activate audio configuration: " + audioProfileId);
|
|
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + audioProfileId);
|
|
}
|
|
else {
|
|
// redraw after activation of profile
|
|
populateAccountAudio();
|
|
}
|
|
}
|
|
|
|
app.layout.showDialog('loopback-wizard');
|
|
}
|
|
|
|
function handleConfigureAudioProfile(audioProfileId) {
|
|
|
|
if(audioProfileId != context.jamClient.FTUEGetMusicProfileName()) {
|
|
var result = context.jamClient.FTUELoadAudioConfiguration(audioProfileId);
|
|
|
|
if(!result) {
|
|
logger.error("unable to activate audio configuration: " + audioProfileId);
|
|
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + audioProfileId);
|
|
}
|
|
else {
|
|
// redraw after activation of profile
|
|
populateAccountAudio();
|
|
}
|
|
}
|
|
|
|
app.layout.showDialog('configure-tracks')
|
|
.one(EVENTS.DIALOG_CLOSED, populateAccountAudio)
|
|
}
|
|
|
|
function handleActivateAudioProfile(audioProfileId) {
|
|
logger.debug("activating audio profile: " + audioProfileId);
|
|
|
|
if(audioProfileId == context.jamClient.FTUEGetMusicProfileName()) {
|
|
context.JK.Banner.showAlert("This profile is already active.");
|
|
return;
|
|
}
|
|
|
|
var result = context.jamClient.FTUELoadAudioConfiguration(audioProfileId);
|
|
|
|
if(!result) {
|
|
logger.error("unable to activate audio configuration: " + audioProfileId);
|
|
context.JK.alertSupportedNeeded("Unable to activate audio configuration for profile named: " + audioProfileId);
|
|
}
|
|
|
|
// redraw after activation of profile
|
|
populateAccountAudio();
|
|
}
|
|
function handleStartAudioQualification() {
|
|
|
|
if(true) {
|
|
app.afterFtue = function() { populateAccountAudio() };
|
|
app.cancelFtue = function() { populateAccountAudio() };
|
|
app.layout.startNewFtue();
|
|
}
|
|
else {
|
|
app.setWizardStep(1);
|
|
app.layout.showDialog('ftue');
|
|
}
|
|
}
|
|
|
|
function registerFtueSuccess() {
|
|
$('div[layout-id=ftue]').on("ftue_success", ftueSuccessHandler);
|
|
}
|
|
|
|
function unregisterFtueSuccess() {
|
|
$('div[layout-id=ftue]').off("ftue_success", ftueSuccessHandler);
|
|
}
|
|
|
|
function ftueSuccessHandler() {
|
|
populateAccountAudio();
|
|
}
|
|
|
|
// events for main screen
|
|
function events() {
|
|
// wire up main panel clicks
|
|
var $root = $('#account-audio-content-scroller');
|
|
$root.on('click', 'a[data-purpose=delete-audio-profile]', function (evt) {
|
|
evt.stopPropagation();
|
|
handleDeleteAudioProfile($(this).attr('data-id'));
|
|
return false;
|
|
});
|
|
|
|
$root.on('click', 'a[data-purpose=activate-audio-profile]', function (evt) {
|
|
evt.stopPropagation();
|
|
var $btn = $(this);
|
|
var status = $btn.closest('tr').attr('data-status');
|
|
if(status == "good") {
|
|
handleActivateAudioProfile($btn.attr('data-id'));
|
|
}
|
|
else {
|
|
context.JK.Banner.showAlert("Unable to activate this profile. Please verify that the devices associated are connected.");
|
|
}
|
|
return false;
|
|
});
|
|
|
|
|
|
$root.on('click', 'a[data-purpose=loopback-audio-profile]', function (evt) {
|
|
evt.stopPropagation();
|
|
var $btn = $(this);
|
|
var status = $btn.closest('tr').attr('data-status');
|
|
if(status == "good") {
|
|
handleLoopbackAudioProfile($btn.attr('data-id'));
|
|
}
|
|
else {
|
|
context.JK.Banner.showAlert("Unable to loopback test this profile. Please verify that the devices associated are connected.");
|
|
}
|
|
return false;
|
|
});
|
|
|
|
$root.on('click', 'a[data-purpose=configure-audio-profile]', function (evt) {
|
|
evt.stopPropagation();
|
|
var $btn = $(this);
|
|
var status = $btn.closest('tr').attr('data-status');
|
|
if(status == "good") {
|
|
handleConfigureAudioProfile($btn.attr('data-id'));
|
|
}
|
|
else {
|
|
context.JK.Banner.showAlert("Unable to configure this profile. Please verify that the devices associated are connected.");
|
|
}
|
|
return false;
|
|
});
|
|
|
|
|
|
$root.on('click', 'a[data-purpose=add-profile]', function (evt) {
|
|
evt.stopPropagation();
|
|
handleStartAudioQualification();
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function initialize() {
|
|
var screenBindings = {
|
|
'beforeShow': beforeShow,
|
|
'afterShow': afterShow
|
|
};
|
|
app.bindScreen('account/audio', screenBindings);
|
|
events();
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
this.beforeShow = beforeShow;
|
|
this.afterShow = afterShow;
|
|
this.beforeHide = beforeHide;
|
|
return this;
|
|
};
|
|
|
|
})(window, jQuery); |