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

129 lines
4.4 KiB
JavaScript
Raw Normal View History

2014-05-21 11:38:12 -07:00
(function ($, window, document) {
2014-05-21 12:33:46 -07:00
function loadForm(page, userId, displayPreferences) {
2014-05-21 11:38:12 -07:00
2014-09-16 18:38:50 -07:00
$('#selectMaxBitrate', page).val(AppSettings.maxStreamingBitrate()).selectmenu("refresh");
2015-04-25 21:39:40 -07:00
$('#selectMaxChromecastBitrate', page).val(AppSettings.maxChromecastBitrate()).selectmenu("refresh");
2014-09-16 18:38:50 -07:00
2015-05-25 10:32:22 -07:00
$('#chkExternalVideoPlayer', page).checked(AppSettings.enableExternalPlayers()).checkboxradio("refresh");
2014-09-15 20:33:30 -07:00
2015-05-20 10:29:26 -07:00
$('#selectThemeSong', page).val(appStorage.getItem('enableThemeSongs-' + userId) || '').selectmenu("refresh");
$('#selectBackdrop', page).val(appStorage.getItem('enableBackdrops-' + userId) || '').selectmenu("refresh");
2014-05-21 12:33:46 -07:00
$('#selectHomeSection1', page).val(displayPreferences.CustomPrefs.home0 || '').selectmenu("refresh");
$('#selectHomeSection2', page).val(displayPreferences.CustomPrefs.home1 || '').selectmenu("refresh");
$('#selectHomeSection3', page).val(displayPreferences.CustomPrefs.home2 || '').selectmenu("refresh");
$('#selectHomeSection4', page).val(displayPreferences.CustomPrefs.home3 || '').selectmenu("refresh");
2014-05-21 11:38:12 -07:00
2015-03-14 18:58:06 -07:00
$('#chkEnableLibraryTileNames', page).checked(displayPreferences.CustomPrefs.enableLibraryTileNames != '0').checkboxradio("refresh");
2014-05-21 11:38:12 -07:00
Dashboard.hideLoadingMsg();
}
2014-05-21 12:33:46 -07:00
function saveUser(page, userId, displayPreferences) {
2015-05-20 10:29:26 -07:00
appStorage.setItem('enableThemeSongs-' + userId, $('#selectThemeSong', page).val());
appStorage.setItem('enableBackdrops-' + userId, $('#selectBackdrop', page).val());
2014-05-21 12:33:46 -07:00
displayPreferences.CustomPrefs.home0 = $('#selectHomeSection1', page).val();
displayPreferences.CustomPrefs.home1 = $('#selectHomeSection2', page).val();
displayPreferences.CustomPrefs.home2 = $('#selectHomeSection3', page).val();
displayPreferences.CustomPrefs.home3 = $('#selectHomeSection4', page).val();
2015-03-14 18:58:06 -07:00
displayPreferences.CustomPrefs.enableLibraryTileNames = $('#chkEnableLibraryTileNames', page).checked() ? '1' : '0';
2014-05-21 11:38:12 -07:00
2014-05-21 12:33:46 -07:00
ApiClient.updateDisplayPreferences('home', displayPreferences, userId, 'webclient').done(function () {
2014-05-21 11:38:12 -07:00
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('SettingsSaved'));
2014-07-21 18:29:06 -07:00
2014-05-21 12:33:46 -07:00
});
2014-05-21 11:38:12 -07:00
}
function onSubmit() {
var page = $(this).parents('.page');
Dashboard.showLoadingMsg();
2015-05-25 10:32:22 -07:00
AppSettings.enableExternalPlayers($('#chkExternalVideoPlayer', page).checked());
2014-09-15 20:33:30 -07:00
2014-09-16 18:38:50 -07:00
AppSettings.maxStreamingBitrate($('#selectMaxBitrate', page).val());
2015-04-25 21:39:40 -07:00
AppSettings.maxChromecastBitrate($('#selectMaxChromecastBitrate', page).val());
2014-09-16 18:38:50 -07:00
2014-05-21 11:38:12 -07:00
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2014-05-21 12:33:46 -07:00
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
2014-05-21 11:38:12 -07:00
2014-05-21 12:33:46 -07:00
saveUser(page, userId, result);
2014-05-21 11:38:12 -07:00
});
// Disable default form submission
return false;
}
$(document).on('pageinit', "#webClientPreferencesPage", function () {
var page = this;
}).on('pagebeforeshow', "#webClientPreferencesPage", function () {
var page = this;
Dashboard.showLoadingMsg();
var userId = getParameterByName('userId') || Dashboard.getCurrentUserId();
2014-05-21 12:33:46 -07:00
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
2014-05-21 11:38:12 -07:00
2014-05-21 12:33:46 -07:00
loadForm(page, userId, result);
2014-05-21 11:38:12 -07:00
});
2014-08-07 21:36:51 -07:00
2015-05-04 07:35:38 -07:00
$('.fldEnableBackdrops', page).show();
2015-05-07 15:27:01 -07:00
if (Dashboard.isRunningInCordova()) {
$('.homePageConfigurationSection', page).hide();
} else {
$('.homePageConfigurationSection', page).show();
}
2014-05-21 11:38:12 -07:00
});
window.WebClientPreferencesPage = {
onSubmit: onSubmit
};
2014-09-16 18:38:50 -07:00
})(jQuery, window, document);
(function (window, store) {
window.AppSettings = {
maxStreamingBitrate: function (val) {
if (val != null) {
store.setItem('preferredVideoBitrate', val);
}
return parseInt(store.getItem('preferredVideoBitrate') || '') || 1500000;
2015-04-25 21:39:40 -07:00
},
maxChromecastBitrate: function (val) {
if (val != null) {
store.setItem('chromecastBitrate', val);
}
return parseInt(store.getItem('chromecastBitrate') || '') || 3000000;
2015-05-25 10:32:22 -07:00
},
enableExternalPlayers: function (val) {
if (val != null) {
store.setItem('externalplayers', val.toString());
}
return store.getItem('externalplayers') == 'true';
2014-09-16 18:38:50 -07:00
}
};
2015-05-20 10:29:26 -07:00
})(window, window.appStorage);