2013-10-25 08:52:10 -07:00
|
|
|
|
(function ($, window, document) {
|
|
|
|
|
|
|
|
|
|
function loadUser(page, user, loggedInUser, allCulturesPromise) {
|
|
|
|
|
|
|
|
|
|
Dashboard.setPageTitle(user.Name);
|
|
|
|
|
|
|
|
|
|
allCulturesPromise.done(function (allCultures) {
|
|
|
|
|
|
2013-12-28 09:58:13 -07:00
|
|
|
|
Dashboard.populateLanguages($('#selectAudioLanguage', page), allCultures);
|
|
|
|
|
Dashboard.populateLanguages($('#selectSubtitleLanguage', page), allCultures);
|
2013-10-25 08:52:10 -07:00
|
|
|
|
|
|
|
|
|
$('#selectAudioLanguage', page).val(user.Configuration.AudioLanguagePreference || "").selectmenu("refresh");
|
|
|
|
|
$('#selectSubtitleLanguage', page).val(user.Configuration.SubtitleLanguagePreference || "").selectmenu("refresh");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#chkForcedSubtitlesOnly', page).checked(user.Configuration.UseForcedSubtitlesOnly || false).checkboxradio("refresh");
|
2013-10-26 15:01:21 -07:00
|
|
|
|
$('#chkDisplayMissingEpisodes', page).checked(user.Configuration.DisplayMissingEpisodes || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkDisplayUnairedEpisodes', page).checked(user.Configuration.DisplayUnairedEpisodes || false).checkboxradio("refresh");
|
2013-10-25 08:52:10 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSaveComplete(page) {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
|
|
|
|
Dashboard.validateCurrentUser(page);
|
|
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
|
Dashboard.alert("Settings saved.");
|
|
|
|
|
} else {
|
|
|
|
|
Dashboard.navigate("userprofiles.html");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveUser(user, page) {
|
|
|
|
|
|
|
|
|
|
user.Configuration.AudioLanguagePreference = $('#selectAudioLanguage', page).val();
|
|
|
|
|
user.Configuration.SubtitleLanguagePreference = $('#selectSubtitleLanguage', page).val();
|
|
|
|
|
user.Configuration.UseForcedSubtitlesOnly = $('#chkForcedSubtitlesOnly', page).checked();
|
2013-10-26 15:01:21 -07:00
|
|
|
|
user.Configuration.DisplayMissingEpisodes = $('#chkDisplayMissingEpisodes', page).checked();
|
|
|
|
|
user.Configuration.DisplayUnairedEpisodes = $('#chkDisplayUnairedEpisodes', page).checked();
|
2013-10-25 08:52:10 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.updateUser(user).done(function () {
|
|
|
|
|
onSaveComplete(page);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function userSettingsPage() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.onSubmit = function () {
|
|
|
|
|
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
|
|
|
|
ApiClient.getUser(userId).done(function (result) {
|
|
|
|
|
saveUser(result, page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.UserSettingsPage = new userSettingsPage();
|
|
|
|
|
|
|
|
|
|
$(document).on('pagebeforeshow', "#userSettingsPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
Dashboard.getCurrentUser().done(function (loggedInUser) {
|
|
|
|
|
|
|
|
|
|
if (loggedInUser.Configuration.IsAdministrator) {
|
2013-12-26 08:40:38 -07:00
|
|
|
|
$('#lnkParentalControl', page).show();
|
2013-10-25 08:52:10 -07:00
|
|
|
|
} else {
|
2013-12-26 08:40:38 -07:00
|
|
|
|
$('#lnkParentalControl', page).hide();
|
2013-10-25 08:52:10 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#userSettingsPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
|
|
|
|
var promise1;
|
|
|
|
|
|
|
|
|
|
if (!userId) {
|
|
|
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [{
|
|
|
|
|
Configuration: {}
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
promise1 = deferred.promise();
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
promise1 = ApiClient.getUser(userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var promise2 = Dashboard.getCurrentUser();
|
|
|
|
|
|
|
|
|
|
var allCulturesPromise = ApiClient.getCultures();
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
|
|
|
|
loadUser(page, response1[0] || response1, response2[0], allCulturesPromise);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#userSettingsForm input:first").focus();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, window, document);
|