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

109 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-05-21 09:45:42 -07:00
(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");
2014-06-04 19:32:40 -07:00
ApiClient.getItems(user.Id, {}).done(function (result) {
var folderHtml = '';
folderHtml += '<div data-role="controlgroup">';
folderHtml += result.Items.map(function (i) {
var currentHtml = '';
var id = 'chkGroupFolder' + i.Id;
currentHtml += '<label for="' + id + '">' + i.Name + '</label>';
var isChecked = user.Configuration.ExcludeFoldersFromGrouping.indexOf(i.Id) == -1;
var checkedHtml = isChecked ? ' checked="checked"' : '';
currentHtml += '<input class="chkGroupFolder" data-folderid="' + i.Id + '" type="checkbox" data-mini="true" id="' + id + '"' + checkedHtml + ' />';
return currentHtml;
}).join('');
folderHtml += '</div>';
$('.folderGroupList', page).html(folderHtml).trigger('create');
Dashboard.hideLoadingMsg();
});
2014-05-21 09:45:42 -07:00
}
function saveUser(page, user) {
user.Configuration.DisplayMissingEpisodes = $('#chkDisplayMissingEpisodes', page).checked();
user.Configuration.DisplayUnairedEpisodes = $('#chkDisplayUnairedEpisodes', page).checked();
user.Configuration.GroupMoviesIntoBoxSets = $('#chkGroupMoviesIntoCollections', page).checked();
2014-06-04 19:32:40 -07:00
user.Configuration.ExcludeFoldersFromGrouping = $(".chkGroupFolder:not(:checked)", page).get().map(function (i) {
return i.getAttribute('data-folderid');
});
2014-05-21 09:45:42 -07:00
ApiClient.updateUser(user).done(function () {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('SettingsSaved'));
2014-05-21 09:45:42 -07:00
});
}
function onSubmit() {
var page = $(this).parents('.page');
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
ApiClient.getUser(userId).done(function (result) {
2014-06-04 19:32:40 -07:00
2014-05-21 09:45:42 -07:00
saveUser(page, result);
2014-06-04 19:32:40 -07:00
2014-05-21 09:45:42 -07:00
});
// 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);
});
2014-06-04 19:32:40 -07:00
2014-05-21 09:45:42 -07:00
}).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);