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

173 lines
5.8 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>";
}
2015-09-03 10:01:51 -07:00
$(select).html(html);
2014-05-21 09:45:42 -07:00
}
function loadForm(page, user, loggedInUser, allCulturesPromise) {
2015-12-14 08:43:03 -07:00
allCulturesPromise.then(function (allCultures) {
2014-05-21 09:45:42 -07:00
populateLanguages($('#selectAudioLanguage', page), allCultures);
populateLanguages($('#selectSubtitleLanguage', page), allCultures);
2015-09-03 10:01:51 -07:00
$('#selectAudioLanguage', page).val(user.Configuration.AudioLanguagePreference || "");
$('#selectSubtitleLanguage', page).val(user.Configuration.SubtitleLanguagePreference || "");
2014-05-21 09:45:42 -07:00
});
2015-09-03 10:01:51 -07:00
$('#selectSubtitlePlaybackMode', page).val(user.Configuration.SubtitleMode || "").trigger('change');
2014-05-21 09:45:42 -07:00
2015-07-28 12:42:24 -07:00
page.querySelector('.chkPlayDefaultAudioTrack').checked = user.Configuration.PlayDefaultAudioTrack || false;
2015-12-14 08:43:03 -07:00
page.querySelector('.chkEnableCinemaMode').checked = AppSettings.enableCinemaMode();
2015-07-28 12:42:24 -07:00
page.querySelector('.chkEnableChromecastAc3').checked = AppSettings.enableChromecastAc3();
page.querySelector('.chkExternalVideoPlayer').checked = AppSettings.enableExternalPlayers();
2015-07-22 22:25:55 -07:00
2015-12-30 10:02:11 -07:00
require(['qualityoptions'], function (qualityoptions) {
2015-07-22 22:25:55 -07:00
2015-12-30 10:02:11 -07:00
var bitrateOptions = qualityoptions.getVideoQualityOptions(AppSettings.maxStreamingBitrate()).map(function (i) {
2015-07-22 22:25:55 -07:00
2015-12-30 10:02:11 -07:00
return '<option value="' + i.bitrate + '">' + i.name + '</option>';
2015-07-22 22:25:55 -07:00
2015-12-30 10:02:11 -07:00
}).join('');
2015-09-05 14:15:36 -07:00
2015-12-30 10:02:11 -07:00
bitrateOptions = '<option value="">' + Globalize.translate('OptionAutomatic') + '</option>' + bitrateOptions;
2015-09-05 14:15:36 -07:00
2015-12-30 10:02:11 -07:00
$('#selectMaxBitrate', page).html(bitrateOptions);
if (AppSettings.enableAutomaticBitrateDetection()) {
$('#selectMaxBitrate', page).val('');
} else {
$('#selectMaxBitrate', page).val(AppSettings.maxStreamingBitrate());
}
2015-07-22 22:25:55 -07:00
2015-12-30 10:02:11 -07:00
$('#selectMaxChromecastBitrate', page).val(AppSettings.maxChromecastBitrate());
2015-07-03 10:55:29 -07:00
2015-12-30 10:02:11 -07:00
Dashboard.hideLoadingMsg();
});
2014-05-21 09:45:42 -07:00
}
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();
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-10-01 17:28:16 -07:00
2015-12-14 08:43:03 -07:00
loadForm(page, responses[1], responses[0], allCulturesPromise);
2014-10-01 17:28:16 -07:00
});
2015-12-14 08:43:03 -07:00
ApiClient.getNamedConfiguration("cinemamode").then(function (cinemaConfig) {
2014-10-01 17:28:16 -07:00
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();
2015-07-28 12:42:24 -07:00
user.Configuration.PlayDefaultAudioTrack = page.querySelector('.chkPlayDefaultAudioTrack').checked;
2014-05-21 09:45:42 -07:00
2015-12-14 08:43:03 -07:00
AppSettings.enableCinemaMode(page.querySelector('.chkEnableCinemaMode').checked);
ApiClient.updateUserConfiguration(user.Id, user.Configuration).then(function () {
Dashboard.hideLoadingMsg();
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('SettingsSaved'));
2015-07-08 09:10:34 -07:00
2015-12-14 08:43:03 -07:00
}, function () {
2015-07-08 09:10:34 -07:00
Dashboard.hideLoadingMsg();
2014-05-21 09:45:42 -07:00
});
}
function onSubmit() {
2015-07-29 13:31:15 -07:00
var page = $(this).parents('.page')[0];
2014-05-21 09:45:42 -07:00
Dashboard.showLoadingMsg();
2015-07-28 12:42:24 -07:00
AppSettings.enableExternalPlayers(page.querySelector('.chkExternalVideoPlayer').checked);
2015-09-05 14:15:36 -07:00
if ($('#selectMaxBitrate', page).val()) {
AppSettings.maxStreamingBitrate($('#selectMaxBitrate', page).val());
AppSettings.enableAutomaticBitrateDetection(false);
} else {
AppSettings.enableAutomaticBitrateDetection(true);
}
2015-07-03 10:55:29 -07:00
AppSettings.maxChromecastBitrate($('#selectMaxChromecastBitrate', page).val());
2015-07-29 19:08:35 -07:00
AppSettings.enableChromecastAc3(page.querySelector('.chkEnableChromecastAc3').checked);
2015-07-03 10:55:29 -07:00
2014-05-21 09:45:42 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2015-12-14 08:43:03 -07:00
ApiClient.getUser(userId).then(function (result) {
2014-05-21 09:45:42 -07:00
saveUser(page, result);
});
// Disable default form submission
return false;
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#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);
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#languagePreferencesPage", function () {
2014-05-21 09:45:42 -07:00
var page = this;
2015-12-14 08:43:03 -07:00
if (AppInfo.supportsExternalPlayers) {
$('.fldExternalPlayer', page).show();
} else {
$('.fldExternalPlayer', page).hide();
}
if (AppInfo.supportsExternalPlayerMenu) {
2015-07-03 10:55:29 -07:00
$('.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);