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

209 lines
8.1 KiB
JavaScript
Raw Normal View History

define(['appSettings', 'userSettingsBuilder'], function (appSettings, userSettingsBuilder) {
2016-10-22 22:11:46 -07:00
'use strict';
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>";
}
2016-06-19 09:53:53 -07:00
select.innerHTML = html;
2014-05-21 09:45:42 -07:00
}
return function (view, params) {
2014-05-21 09:45:42 -07:00
var userId = params.userId || Dashboard.getCurrentUserId();
2016-12-09 18:58:52 -07:00
var userSettingsInstance = new userSettingsBuilder();
2016-09-05 23:45:22 -07:00
var userSettingsLoaded;
2014-05-21 09:45:42 -07:00
function loadForm(page, user, loggedInUser, allCulturesPromise) {
2014-05-21 09:45:42 -07:00
2016-12-09 18:58:52 -07:00
userSettingsInstance.setUserInfo(userId, ApiClient).then(function () {
2016-09-05 23:45:22 -07:00
userSettingsLoaded = true;
allCulturesPromise.then(function (allCultures) {
2014-05-21 09:45:42 -07:00
2016-09-05 23:45:22 -07:00
populateLanguages(page.querySelector('#selectAudioLanguage'), allCultures);
populateLanguages(page.querySelector('#selectSubtitleLanguage'), allCultures);
2015-07-22 22:25:55 -07:00
2016-09-05 23:45:22 -07:00
page.querySelector('#selectAudioLanguage', page).value = user.Configuration.AudioLanguagePreference || "";
page.querySelector('#selectSubtitleLanguage', page).value = user.Configuration.SubtitleLanguagePreference || "";
page.querySelector('.chkEpisodeAutoPlay').checked = user.Configuration.EnableNextEpisodeAutoPlay || false;
});
2015-07-22 22:25:55 -07:00
2016-09-05 23:45:22 -07:00
page.querySelector('#selectSubtitlePlaybackMode').value = user.Configuration.SubtitleMode || "";
2015-07-22 22:25:55 -07:00
2016-09-05 23:45:22 -07:00
page.querySelector('.chkPlayDefaultAudioTrack').checked = user.Configuration.PlayDefaultAudioTrack || false;
2016-12-09 18:58:52 -07:00
page.querySelector('.chkEnableCinemaMode').checked = userSettingsInstance.enableCinemaMode();
2016-09-05 23:45:22 -07:00
page.querySelector('.chkExternalVideoPlayer').checked = appSettings.enableExternalPlayers();
2015-09-05 14:15:36 -07:00
2016-09-05 23:45:22 -07:00
require(['qualityoptions'], function (qualityoptions) {
2015-09-05 14:15:36 -07:00
2016-09-05 23:45:22 -07:00
var bitrateOptions = qualityoptions.getVideoQualityOptions(appSettings.maxStreamingBitrate()).map(function (i) {
2015-12-30 10:02:11 -07:00
2016-09-05 23:45:22 -07:00
return '<option value="' + i.bitrate + '">' + i.name + '</option>';
2015-07-22 22:25:55 -07:00
2016-09-05 23:45:22 -07:00
}).join('');
2015-07-03 10:55:29 -07:00
2016-09-05 23:45:22 -07:00
bitrateOptions = '<option value="">' + Globalize.translate('OptionAutomatic') + '</option>' + bitrateOptions;
2014-05-21 09:45:42 -07:00
2016-09-05 23:45:22 -07:00
page.querySelector('#selectMaxBitrate').innerHTML = bitrateOptions;
page.querySelector('#selectMaxChromecastBitrate').innerHTML = bitrateOptions;
2014-10-01 17:28:16 -07:00
2016-09-05 23:45:22 -07:00
if (appSettings.enableAutomaticBitrateDetection()) {
page.querySelector('#selectMaxBitrate').value = '';
} else {
page.querySelector('#selectMaxBitrate').value = appSettings.maxStreamingBitrate();
}
2014-10-01 17:28:16 -07:00
2016-09-05 23:45:22 -07:00
page.querySelector('#selectMaxChromecastBitrate').value = appSettings.maxChromecastBitrate() || '';
2014-10-01 17:28:16 -07:00
2016-09-05 23:45:22 -07:00
Dashboard.hideLoadingMsg();
});
});
}
2014-10-01 17:28:16 -07:00
function loadPage(page) {
2014-10-01 17:28:16 -07:00
Dashboard.showLoadingMsg();
2014-10-01 17:28:16 -07:00
var promise1 = ApiClient.getUser(userId);
2014-10-01 17:28:16 -07:00
var promise2 = Dashboard.getCurrentUser();
2014-10-01 17:28:16 -07:00
var allCulturesPromise = ApiClient.getCultures();
2014-10-01 17:28:16 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-10-01 17:28:16 -07:00
loadForm(page, responses[1], responses[0], allCulturesPromise);
2014-10-01 17:28:16 -07:00
});
2014-05-21 09:45:42 -07:00
ApiClient.getNamedConfiguration("cinemamode").then(function (cinemaConfig) {
2014-05-21 09:45:42 -07:00
if (cinemaConfig.EnableIntrosForMovies || cinemaConfig.EnableIntrosForEpisodes) {
page.querySelector('.cinemaModeOptions').classList.remove('hide');
} else {
page.querySelector('.cinemaModeOptions').classList.add('hide');
}
});
}
2015-12-14 08:43:03 -07:00
2016-12-09 18:58:52 -07:00
function refreshGlobalUserSettings() {
require(['userSettings'], function (userSettings) {
userSettings.importFrom(userSettingsInstance);
});
}
function saveUser(page, user) {
2014-05-21 09:45:42 -07:00
user.Configuration.AudioLanguagePreference = page.querySelector('#selectAudioLanguage').value;
user.Configuration.SubtitleLanguagePreference = page.querySelector('#selectSubtitleLanguage').value;
2016-02-29 23:02:03 -07:00
user.Configuration.SubtitleMode = page.querySelector('#selectSubtitlePlaybackMode').value;
user.Configuration.PlayDefaultAudioTrack = page.querySelector('.chkPlayDefaultAudioTrack').checked;
user.Configuration.EnableNextEpisodeAutoPlay = page.querySelector('.chkEpisodeAutoPlay').checked;
2016-09-05 23:45:22 -07:00
if (userSettingsLoaded) {
2016-12-09 18:58:52 -07:00
userSettingsInstance.enableCinemaMode(page.querySelector('.chkEnableCinemaMode').checked);
if (userId === Dashboard.getCurrentUserId()) {
refreshGlobalUserSettings();
}
2016-09-05 23:45:22 -07:00
}
2015-07-28 12:42:24 -07:00
return ApiClient.updateUserConfiguration(user.Id, user.Configuration);
2015-09-05 14:15:36 -07:00
}
function save(page) {
2015-07-03 10:55:29 -07:00
appSettings.enableExternalPlayers(page.querySelector('.chkExternalVideoPlayer').checked);
2014-05-21 09:45:42 -07:00
if (page.querySelector('#selectMaxBitrate').value) {
appSettings.maxStreamingBitrate(page.querySelector('#selectMaxBitrate').value);
appSettings.enableAutomaticBitrateDetection(false);
} else {
appSettings.enableAutomaticBitrateDetection(true);
}
appSettings.maxChromecastBitrate(page.querySelector('#selectMaxChromecastBitrate').value);
2016-01-06 13:16:16 -07:00
if (!AppInfo.enableAutoSave) {
Dashboard.showLoadingMsg();
}
2014-05-21 09:45:42 -07:00
ApiClient.getUser(userId).then(function (result) {
2016-01-06 13:16:16 -07:00
saveUser(page, result).then(function () {
2016-01-06 13:16:16 -07:00
Dashboard.hideLoadingMsg();
if (!AppInfo.enableAutoSave) {
require(['toast'], function (toast) {
toast(Globalize.translate('SettingsSaved'));
});
}
2014-05-21 09:45:42 -07:00
}, function () {
Dashboard.hideLoadingMsg();
});
2016-01-06 13:16:16 -07:00
});
}
2016-01-06 13:16:16 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('#selectSubtitlePlaybackMode').addEventListener('change', function () {
2016-01-06 13:16:16 -07:00
2016-06-19 09:53:53 -07:00
var subtitlesHelp = view.querySelectorAll('.subtitlesHelp');
for (var i = 0, length = subtitlesHelp.length; i < length; i++) {
subtitlesHelp[i].classList.add('hide');
}
view.querySelector('.subtitles' + this.value + 'Help').classList.remove('hide');
});
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('.languagePreferencesForm').addEventListener('submit', function (e) {
save(view);
2014-05-21 11:38:12 -07:00
2016-06-19 09:53:53 -07:00
// Disable default form submission
e.preventDefault();
return false;
2014-05-21 11:38:12 -07:00
});
2016-01-06 13:16:16 -07:00
if (AppInfo.enableAutoSave) {
2016-06-19 09:53:53 -07:00
view.querySelector('.btnSave').classList.add('hide');
2016-01-06 13:16:16 -07:00
} else {
2016-06-19 09:53:53 -07:00
view.querySelector('.btnSave').classList.remove('hide');
2016-01-06 13:16:16 -07:00
}
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
view.addEventListener('viewshow', function () {
2015-12-14 08:43:03 -07:00
2016-06-19 09:53:53 -07:00
if (AppInfo.supportsExternalPlayers) {
view.querySelector('.fldExternalPlayer').classList.remove('hide');
} else {
view.querySelector('.fldExternalPlayer').classList.add('hide');
}
2015-07-03 10:55:29 -07:00
2016-06-19 09:53:53 -07:00
if (AppInfo.supportsExternalPlayerMenu) {
view.querySelector('.labelNativeExternalPlayers').classList.remove('hide');
view.querySelector('.labelGenericExternalPlayers').classList.add('hide');
} else {
view.querySelector('.labelGenericExternalPlayers').classList.remove('hide');
view.querySelector('.labelNativeExternalPlayers').classList.add('hide');
}
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
loadPage(view);
});
2016-01-06 13:16:16 -07:00
2016-06-19 09:53:53 -07:00
view.addEventListener('viewbeforehide', function () {
var page = this;
2016-01-06 13:16:16 -07:00
2016-06-19 09:53:53 -07:00
if (AppInfo.enableAutoSave) {
save(page);
}
});
};
2016-01-06 13:16:16 -07:00
2016-02-29 23:02:03 -07:00
});