2016-03-18 21:26:17 -07:00
|
|
|
|
define(['userSettings', 'appStorage', 'jQuery'], function (userSettings, appStorage, $) {
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
function loadForm(page, user) {
|
2014-08-18 18:42:53 -07:00
|
|
|
|
|
2015-07-28 12:42:24 -07:00
|
|
|
|
page.querySelector('.chkDisplayMissingEpisodes').checked = user.Configuration.DisplayMissingEpisodes || false;
|
|
|
|
|
page.querySelector('.chkDisplayUnairedEpisodes').checked = user.Configuration.DisplayUnairedEpisodes || false;
|
|
|
|
|
page.querySelector('.chkGroupMoviesIntoCollections').checked = user.Configuration.GroupMoviesIntoBoxSets || false;
|
2014-08-18 18:42:53 -07:00
|
|
|
|
|
2015-09-03 10:01:51 -07:00
|
|
|
|
$('#selectThemeSong', page).val(appStorage.getItem('enableThemeSongs-' + user.Id) || '');
|
|
|
|
|
$('#selectBackdrop', page).val(appStorage.getItem('enableBackdrops-' + user.Id) || '');
|
2015-03-31 09:24:16 -07:00
|
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
|
$('#selectLanguage', page).val(userSettings.language() || '');
|
2016-03-01 09:17:03 -07:00
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2014-05-21 09:45:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveUser(page, user) {
|
|
|
|
|
|
2015-07-28 12:42:24 -07:00
|
|
|
|
user.Configuration.DisplayMissingEpisodes = page.querySelector('.chkDisplayMissingEpisodes').checked;
|
|
|
|
|
user.Configuration.DisplayUnairedEpisodes = page.querySelector('.chkDisplayUnairedEpisodes').checked;
|
|
|
|
|
user.Configuration.GroupMoviesIntoBoxSets = page.querySelector('.chkGroupMoviesIntoCollections').checked;
|
2014-09-29 21:47:30 -07:00
|
|
|
|
|
2016-03-01 21:46:10 -07:00
|
|
|
|
userSettings.language(page.querySelector('#selectLanguage').value);
|
2016-03-01 09:17:03 -07:00
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
appStorage.setItem('enableThemeSongs-' + user.Id, $('#selectThemeSong', page).val());
|
|
|
|
|
appStorage.setItem('enableBackdrops-' + user.Id, $('#selectBackdrop', page).val());
|
2014-08-18 18:42:53 -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) {
|
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 (user) {
|
2014-06-04 19:32:40 -07:00
|
|
|
|
|
2016-01-06 13:16:16 -07:00
|
|
|
|
saveUser(page, user).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-06-04 19:32:40 -07:00
|
|
|
|
|
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', "displayPreferencesPage", function () {
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
$('.displayPreferencesForm').off('submit', onSubmit).on('submit', onSubmit);
|
2014-08-18 18:42:53 -07:00
|
|
|
|
|
2016-01-06 13:16:16 -07:00
|
|
|
|
if (AppInfo.enableAutoSave) {
|
|
|
|
|
page.querySelector('.btnSave').classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.btnSave').classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
pageIdOn('pageshow', "displayPreferencesPage", function () {
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getUser(userId).then(function (user) {
|
2014-05-21 09:45:42 -07:00
|
|
|
|
|
|
|
|
|
loadForm(page, user);
|
|
|
|
|
|
2015-07-03 10:55:29 -07:00
|
|
|
|
if (user.Policy.EnableUserPreferenceAccess) {
|
|
|
|
|
$('.requiresUserPreferences', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.requiresUserPreferences', page).hide();
|
|
|
|
|
}
|
2014-05-21 09:45:42 -07:00
|
|
|
|
});
|
2015-07-03 10:55:29 -07:00
|
|
|
|
|
|
|
|
|
$('.fldEnableBackdrops', page).show();
|
|
|
|
|
|
2016-03-01 09:17:03 -07:00
|
|
|
|
if (AppInfo.supportsUserDisplayLanguageSetting) {
|
|
|
|
|
$('.languageSection', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.languageSection', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 13:16:16 -07:00
|
|
|
|
});
|
|
|
|
|
pageIdOn('pagebeforehide', "displayPreferencesPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
if (AppInfo.enableAutoSave) {
|
|
|
|
|
save(page);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 09:45:42 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-03-01 09:17:03 -07:00
|
|
|
|
});
|