91 lines
3.5 KiB
JavaScript
91 lines
3.5 KiB
JavaScript
/**
|
|
* Javascript for the session settings dialog.
|
|
*/
|
|
(function(context,$) {
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.SessionSettingsDialog = function(app, sessionScreen) {
|
|
var logger = context.JK.logger;
|
|
var $dialog;
|
|
var rest = new JK.Rest(app);
|
|
|
|
function beforeShow(data) {
|
|
context.JK.GenreSelectorHelper.render('#session-settings-genre');
|
|
$dialog = $('[layout-id="session-settings"]');
|
|
var currentSession = sessionScreen.getCurrentSession();
|
|
context.JK.GenreSelectorHelper.setSelectedGenres('#session-settings-genre', currentSession.genres);
|
|
// dynamic object binding to form.
|
|
// TODO: Generalize, test and bundle with formToObject
|
|
var skip = [
|
|
'participants', // has its own API
|
|
'invitations', // has its own API
|
|
'join_requests', // has its own API
|
|
'genres' // handled specifically
|
|
];
|
|
$.each(_.keys(currentSession), function(index,propName) {
|
|
if (context._.contains(skip, propName)) {
|
|
logger.debug("Skipping " + propName);
|
|
return true; // "continue"
|
|
}
|
|
var inputSelector = '[name="' + propName + '"]';
|
|
$input = $(inputSelector, $dialog);
|
|
logger.debug('Found ' + $input.length + ' inputs for selector, ' + inputSelector);
|
|
var desiredValue = null;
|
|
if ($.isArray(currentSession[propName])) {
|
|
desiredValue = currentSession[propName].join(',');
|
|
} else {
|
|
desiredValue = currentSession[propName];
|
|
}
|
|
|
|
logger.debug("setting to " + desiredValue);
|
|
$input.val(desiredValue).change();
|
|
});
|
|
|
|
}
|
|
|
|
function updateFanChatDisabled(evt) {
|
|
logger.debug('updateFanChatDisabled');
|
|
$dialog = $('[layout-id="session-settings"]');
|
|
var hasFanAccess = $('select[name="fan_access"]', $dialog).val(); // string
|
|
hasFanAccess = context.JK.stringToBool(hasFanAccess);
|
|
logger.debug('hasFanAccess? ' + hasFanAccess);
|
|
if (hasFanAccess) {
|
|
$('input[name="fan_chat"]', $dialog).removeAttr("disabled");
|
|
} else {
|
|
$('input[name="fan_chat"]', $dialog).attr("disabled", "disabled");
|
|
}
|
|
}
|
|
|
|
function saveSettings(evt) {
|
|
var newSessionInfo = $('#session-settings-dialog').formToObject();
|
|
var id = newSessionInfo.id;
|
|
delete newSessionInfo.id;
|
|
if (typeof newSessionInfo.genres === "string") {
|
|
newSessionInfo.genres = [newSessionInfo.genres];
|
|
}
|
|
var toSend = { music_session: newSessionInfo };
|
|
rest.updateSession(id, toSend, settingsSaved);
|
|
}
|
|
|
|
function settingsSaved(response) {
|
|
// No response returned from this call. 204.
|
|
app.layout.closeDialog('session-settings');
|
|
}
|
|
|
|
function events() {
|
|
$('#session-settings-dialog-submit').on('click', saveSettings);
|
|
$('#session-settings-dialog select[name="fan_access"]').on('change', updateFanChatDisabled);
|
|
}
|
|
|
|
this.initialize = function() {
|
|
events();
|
|
var dialogBindings = {
|
|
'beforeShow': beforeShow
|
|
};
|
|
app.bindDialog('session-settings', dialogBindings);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
})(window,jQuery); |