jellyfin-web/dashboard-ui/scripts/mypreferenceslanguages.js

146 lines
5.1 KiB
JavaScript
Raw Normal View History

2014-05-21 09:45:42 -07:00
(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");
2014-10-01 17:28:16 -07:00
$('#chkEnableCinemaMode', page).checked(user.Configuration.EnableCinemaMode || false).checkboxradio("refresh");
2014-05-21 09:45:42 -07:00
2015-07-03 10:55:29 -07:00
$('#chkEnableChromecastAc3', page).checked(AppSettings.enableChromecastAc3()).checkboxradio("refresh");
$('#chkExternalVideoPlayer', page).checked(AppSettings.enableExternalPlayers()).checkboxradio("refresh");
2015-07-22 22:25:55 -07:00
var bitrateOptions = MediaPlayer.getVideoQualityOptions().map(function (i) {
return '<option value="' + i.bitrate + '">' + i.name + '</option>';
}).join('');
$('#selectMaxBitrate', page).html(bitrateOptions).val(AppSettings.maxStreamingBitrate()).selectmenu("refresh");
2015-07-03 10:55:29 -07:00
$('#selectMaxChromecastBitrate', page).val(AppSettings.maxChromecastBitrate()).selectmenu("refresh");
2014-05-21 09:45:42 -07:00
Dashboard.hideLoadingMsg();
}
2014-10-01 17:28:16 -07:00
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();
}
});
}
2014-05-21 09:45:42 -07:00
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();
2014-10-01 17:28:16 -07:00
user.Configuration.EnableCinemaMode = $('#chkEnableCinemaMode', page).checked();
2014-05-21 09:45:42 -07:00
2014-12-18 21:20:07 -07:00
ApiClient.updateUserConfiguration(user.Id, user.Configuration).done(function () {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('SettingsSaved'));
2015-07-08 09:10:34 -07:00
}).always(function () {
Dashboard.hideLoadingMsg();
2014-05-21 09:45:42 -07:00
});
}
function onSubmit() {
var page = $(this).parents('.page');
Dashboard.showLoadingMsg();
2015-07-03 10:55:29 -07:00
AppSettings.enableExternalPlayers($('#chkExternalVideoPlayer', page).checked());
AppSettings.maxStreamingBitrate($('#selectMaxBitrate', page).val());
AppSettings.maxChromecastBitrate($('#selectMaxChromecastBitrate', page).val());
AppSettings.enableChromecastAc3($('#chkEnableChromecastAc3', page).checked());
2014-05-21 09:45:42 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
ApiClient.getUser(userId).done(function (result) {
saveUser(page, result);
});
// Disable default form submission
return false;
}
2015-05-27 22:51:48 -07:00
$(document).on('pageinitdepends', "#languagePreferencesPage", function () {
2014-05-21 09:45:42 -07:00
var page = this;
2014-05-21 11:38:12 -07:00
$('#selectSubtitlePlaybackMode', page).on('change', function () {
$('.subtitlesHelp', page).hide();
$('.subtitles' + this.value + 'Help', page).show();
});
2015-05-27 22:51:48 -07:00
$('.languagePreferencesForm').off('submit', onSubmit).on('submit', onSubmit);
}).on('pageshowready', "#languagePreferencesPage", function () {
2014-05-21 09:45:42 -07:00
var page = this;
2015-07-03 10:55:29 -07:00
if (AppInfo.hasKnownExternalPlayerSupport) {
$('.labelNativeExternalPlayers', page).show();
$('.labelGenericExternalPlayers', page).hide();
} else {
$('.labelGenericExternalPlayers', page).show();
$('.labelNativeExternalPlayers', page).hide();
}
2014-10-01 17:28:16 -07:00
loadPage(page);
2014-05-21 09:45:42 -07:00
});
})(jQuery, window, document);