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

199 lines
6.6 KiB
JavaScript
Raw Normal View History

define(['appSettings', 'userSettings', 'jQuery'], function (appSettings, userSettings, $) {
2014-05-21 09:45:42 -07:00
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 || "");
2016-02-25 06:41:06 -07:00
page.querySelector('.chkEpisodeAutoPlay').checked = user.Configuration.EnableNextEpisodeAutoPlay || false;
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;
2016-03-01 21:46:10 -07:00
page.querySelector('.chkEnableCinemaMode').checked = userSettings.enableCinemaMode();
2016-02-29 23:02:03 -07:00
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
2016-02-29 23:02:03 -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);
2016-01-06 13:16:16 -07:00
$('#selectMaxChromecastBitrate', page).html(bitrateOptions);
2015-12-30 10:02:11 -07:00
2016-02-29 23:02:03 -07:00
if (appSettings.enableAutomaticBitrateDetection()) {
2015-12-30 10:02:11 -07:00
$('#selectMaxBitrate', page).val('');
} else {
2016-02-29 23:02:03 -07:00
$('#selectMaxBitrate', page).val(appSettings.maxStreamingBitrate());
2015-12-30 10:02:11 -07:00
}
2015-07-22 22:25:55 -07:00
2016-02-29 23:02:03 -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;
2016-02-25 06:41:06 -07:00
user.Configuration.EnableNextEpisodeAutoPlay = page.querySelector('.chkEpisodeAutoPlay').checked;
2016-03-01 21:46:10 -07:00
userSettings.enableCinemaMode(page.querySelector('.chkEnableCinemaMode').checked);
2015-12-14 08:43:03 -07:00
2016-01-06 13:16:16 -07:00
return ApiClient.updateUserConfiguration(user.Id, user.Configuration);
2014-05-21 09:45:42 -07:00
}
2016-01-06 13:16:16 -07:00
function save(page) {
2016-02-29 23:02:03 -07:00
appSettings.enableExternalPlayers(page.querySelector('.chkExternalVideoPlayer').checked);
2015-07-28 12:42:24 -07:00
2015-09-05 14:15:36 -07:00
if ($('#selectMaxBitrate', page).val()) {
2016-02-29 23:02:03 -07:00
appSettings.maxStreamingBitrate($('#selectMaxBitrate', page).val());
appSettings.enableAutomaticBitrateDetection(false);
2015-09-05 14:15:36 -07:00
} else {
2016-02-29 23:02:03 -07:00
appSettings.enableAutomaticBitrateDetection(true);
2015-09-05 14:15:36 -07:00
}
2016-02-29 23:02:03 -07:00
appSettings.maxChromecastBitrate($('#selectMaxChromecastBitrate', page).val());
2015-07-03 10:55:29 -07:00
2014-05-21 09:45:42 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2016-01-06 13:16:16 -07:00
if (!AppInfo.enableAutoSave) {
Dashboard.showLoadingMsg();
}
2015-12-14 08:43:03 -07:00
ApiClient.getUser(userId).then(function (result) {
2014-05-21 09:45:42 -07:00
2016-01-06 13:16:16 -07:00
saveUser(page, result).then(function () {
Dashboard.hideLoadingMsg();
if (!AppInfo.enableAutoSave) {
2016-02-24 23:38:12 -07:00
require(['toast'], function (toast) {
toast(Globalize.translate('SettingsSaved'));
});
2016-01-06 13:16:16 -07:00
}
}, function () {
Dashboard.hideLoadingMsg();
});
2014-05-21 09:45:42 -07:00
});
2016-01-06 13:16:16 -07:00
}
function onSubmit() {
var page = $(this).parents('.page')[0];
save(page);
2014-05-21 09:45:42 -07:00
// Disable default form submission
return false;
}
2016-01-06 13:16:16 -07:00
pageIdOn('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);
2016-01-06 13:16:16 -07:00
if (AppInfo.enableAutoSave) {
page.querySelector('.btnSave').classList.add('hide');
} else {
page.querySelector('.btnSave').classList.remove('hide');
}
});
2015-05-27 22:51:48 -07:00
2016-01-06 13:16:16 -07:00
pageIdOn('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
});
2016-01-06 13:16:16 -07:00
pageIdOn('pagebeforehide', "languagePreferencesPage", function () {
var page = this;
if (AppInfo.enableAutoSave) {
save(page);
}
});
2016-02-29 23:02:03 -07:00
});