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

106 lines
3.8 KiB
JavaScript
Raw Normal View History

define(['userSettingsBuilder', 'appStorage'], function (userSettingsBuilder, appStorage) {
2014-05-21 09:45:42 -07:00
return function (view, params) {
2014-08-18 18:42:53 -07:00
var userId = params.userId || Dashboard.getCurrentUserId();
var userSettings = new userSettingsBuilder(userId);
2015-03-31 09:24:16 -07:00
function loadForm(page, user) {
2016-03-01 09:17:03 -07:00
page.querySelector('.chkDisplayMissingEpisodes').checked = user.Configuration.DisplayMissingEpisodes || false;
page.querySelector('.chkDisplayUnairedEpisodes').checked = user.Configuration.DisplayUnairedEpisodes || false;
2014-05-21 09:45:42 -07:00
page.querySelector('#selectThemeSong').value = appStorage.getItem('enableThemeSongs-' + user.Id) || '';
page.querySelector('#selectBackdrop').value = appStorage.getItem('enableBackdrops-' + user.Id) || '';
2014-05-21 09:45:42 -07:00
page.querySelector('#selectLanguage').value = userSettings.language() || '';
2014-09-29 21:47:30 -07:00
Dashboard.hideLoadingMsg();
}
2016-03-01 09:17:03 -07:00
function saveUser(page, user) {
2014-08-18 18:42:53 -07:00
user.Configuration.DisplayMissingEpisodes = page.querySelector('.chkDisplayMissingEpisodes').checked;
user.Configuration.DisplayUnairedEpisodes = page.querySelector('.chkDisplayUnairedEpisodes').checked;
2014-05-21 09:45:42 -07:00
userSettings.language(page.querySelector('#selectLanguage').value);
2014-05-21 09:45:42 -07:00
appStorage.setItem('enableThemeSongs-' + user.Id, page.querySelector('#selectThemeSong').value);
appStorage.setItem('enableBackdrops-' + user.Id, page.querySelector('#selectBackdrop').value);
2014-05-21 09:45:42 -07:00
return ApiClient.updateUserConfiguration(user.Id, user.Configuration);
2016-01-06 13:16:16 -07:00
}
function save(page) {
2014-06-04 19:32:40 -07:00
if (!AppInfo.enableAutoSave) {
Dashboard.showLoadingMsg();
}
2016-01-06 13:16:16 -07:00
ApiClient.getUser(userId).then(function (user) {
2016-01-06 13:16:16 -07:00
saveUser(page, user).then(function () {
2014-06-04 19:32:40 -07:00
Dashboard.hideLoadingMsg();
if (!AppInfo.enableAutoSave) {
require(['toast'], function (toast) {
toast(Globalize.translate('SettingsSaved'));
});
}
2016-01-06 13:16:16 -07:00
}, function () {
Dashboard.hideLoadingMsg();
});
});
}
2016-01-06 13:16:16 -07:00
2016-06-19 09:53:53 -07:00
view.querySelector('.displayPreferencesForm').addEventListener('submit', function (e) {
save(view);
e.preventDefault();
// Disable default form submission
return false;
});
2014-08-18 18:42:53 -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
}
2016-06-19 09:53:53 -07:00
view.addEventListener('viewshow', function () {
var page = this;
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
Dashboard.showLoadingMsg();
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
ApiClient.getUser(userId).then(function (user) {
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
loadForm(page, user);
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
var requiresUserPreferences = view.querySelectorAll('.requiresUserPreferences');
for (var i = 0, length = requiresUserPreferences.length; i < length; i++) {
if (user.Policy.EnableUserPreferenceAccess) {
requiresUserPreferences[i].classList.remove('hide');
} else {
requiresUserPreferences[i].classList.add('hide');
}
}
});
2014-05-21 09:45:42 -07:00
2016-06-19 09:53:53 -07:00
if (AppInfo.supportsUserDisplayLanguageSetting) {
page.querySelector('.languageSection').classList.remove('hide');
2015-07-03 10:55:29 -07:00
} else {
2016-06-19 09:53:53 -07:00
page.querySelector('.languageSection').classList.add('hide');
2015-07-03 10:55:29 -07:00
}
2014-05-21 09:45:42 -07:00
});
2015-07-03 10:55:29 -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);
}
});
};
2014-05-21 09:45:42 -07:00
2016-03-01 09:17:03 -07:00
});