jellyfin-web/dashboard-ui/scripts/mypreferenceslanguages.js
2015-05-28 01:51:48 -04:00

117 lines
3.8 KiB
JavaScript

(function ($, window, document) {
function populateLanguages(select, languages) {
var html = "";
html += "<option value=''></option>";
for (var i = 0, length = languages.length; i < length; i++) {
var culture = languages[i];
html += "<option value='" + culture.ThreeLetterISOLanguageName + "'>" + culture.DisplayName + "</option>";
}
$(select).html(html).selectmenu("refresh");
}
function loadForm(page, user, loggedInUser, allCulturesPromise) {
allCulturesPromise.done(function (allCultures) {
populateLanguages($('#selectAudioLanguage', page), allCultures);
populateLanguages($('#selectSubtitleLanguage', page), allCultures);
$('#selectAudioLanguage', page).val(user.Configuration.AudioLanguagePreference || "").selectmenu("refresh");
$('#selectSubtitleLanguage', page).val(user.Configuration.SubtitleLanguagePreference || "").selectmenu("refresh");
});
$('#selectSubtitlePlaybackMode', page).val(user.Configuration.SubtitleMode || "").selectmenu("refresh").trigger('change');
$('#chkPlayDefaultAudioTrack', page).checked(user.Configuration.PlayDefaultAudioTrack || false).checkboxradio("refresh");
$('#chkEnableCinemaMode', page).checked(user.Configuration.EnableCinemaMode || false).checkboxradio("refresh");
Dashboard.hideLoadingMsg();
}
function loadPage(page) {
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
var promise1 = ApiClient.getUser(userId);
var promise2 = Dashboard.getCurrentUser();
var allCulturesPromise = ApiClient.getCultures();
$.when(promise1, promise2).done(function (response1, response2) {
loadForm(page, response1[0] || response1, response2[0], allCulturesPromise);
});
ApiClient.getNamedConfiguration("cinemamode").done(function (cinemaConfig) {
if (cinemaConfig.EnableIntrosForMovies || cinemaConfig.EnableIntrosForEpisodes) {
$('.cinemaModeOptions', page).show();
} else {
$('.cinemaModeOptions', page).hide();
}
});
}
function saveUser(page, user) {
user.Configuration.AudioLanguagePreference = $('#selectAudioLanguage', page).val();
user.Configuration.SubtitleLanguagePreference = $('#selectSubtitleLanguage', page).val();
user.Configuration.SubtitleMode = $('#selectSubtitlePlaybackMode', page).val();
user.Configuration.PlayDefaultAudioTrack = $('#chkPlayDefaultAudioTrack', page).checked();
user.Configuration.EnableCinemaMode = $('#chkEnableCinemaMode', page).checked();
ApiClient.updateUserConfiguration(user.Id, user.Configuration).done(function () {
Dashboard.alert(Globalize.translate('SettingsSaved'));
});
}
function onSubmit() {
var page = $(this).parents('.page');
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
ApiClient.getUser(userId).done(function (result) {
saveUser(page, result);
});
// Disable default form submission
return false;
}
$(document).on('pageinitdepends', "#languagePreferencesPage", function () {
var page = this;
$('#selectSubtitlePlaybackMode', page).on('change', function () {
$('.subtitlesHelp', page).hide();
$('.subtitles' + this.value + 'Help', page).show();
});
$('.languagePreferencesForm').off('submit', onSubmit).on('submit', onSubmit);
}).on('pageshowready', "#languagePreferencesPage", function () {
var page = this;
loadPage(page);
});
})(jQuery, window, document);