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

246 lines
8.8 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-05-21 13:36:26 -07:00
function loadPage(page, config) {
if (config.MergeMetadataAndImagesByName) {
$('.fldImagesByName', page).hide();
} else {
$('.fldImagesByName', page).show();
}
$('#txtSeasonZeroName', page).val(config.SeasonZeroDisplayName);
2015-09-03 10:01:51 -07:00
$('#selectEnableRealtimeMonitor', page).val(config.EnableLibraryMonitor);
2014-01-29 13:30:26 -07:00
2016-02-11 11:29:32 -07:00
page.querySelector('#chkEnableAudioArchiveFiles').checked = config.EnableAudioArchiveFiles;
page.querySelector('#chkEnableVideoArchiveFiles').checked = config.EnableVideoArchiveFiles;
2015-01-09 22:53:35 -07:00
2016-03-27 20:37:33 -07:00
$('#chkSaveMetadataHidden', page).checked(config.SaveMetadataHidden);
$('#txtMetadataPath', page).val(config.MetadataPath || '');
$('#chkPeopleActors', page).checked(config.PeopleMetadataOptions.DownloadActorMetadata);
$('#chkPeopleComposers', page).checked(config.PeopleMetadataOptions.DownloadComposerMetadata);
$('#chkPeopleDirectors', page).checked(config.PeopleMetadataOptions.DownloadDirectorMetadata);
$('#chkPeopleProducers', page).checked(config.PeopleMetadataOptions.DownloadProducerMetadata);
$('#chkPeopleWriters', page).checked(config.PeopleMetadataOptions.DownloadWriterMetadata);
$('#chkPeopleOthers', page).checked(config.PeopleMetadataOptions.DownloadOtherPeopleMetadata);
$('#chkPeopleGuestStars', page).checked(config.PeopleMetadataOptions.DownloadGuestStarMetadata);
$('#chkDownloadImagesInAdvance', page).checked(config.DownloadImagesInAdvance);
2013-05-21 13:36:26 -07:00
Dashboard.hideLoadingMsg();
}
2016-03-27 20:37:33 -07:00
function loadMetadataConfig(page, config) {
$('#selectDateAdded', page).val((config.UseFileCreationTimeForDateAdded ? '1' : '0'));
}
function loadTmdbConfig(page, config) {
$('#chkEnableTmdbUpdates', page).checked(config.EnableAutomaticUpdates);
}
function loadTvdbConfig(page, config) {
$('#chkEnableTvdbUpdates', page).checked(config.EnableAutomaticUpdates);
}
function loadFanartConfig(page, config) {
$('#chkEnableFanartUpdates', page).checked(config.EnableAutomaticUpdates);
$('#txtFanartApiKey', page).val(config.UserApiKey || '');
}
function loadChapters(page, config, providers) {
$('#chkChaptersMovies', page).checked(config.EnableMovieChapterImageExtraction);
$('#chkChaptersEpisodes', page).checked(config.EnableEpisodeChapterImageExtraction);
$('#chkChaptersOtherVideos', page).checked(config.EnableOtherVideoChapterImageExtraction);
$('#chkExtractChaptersDuringLibraryScan', page).checked(config.ExtractDuringLibraryScan);
Dashboard.hideLoadingMsg();
}
function saveFanart(form) {
ApiClient.getNamedConfiguration("fanart").then(function (config) {
config.EnableAutomaticUpdates = $('#chkEnableFanartUpdates', form).checked();
config.UserApiKey = $('#txtFanartApiKey', form).val();
ApiClient.updateNamedConfiguration("fanart", config);
});
}
function saveTvdb(form) {
ApiClient.getNamedConfiguration("tvdb").then(function (config) {
config.EnableAutomaticUpdates = $('#chkEnableTvdbUpdates', form).checked();
ApiClient.updateNamedConfiguration("tvdb", config);
});
}
function saveTmdb(form) {
ApiClient.getNamedConfiguration("themoviedb").then(function (config) {
config.EnableAutomaticUpdates = $('#chkEnableTmdbUpdates', form).checked();
ApiClient.updateNamedConfiguration("themoviedb", config);
});
}
function saveMetadata(form) {
ApiClient.getNamedConfiguration("metadata").then(function (config) {
config.UseFileCreationTimeForDateAdded = $('#selectDateAdded', form).val() == '1';
ApiClient.updateNamedConfiguration("metadata", config);
});
}
function saveChapters(form) {
ApiClient.getNamedConfiguration("chapters").then(function (config) {
config.EnableMovieChapterImageExtraction = $('#chkChaptersMovies', form).checked();
config.EnableEpisodeChapterImageExtraction = $('#chkChaptersEpisodes', form).checked();
config.EnableOtherVideoChapterImageExtraction = $('#chkChaptersOtherVideos', form).checked();
config.ExtractDuringLibraryScan = $('#chkExtractChaptersDuringLibraryScan', form).checked();
ApiClient.updateNamedConfiguration("chapters", config);
});
}
2015-06-07 18:23:56 -07:00
function onSubmit() {
Dashboard.showLoadingMsg();
var form = this;
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2015-06-07 18:23:56 -07:00
config.SeasonZeroDisplayName = $('#txtSeasonZeroName', form).val();
config.EnableLibraryMonitor = $('#selectEnableRealtimeMonitor', form).val();
2015-06-07 18:23:56 -07:00
2016-02-11 11:29:32 -07:00
config.EnableAudioArchiveFiles = form.querySelector('#chkEnableAudioArchiveFiles').checked;
config.EnableVideoArchiveFiles = form.querySelector('#chkEnableVideoArchiveFiles').checked;
2015-06-07 18:23:56 -07:00
2016-03-27 20:37:33 -07:00
config.SaveMetadataHidden = $('#chkSaveMetadataHidden', form).checked();
config.EnableTvDbUpdates = $('#chkEnableTvdbUpdates', form).checked();
config.EnableTmdbUpdates = $('#chkEnableTmdbUpdates', form).checked();
config.EnableFanArtUpdates = $('#chkEnableFanartUpdates', form).checked();
config.MetadataPath = $('#txtMetadataPath', form).val();
config.FanartApiKey = $('#txtFanartApiKey', form).val();
config.DownloadImagesInAdvance = $('#chkDownloadImagesInAdvance', form).checked();
config.PeopleMetadataOptions.DownloadActorMetadata = $('#chkPeopleActors', form).checked();
config.PeopleMetadataOptions.DownloadComposerMetadata = $('#chkPeopleComposers', form).checked();
config.PeopleMetadataOptions.DownloadDirectorMetadata = $('#chkPeopleDirectors', form).checked();
config.PeopleMetadataOptions.DownloadGuestStarMetadata = $('#chkPeopleGuestStars', form).checked();
config.PeopleMetadataOptions.DownloadProducerMetadata = $('#chkPeopleProducers', form).checked();
config.PeopleMetadataOptions.DownloadWriterMetadata = $('#chkPeopleWriters', form).checked();
config.PeopleMetadataOptions.DownloadOtherPeopleMetadata = $('#chkPeopleOthers', form).checked();
2015-12-14 08:43:03 -07:00
ApiClient.updateServerConfiguration(config).then(Dashboard.processServerConfigurationUpdateResult);
2015-06-07 18:23:56 -07:00
});
2016-03-27 20:37:33 -07:00
saveChapters(form);
saveMetadata(form);
saveTmdb(form);
saveTvdb(form);
saveFanart(form);
2015-06-07 18:23:56 -07:00
// Disable default form submission
return false;
}
2015-09-24 10:08:10 -07:00
$(document).on('pageshow', "#librarySettingsPage", function () {
2013-05-21 13:36:26 -07:00
Dashboard.showLoadingMsg();
var page = this;
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2013-05-21 13:36:26 -07:00
loadPage(page, config);
2016-03-27 20:37:33 -07:00
});
ApiClient.getNamedConfiguration("metadata").then(function (metadata) {
2013-05-21 13:36:26 -07:00
2016-03-27 20:37:33 -07:00
loadMetadataConfig(page, metadata);
});
ApiClient.getNamedConfiguration("fanart").then(function (metadata) {
loadFanartConfig(page, metadata);
});
ApiClient.getNamedConfiguration("themoviedb").then(function (metadata) {
loadTmdbConfig(page, metadata);
});
ApiClient.getNamedConfiguration("tvdb").then(function (metadata) {
loadTvdbConfig(page, metadata);
});
var promise1 = ApiClient.getNamedConfiguration("chapters");
var promise2 = ApiClient.getJSON(ApiClient.getUrl("Providers/Chapters"));
Promise.all([promise1, promise2]).then(function (responses) {
loadChapters(page, responses[0], responses[1]);
2013-05-21 13:36:26 -07:00
});
2015-09-01 07:01:59 -07:00
}).on('pageinit', "#librarySettingsPage", function () {
2014-07-19 21:46:29 -07:00
var page = this;
2016-03-27 20:37:33 -07:00
$('#btnSelectMetadataPath', page).on("click.selectDirectory", function () {
require(['directorybrowser'], function (directoryBrowser) {
var picker = new directoryBrowser();
picker.show({
callback: function (path) {
if (path) {
$('#txtMetadataPath', page).val(path);
}
picker.close();
},
header: Globalize.translate('HeaderSelectMetadataPath'),
instruction: Globalize.translate('HeaderSelectMetadataPathHelp')
});
});
});
2015-06-07 18:23:56 -07:00
$('.librarySettingsForm').off('submit', onSubmit).on('submit', onSubmit);
2015-12-14 08:43:03 -07:00
ApiClient.getSystemInfo().then(function (systemInfo) {
if (systemInfo.SupportsLibraryMonitor) {
page.querySelector('.fldLibraryMonitor').classList.remove('hide');
} else {
page.querySelector('.fldLibraryMonitor').classList.add('hide');
}
});
2015-06-07 18:23:56 -07:00
});
2013-05-21 13:36:26 -07:00
});