(function ($, window, document) { function loadForm(page, user) { $('#chkDisplayMissingEpisodes', page).checked(user.Configuration.DisplayMissingEpisodes || false).checkboxradio("refresh"); $('#chkDisplayUnairedEpisodes', page).checked(user.Configuration.DisplayUnairedEpisodes || false).checkboxradio("refresh"); $('#chkGroupMoviesIntoCollections', page).checked(user.Configuration.GroupMoviesIntoBoxSets || false).checkboxradio("refresh"); ApiClient.getItems(user.Id, {}).done(function (result) { var folderHtml = ''; folderHtml += '
'; folderHtml += result.Items.map(function (i) { var currentHtml = ''; var id = 'chkGroupFolder' + i.Id; currentHtml += ''; var isChecked = user.Configuration.ExcludeFoldersFromGrouping.indexOf(i.Id) == -1; var checkedHtml = isChecked ? ' checked="checked"' : ''; currentHtml += ''; return currentHtml; }).join(''); folderHtml += '
'; $('.folderGroupList', page).html(folderHtml).trigger('create'); Dashboard.hideLoadingMsg(); }); } function saveUser(page, user) { user.Configuration.DisplayMissingEpisodes = $('#chkDisplayMissingEpisodes', page).checked(); user.Configuration.DisplayUnairedEpisodes = $('#chkDisplayUnairedEpisodes', page).checked(); user.Configuration.GroupMoviesIntoBoxSets = $('#chkGroupMoviesIntoCollections', page).checked(); user.Configuration.ExcludeFoldersFromGrouping = $(".chkGroupFolder:not(:checked)", page).get().map(function (i) { return i.getAttribute('data-folderid'); }); ApiClient.updateUser(user).done(function () { Dashboard.alert(Globalize.translate('SettingsSaved')); }); } function onSubmit() { var page = $(this).parents('.page'); Dashboard.showLoadingMsg(); var userId = getParameterByName('userId') || Dashboard.getCurrentUserId(); ApiClient.getUser(userId).done(function (result) { saveUser(page, result); }); // Disable default form submission return false; } $(document).on('pageinit', "#displayPreferencesPage", function () { var page = this; }).on('pageshow', "#displayPreferencesPage", function () { var page = this; Dashboard.showLoadingMsg(); var userId = getParameterByName('userId') || Dashboard.getCurrentUserId(); ApiClient.getUser(userId).done(function (user) { loadForm(page, user); }); }).on('pageshow', ".userPreferencesPage", function () { var page = this; var userId = getParameterByName('userId') || Dashboard.getCurrentUserId(); $('.lnkDisplayPreferences', page).attr('href', 'mypreferencesdisplay.html?userId=' + userId); $('.lnkLanguagePreferences', page).attr('href', 'mypreferenceslanguages.html?userId=' + userId); $('.lnkWebClientPreferences', page).attr('href', 'mypreferenceswebclient.html?userId=' + userId); }); window.DisplayPreferencesPage = { onSubmit: onSubmit }; })(jQuery, window, document);