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

582 lines
20 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-02-20 18:33:05 -07:00
var currentType;
2014-02-02 06:36:31 -07:00
function loadTabs(page, tabs) {
var html = '';
for (var i = 0, length = tabs.length; i < length; i++) {
var tab = tabs[i];
2014-05-12 11:04:25 -07:00
var isChecked = i == 0 ? ' selected="selected"' : '';
2014-08-15 09:35:41 -07:00
html += '<option value="' + tab.type + '"' + isChecked + '>' + Globalize.translate(tab.name) + '</option>';
2014-02-02 06:36:31 -07:00
}
2015-09-03 10:01:51 -07:00
$('#selectItemType', page).html(html).trigger('change');
2014-02-02 06:36:31 -07:00
Dashboard.hideLoadingMsg();
}
function loadType(page, type) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
currentType = type;
2014-02-02 06:36:31 -07:00
var promise1 = ApiClient.getServerConfiguration();
2014-07-01 22:16:59 -07:00
var promise2 = ApiClient.getJSON(ApiClient.getUrl("System/Configuration/MetadataPlugins"));
2014-02-02 06:36:31 -07:00
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2014-02-02 06:36:31 -07:00
2015-12-14 08:43:03 -07:00
var config = responses[0];
var metadataPlugins = responses[1];
config = config.MetadataOptions.filter(function (c) {
return c.ItemType == type;
})[0];
if (config) {
renderType(page, type, config, metadataPlugins);
Dashboard.hideLoadingMsg();
} else {
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl("System/Configuration/MetadataOptions/Default")).then(function (defaultConfig) {
config = defaultConfig;
renderType(page, type, config, metadataPlugins);
Dashboard.hideLoadingMsg();
});
}
2013-02-20 18:33:05 -07:00
});
2014-02-02 06:36:31 -07:00
}
function setVisibilityOfBackdrops(elem, visible) {
if (visible) {
elem.show();
$('input', elem).attr('required', 'required');
} else {
elem.hide();
$('input', elem).attr('required', '').removeAttr('required');
}
}
2014-02-02 06:36:31 -07:00
function renderType(page, type, config, metadataPlugins) {
var metadataInfo = metadataPlugins.filter(function (f) {
return type == f.ItemType;
})[0];
setVisibilityOfBackdrops($('.backdropFields', page), metadataInfo.SupportedImageTypes.indexOf('Backdrop') != -1);
setVisibilityOfBackdrops($('.screenshotFields', page), metadataInfo.SupportedImageTypes.indexOf('Screenshot') != -1);
2014-02-02 06:36:31 -07:00
$('.imageType', page).each(function () {
var imageType = this.getAttribute('data-imagetype');
if (metadataInfo.SupportedImageTypes.indexOf(imageType) == -1) {
2016-02-18 22:03:00 -07:00
this.classList.add('hide');
2014-02-02 06:36:31 -07:00
} else {
2016-02-18 22:03:00 -07:00
this.classList.remove('hide');
2014-02-02 06:36:31 -07:00
}
if (getImageConfig(config, imageType).Limit) {
2016-02-18 22:03:00 -07:00
this.checked = true;
} else {
2016-02-18 22:03:00 -07:00
this.checked = false;
}
2014-02-02 06:36:31 -07:00
});
var backdropConfig = getImageConfig(config, 'Backdrop');
$('#txtMaxBackdrops', page).val(backdropConfig.Limit);
$('#txtMinBackdropDownloadWidth', page).val(backdropConfig.MinWidth);
var screenshotConfig = getImageConfig(config, 'Screenshot');
$('#txtMaxScreenshots', page).val(screenshotConfig.Limit);
$('#txtMinScreenshotDownloadWidth', page).val(screenshotConfig.MinWidth);
2014-02-02 06:36:31 -07:00
renderMetadataLocals(page, type, config, metadataInfo);
renderMetadataFetchers(page, type, config, metadataInfo);
renderMetadataSavers(page, type, config, metadataInfo);
renderImageFetchers(page, type, config, metadataInfo);
}
function getImageConfig(config, type) {
return config.ImageOptions.filter(function (i) {
return i.Type == type;
})[0] || {
Type: type,
MinWidth: type == 'Backdrop' ? 1280 : 0,
Limit: type == 'Backdrop' ? 3 : 1
};
}
2014-02-02 06:36:31 -07:00
function renderImageFetchers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'ImageFetcher';
});
var html = '';
if (!plugins.length) {
$('.imageFetchers', page).html(html).hide().trigger('create');
return;
}
2014-02-10 21:55:01 -07:00
var i, length, plugin, id;
2014-02-02 06:36:31 -07:00
2014-08-15 09:35:41 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">' + Globalize.translate('LabelImageFetchers') + '</div>';
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
html += '<div style="display:inline-block;width: 75%;vertical-align:top;">';
html += '<div data-role="controlgroup" class="imageFetcherGroup">';
2014-02-10 21:55:01 -07:00
for (i = 0, length = plugins.length; i < length; i++) {
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
plugin = plugins[i];
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
id = 'chkImageFetcher' + i;
var isChecked = config.DisabledImageFetchers.indexOf(plugin.Name) == -1 ? ' checked="checked"' : '';
html += '<input class="chkImageFetcher" type="checkbox" name="' + id + '" id="' + id + '" data-pluginname="' + plugin.Name + '" data-mini="true"' + isChecked + '>';
2014-02-02 06:36:31 -07:00
html += '<label for="' + id + '">' + plugin.Name + '</label>';
}
2014-02-10 21:55:01 -07:00
html += '</div>';
html += '</div>';
if (plugins.length > 1) {
html += '<div style="display:inline-block;vertical-align:top;margin-left:5px;">';
for (i = 0, length = plugins.length; i < length; i++) {
2015-12-14 08:43:03 -07:00
html += '<div>';
2015-09-06 12:09:36 -07:00
if (i > 0) {
html += '<paper-icon-button class="btnUp" data-pluginindex="' + i + '" icon="keyboard-arrow-up" title="' + Globalize.translate('ButtonUp') + '" style="padding:3px 8px;"></paper-icon-button>';
} else {
html += '<paper-icon-button disabled class="btnUp" data-pluginindex="' + i + '" icon="keyboard-arrow-up" title="' + Globalize.translate('ButtonUp') + '" style="padding:3px 8px;"></paper-icon-button>';
2014-02-11 14:41:01 -07:00
}
2015-09-06 12:09:36 -07:00
if (i < (plugins.length - 1)) {
html += '<paper-icon-button class="btnDown" data-pluginindex="' + i + '" icon="keyboard-arrow-down" title="' + Globalize.translate('ButtonDown') + '" style="padding:3px 8px;"></paper-icon-button>';
} else {
html += '<paper-icon-button disabled class="btnDown" data-pluginindex="' + i + '" icon="keyboard-arrow-down" title="' + Globalize.translate('ButtonDown') + '" style="padding:3px 8px;"></paper-icon-button>';
2014-02-10 21:55:01 -07:00
}
2014-02-11 14:41:01 -07:00
html += '</div>';
2014-02-10 21:55:01 -07:00
}
}
html += '</div>';
2014-08-15 09:35:41 -07:00
html += '<div class="fieldDescription" style="width:75%;">' + Globalize.translate('LabelImageFetchersHelp') + '</div>';
2014-02-11 14:41:01 -07:00
var elem = $('.imageFetchers', page).html(html).show().trigger('create');
$('.btnDown', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
var elemToMove = $('.imageFetcherGroup .ui-checkbox', page)[index];
var insertAfter = $(elemToMove).next('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertAfter(insertAfter);
});
$('.btnUp', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.imageFetcherGroup .ui-checkbox', page)[index];
var insertBefore = $(elemToMove).prev('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertBefore(insertBefore);
});
2014-02-02 06:36:31 -07:00
}
function renderMetadataSavers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'MetadataSaver';
});
var html = '';
if (!plugins.length) {
$('.metadataSavers', page).html(html).hide().trigger('create');
return;
}
2016-02-23 13:06:45 -07:00
html += '<div class="paperCheckboxListLabel">' + Globalize.translate('LabelMetadataSavers') + '</div>';
html += '<div class="paperCheckboxList">';
2014-02-02 06:36:31 -07:00
for (var i = 0, length = plugins.length; i < length; i++) {
var plugin = plugins[i];
var isChecked = config.DisabledMetadataSavers.indexOf(plugin.Name) == -1 ? ' checked="checked"' : '';
2016-02-23 13:06:45 -07:00
html += '<paper-checkbox class="chkMetadataSaver"' + isChecked + ' data-pluginname="' + plugin.Name + '">' + plugin.Name + '</paper-checkbox>';
2014-02-02 06:36:31 -07:00
}
2016-02-23 13:06:45 -07:00
html += '</div>';
html += '<div class="fieldDescription" style="margin-top:.25em;">' + Globalize.translate('LabelMetadataSaversHelp') + '</div>';
2014-02-02 06:36:31 -07:00
2016-02-23 13:06:45 -07:00
page.querySelector('.metadataSavers').innerHTML = html;
2014-02-02 06:36:31 -07:00
}
function renderMetadataFetchers(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'MetadataFetcher';
});
var html = '';
if (!plugins.length) {
$('.metadataFetchers', page).html(html).hide().trigger('create');
return;
}
2014-02-10 21:55:01 -07:00
var i, length, plugin, id;
2014-02-02 06:36:31 -07:00
2014-08-15 09:35:41 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">' + Globalize.translate('LabelMetadataDownloaders') + '</div>';
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
html += '<div style="display:inline-block;width: 75%;vertical-align:top;">';
html += '<div data-role="controlgroup" class="metadataFetcherGroup">';
2014-02-10 21:55:01 -07:00
for (i = 0, length = plugins.length; i < length; i++) {
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
plugin = plugins[i];
2014-02-02 06:36:31 -07:00
2014-02-10 21:55:01 -07:00
id = 'chkMetadataFetcher' + i;
var isChecked = config.DisabledMetadataFetchers.indexOf(plugin.Name) == -1 ? ' checked="checked"' : '';
html += '<input class="chkMetadataFetcher" type="checkbox" name="' + id + '" id="' + id + '" data-pluginname="' + plugin.Name + '" data-mini="true"' + isChecked + '>';
2014-02-02 06:36:31 -07:00
html += '<label for="' + id + '">' + plugin.Name + '</label>';
}
2014-02-10 21:55:01 -07:00
html += '</div>';
html += '</div>';
if (plugins.length > 1) {
html += '<div style="display:inline-block;vertical-align:top;margin-left:5px;">';
for (i = 0, length = plugins.length; i < length; i++) {
2015-12-14 08:43:03 -07:00
html += '<div>';
2015-09-06 12:09:36 -07:00
if (i > 0) {
html += '<paper-icon-button class="btnUp" data-pluginindex="' + i + '" icon="keyboard-arrow-up" title="' + Globalize.translate('ButtonUp') + '" style="padding:3px 8px;"></paper-icon-button>';
} else {
html += '<paper-icon-button disabled class="btnUp" data-pluginindex="' + i + '" icon="keyboard-arrow-up" title="' + Globalize.translate('ButtonUp') + '" style="padding:3px 8px;"></paper-icon-button>';
2014-02-11 14:41:01 -07:00
}
2015-09-06 12:09:36 -07:00
if (i < (plugins.length - 1)) {
html += '<paper-icon-button class="btnDown" data-pluginindex="' + i + '" icon="keyboard-arrow-down" title="' + Globalize.translate('ButtonDown') + '" style="padding:3px 8px;"></paper-icon-button>';
} else {
html += '<paper-icon-button disabled class="btnDown" data-pluginindex="' + i + '" icon="keyboard-arrow-down" title="' + Globalize.translate('ButtonDown') + '" style="padding:3px 8px;"></paper-icon-button>';
2014-02-10 21:55:01 -07:00
}
2014-02-11 14:41:01 -07:00
html += '</div>';
2014-02-10 21:55:01 -07:00
}
}
html += '</div>';
2014-08-15 09:35:41 -07:00
html += '<div class="fieldDescription" style="width:75%;">' + Globalize.translate('LabelMetadataDownloadersHelp') + '</div>';
2014-02-11 14:41:01 -07:00
var elem = $('.metadataFetchers', page).html(html).show().trigger('create');
$('.btnDown', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
2014-02-02 06:36:31 -07:00
2014-02-11 14:41:01 -07:00
var elemToMove = $('.metadataFetcherGroup .ui-checkbox', page)[index];
var insertAfter = $(elemToMove).next('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertAfter(insertAfter);
});
$('.btnUp', elem).on('click', function () {
var index = parseInt(this.getAttribute('data-pluginindex'));
var elemToMove = $('.metadataFetcherGroup .ui-checkbox', page)[index];
var insertBefore = $(elemToMove).prev('.ui-checkbox')[0];
elemToMove.parentNode.removeChild(elemToMove);
$(elemToMove).insertBefore(insertBefore);
});
2014-02-02 06:36:31 -07:00
}
function renderMetadataLocals(page, type, config, metadataInfo) {
var plugins = metadataInfo.Plugins.filter(function (p) {
return p.Type == 'LocalMetadataProvider';
});
var html = '';
2014-02-10 21:55:01 -07:00
if (plugins.length < 2) {
2014-02-02 06:36:31 -07:00
$('.metadataReaders', page).html(html).hide().trigger('create');
return;
}
2014-08-15 09:35:41 -07:00
html += '<div class="ui-controlgroup-label" style="margin-bottom:0;padding-left:2px;">' + Globalize.translate('LabelMetadataReaders') + '</div>';
2014-02-10 11:39:41 -07:00
html += '<ul data-role="listview" data-inset="true" data-mini="true" style="margin-top:.5em;margin-bottom:.5em;">';
2014-02-02 06:36:31 -07:00
for (var i = 0, length = plugins.length; i < length; i++) {
var plugin = plugins[i];
2014-08-18 18:42:53 -07:00
html += '<li data-mini="true" class="localReaderOption" data-pluginname="' + plugin.Name + '">';
2014-02-02 06:36:31 -07:00
2014-08-18 18:42:53 -07:00
if (i > 0) {
2016-03-12 13:16:42 -07:00
html += '<a href="#" style="font-weight:normal;">' + plugin.Name + '</a>';
2014-02-10 11:39:41 -07:00
2016-03-12 13:16:42 -07:00
html += '<a class="btnLocalReaderUp btnLocalReaderMove" data-pluginindex="' + i + '" href="#" style="font-weight:normal;" data-icon="arrow-u">' + Globalize.translate('ButtonUp') + '</a>';
2014-02-10 11:39:41 -07:00
}
else if (plugins.length > 1) {
2016-03-12 13:16:42 -07:00
html += '<a href="#" style="font-weight:normal;">' + plugin.Name + '</a>';
2014-02-10 11:39:41 -07:00
2016-03-12 13:16:42 -07:00
html += '<a class="btnLocalReaderDown btnLocalReaderMove" data-pluginindex="' + i + '" href="#" style="font-weight:normal;" data-icon="arrow-d">' + Globalize.translate('ButtonDown') + '</a>';
2014-02-10 11:39:41 -07:00
}
else {
html += plugin.Name;
}
2014-08-18 18:42:53 -07:00
html += '</li>';
2014-02-02 06:36:31 -07:00
}
2014-02-10 11:39:41 -07:00
html += '</ul>';
2014-08-15 09:35:41 -07:00
html += '<div class="fieldDescription">' + Globalize.translate('LabelMetadataReadersHelp') + '</div>';
2014-02-02 06:36:31 -07:00
2014-02-23 20:27:13 -07:00
$('.metadataReaders', page).html(html).show().trigger('create');
2014-02-02 06:36:31 -07:00
}
function loadPage(page) {
2014-05-12 11:04:25 -07:00
loadTabs(page, [
2014-08-15 09:35:41 -07:00
{ name: 'OptionMovies', type: 'Movie' },
2014-07-13 17:57:32 -07:00
//{ name: 'Trailers', type: 'Trailer' },
2014-08-15 09:35:41 -07:00
{ name: 'OptionCollections', type: 'BoxSet' },
{ name: 'OptionSeries', type: 'Series' },
{ name: 'OptionSeasons', type: 'Season' },
{ name: 'OptionEpisodes', type: 'Episode' },
{ name: 'OptionGames', type: 'Game' },
{ name: 'OptionGameSystems', type: 'GameSystem' },
2014-07-13 17:57:32 -07:00
//{ name: 'Game Genres', type: 'GameGenre' },
2014-08-15 09:35:41 -07:00
{ name: 'OptionMusicArtists', type: 'MusicArtist' },
{ name: 'OptionMusicAlbums', type: 'MusicAlbum' },
{ name: 'OptionMusicVideos', type: 'MusicVideo' },
2014-07-13 17:57:32 -07:00
//{ name: 'Music Genres', type: 'MusicGenre' },
2014-08-15 09:35:41 -07:00
{ name: 'OptionSongs', type: 'Audio' },
{ name: 'OptionHomeVideos', type: 'Video' },
{ name: 'OptionBooks', type: 'Book' },
{ name: 'OptionPeople', type: 'Person' }
2014-07-13 17:57:32 -07:00
//{ name: 'Genres', type: 'Genre' },
//{ name: 'Studios', type: 'Studio' }
2014-05-12 11:04:25 -07:00
]);
2014-02-02 06:36:31 -07:00
}
function saveSettingsIntoConfig(form, config) {
2016-02-23 13:06:45 -07:00
config.DisabledMetadataSavers = $('.chkMetadataSaver', form).get().filter(function (c) {
return !c.checked;
}).map(function (c) {
return c.getAttribute('data-pluginname');
});
2014-02-10 21:55:01 -07:00
config.LocalMetadataReaderOrder = $('.localReaderOption', form).get().map(function (c) {
return c.getAttribute('data-pluginname');
});
config.DisabledMetadataFetchers = $('.chkMetadataFetcher:not(:checked)', form).get().map(function (c) {
return c.getAttribute('data-pluginname');
});
config.MetadataFetcherOrder = $('.chkMetadataFetcher', form).get().map(function (c) {
return c.getAttribute('data-pluginname');
});
config.DisabledImageFetchers = $('.chkImageFetcher:not(:checked)', form).get().map(function (c) {
return c.getAttribute('data-pluginname');
});
config.ImageFetcherOrder = $('.chkImageFetcher', form).get().map(function (c) {
2014-02-10 11:39:41 -07:00
return c.getAttribute('data-pluginname');
});
2016-02-18 22:03:00 -07:00
config.ImageOptions = $('.imageType:not(.hide)', form).get().map(function (c) {
return {
2016-02-18 22:03:00 -07:00
Type: c.getAttribute('data-imagetype'),
Limit: c.checked ? 1 : 0,
MinWidth: 0
};
});
config.ImageOptions.push({
Type: 'Backdrop',
Limit: $('#txtMaxBackdrops', form).val(),
MinWidth: $('#txtMinBackdropDownloadWidth', form).val()
});
config.ImageOptions.push({
Type: 'Screenshot',
Limit: $('#txtMaxScreenshots', form).val(),
MinWidth: $('#txtMinScreenshotDownloadWidth', form).val()
});
}
2014-02-02 06:36:31 -07:00
function onSubmit() {
2013-02-20 18:33:05 -07:00
var form = this;
2013-04-16 21:58:32 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getServerConfiguration().then(function (config) {
2013-02-20 18:33:05 -07:00
var type = currentType;
var metadataOptions = config.MetadataOptions.filter(function (c) {
return c.ItemType == type;
})[0];
if (metadataOptions) {
saveSettingsIntoConfig(form, metadataOptions);
2015-12-14 08:43:03 -07:00
ApiClient.updateServerConfiguration(config).then(Dashboard.processServerConfigurationUpdateResult);
} else {
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl("System/Configuration/MetadataOptions/Default")).then(function (defaultOptions) {
defaultOptions.ItemType = type;
config.MetadataOptions.push(defaultOptions);
saveSettingsIntoConfig(form, defaultOptions);
2015-12-14 08:43:03 -07:00
ApiClient.updateServerConfiguration(config).then(Dashboard.processServerConfigurationUpdateResult);
});
}
2013-02-20 18:33:05 -07:00
});
// Disable default form submission
return false;
}
2016-04-12 23:02:07 -07:00
function getTabs() {
return [
{
href: 'metadata.html',
name: Globalize.translate('TabSettings')
},
{
href: 'metadataimages.html',
name: Globalize.translate('TabServices')
},
{
href: 'metadatanfo.html',
name: Globalize.translate('TabNfoSettings')
}];
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#metadataImagesConfigurationPage", function () {
2014-02-23 20:27:13 -07:00
var page = this;
$('.metadataReaders', page).on('click', '.btnLocalReaderMove', function () {
var li = $(this).parents('.localReaderOption');
var ul = li.parents('ul');
if ($(this).hasClass('btnLocalReaderDown')) {
var next = li.next();
li.remove().insertAfter(next);
} else {
var prev = li.prev();
li.remove().insertBefore(prev);
}
$('.localReaderOption', ul).each(function () {
if ($(this).prev('.localReaderOption').length) {
$('.btnLocalReaderMove', this).addClass('btnLocalReaderUp').removeClass('btnLocalReaderDown').attr('data-icon', 'arrow-u').removeClass('ui-icon-arrow-d').addClass('ui-icon-arrow-u');
} else {
$('.btnLocalReaderMove', this).addClass('btnLocalReaderDown').removeClass('btnLocalReaderUp').attr('data-icon', 'arrow-d').removeClass('ui-icon-arrow-u').addClass('ui-icon-arrow-d');
}
});
});
2014-05-12 11:04:25 -07:00
$('#selectItemType', page).on('change', function () {
loadType(page, this.value);
});
2015-06-08 14:32:20 -07:00
$('.metadataImagesConfigurationForm').off('submit', onSubmit).on('submit', onSubmit);
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#metadataImagesConfigurationPage", function () {
2014-02-02 06:36:31 -07:00
2016-04-12 23:02:07 -07:00
LibraryMenu.setTabs('metadata', 1, getTabs);
2014-02-02 06:36:31 -07:00
Dashboard.showLoadingMsg();
var page = this;
loadPage(page);
});
});