1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/libraryoptionseditor/libraryoptionseditor.js

612 lines
32 KiB
JavaScript
Raw Normal View History

/* eslint-disable indent */
/**
* Module for library options editor.
* @module components/libraryoptionseditor/libraryoptionseditor
*/
2022-01-30 00:27:26 +03:00
import escapeHtml from 'escape-html';
2020-08-14 08:46:34 +02:00
import globalize from '../../scripts/globalize';
import dom from '../../scripts/dom';
import '../../elements/emby-checkbox/emby-checkbox';
import '../../elements/emby-select/emby-select';
import '../../elements/emby-input/emby-input';
import './style.scss';
2020-11-25 00:17:24 -05:00
import template from './libraryoptionseditor.template.html';
2018-10-23 01:05:09 +03:00
function populateLanguages(parent) {
return ApiClient.getCultures().then(languages => {
2020-05-04 12:44:12 +02:00
populateLanguagesIntoSelect(parent.querySelector('#selectLanguage'), languages);
populateLanguagesIntoList(parent.querySelector('.subtitleDownloadLanguages'), languages);
2019-05-06 17:26:18 -07:00
});
2018-10-23 01:05:09 +03:00
}
function populateLanguagesIntoSelect(select, languages) {
let html = '';
2018-10-23 01:05:09 +03:00
html += "<option value=''></option>";
for (let i = 0; i < languages.length; i++) {
const culture = languages[i];
html += `<option value='${culture.TwoLetterISOLanguageName}'>${culture.DisplayName}</option>`;
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
select.innerHTML = html;
2018-10-23 01:05:09 +03:00
}
function populateLanguagesIntoList(element, languages) {
let html = '';
for (let i = 0; i < languages.length; i++) {
const culture = languages[i];
html += `<label><input type="checkbox" is="emby-checkbox" class="chkSubtitleLanguage" data-lang="${culture.ThreeLetterISOLanguageName.toLowerCase()}" /><span>${culture.DisplayName}</span></label>`;
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
element.innerHTML = html;
2018-10-23 01:05:09 +03:00
}
function populateCountries(select) {
return ApiClient.getCountries().then(allCountries => {
let html = '';
2018-10-23 01:05:09 +03:00
html += "<option value=''></option>";
for (let i = 0; i < allCountries.length; i++) {
const culture = allCountries[i];
html += `<option value='${culture.TwoLetterISORegionName}'>${culture.DisplayName}</option>`;
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
select.innerHTML = html;
});
2018-10-23 01:05:09 +03:00
}
function populateRefreshInterval(select) {
let html = '';
html += `<option value='0'>${globalize.translate('Never')}</option>`;
html += [30, 60, 90].map(val => {
return `<option value='${val}'>${globalize.translate('EveryNDays', val)}</option>`;
2020-05-04 12:44:12 +02:00
}).join('');
2019-05-06 17:26:18 -07:00
select.innerHTML = html;
2018-10-23 01:05:09 +03:00
}
function renderMetadataReaders(page, plugins) {
let html = '';
const elem = page.querySelector('.metadataReaders');
2019-05-06 17:26:18 -07:00
if (plugins.length < 1) {
elem.innerHTML = '';
2022-05-20 13:34:25 -07:00
elem.classList.add('hide');
return false;
}
html += `<h3 class="checkboxListLabel">${globalize.translate('LabelMetadataReaders')}</h3>`;
2019-05-06 17:26:18 -07:00
html += '<div class="checkboxList paperList checkboxList-paperList">';
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
2022-01-30 00:27:26 +03:00
html += `<div class="listItem localReaderOption sortableOption" data-pluginname="${escapeHtml(plugin.Name)}">`;
2022-02-24 20:15:24 +03:00
html += '<span class="listItemIcon material-icons live_tv" aria-hidden="true"></span>';
2019-05-06 17:26:18 -07:00
html += '<div class="listItemBody">';
html += '<h3 class="listItemBodyText">';
2022-01-30 00:27:26 +03:00
html += escapeHtml(plugin.Name);
2020-05-04 12:44:12 +02:00
html += '</h3>';
html += '</div>';
2019-05-06 17:26:18 -07:00
if (i > 0) {
2022-02-24 20:15:24 +03:00
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Up')}" class="btnSortableMoveUp btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_up" aria-hidden="true"></span></button>`;
2019-05-06 17:26:18 -07:00
} else if (plugins.length > 1) {
2022-02-24 20:15:24 +03:00
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Down')}" class="btnSortableMoveDown btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_down" aria-hidden="true"></span></button>`;
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += `<div class="fieldDescription">${globalize.translate('LabelMetadataReadersHelp')}</div>`;
2019-05-06 17:26:18 -07:00
if (plugins.length < 2) {
2020-05-04 12:44:12 +02:00
elem.classList.add('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
elem.classList.remove('hide');
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
elem.innerHTML = html;
return true;
2018-10-23 01:05:09 +03:00
}
function renderMetadataSavers(page, metadataSavers) {
let html = '';
const elem = page.querySelector('.metadataSavers');
if (!metadataSavers.length) {
elem.innerHTML = '';
elem.classList.add('hide');
return false;
}
html += `<h3 class="checkboxListLabel">${globalize.translate('LabelMetadataSavers')}</h3>`;
2019-05-06 17:26:18 -07:00
html += '<div class="checkboxList paperList checkboxList-paperList">';
for (let i = 0; i < metadataSavers.length; i++) {
const plugin = metadataSavers[i];
2022-01-30 00:27:26 +03:00
html += `<label><input type="checkbox" data-defaultenabled="${plugin.DefaultEnabled}" is="emby-checkbox" class="chkMetadataSaver" data-pluginname="${escapeHtml(plugin.Name)}" ${false}><span>${escapeHtml(plugin.Name)}</span></label>`;
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += `<div class="fieldDescription" style="margin-top:.25em;">${globalize.translate('LabelMetadataSaversHelp')}</div>`;
2019-05-06 17:26:18 -07:00
elem.innerHTML = html;
2020-05-04 12:44:12 +02:00
elem.classList.remove('hide');
2019-05-06 17:26:18 -07:00
return true;
2018-10-23 01:05:09 +03:00
}
function getMetadataFetchersForTypeHtml(availableTypeOptions, libraryOptionsForType) {
let html = '';
let plugins = availableTypeOptions.MetadataFetchers;
2019-05-06 17:26:18 -07:00
plugins = getOrderedPlugins(plugins, libraryOptionsForType.MetadataFetcherOrder || []);
if (!plugins.length) return html;
html += '<div class="metadataFetcher" data-type="' + availableTypeOptions.Type + '">';
html += '<h3 class="checkboxListLabel">' + globalize.translate('LabelTypeMetadataDownloaders', globalize.translate('TypeOptionPlural' + availableTypeOptions.Type)) + '</h3>';
2019-05-06 17:26:18 -07:00
html += '<div class="checkboxList paperList checkboxList-paperList">';
2020-04-14 07:00:47 +02:00
plugins.forEach((plugin, index) => {
2022-01-30 00:27:26 +03:00
html += '<div class="listItem metadataFetcherItem sortableOption" data-pluginname="' + escapeHtml(plugin.Name) + '">';
const isChecked = libraryOptionsForType.MetadataFetchers ? libraryOptionsForType.MetadataFetchers.includes(plugin.Name) : plugin.DefaultEnabled;
const checkedHtml = isChecked ? ' checked="checked"' : '';
2022-01-30 00:27:26 +03:00
html += '<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkMetadataFetcher" data-pluginname="' + escapeHtml(plugin.Name) + '" ' + checkedHtml + '><span></span></label>';
2019-05-06 17:26:18 -07:00
html += '<div class="listItemBody">';
html += '<h3 class="listItemBodyText">';
2022-01-30 00:27:26 +03:00
html += escapeHtml(plugin.Name);
2020-05-04 12:44:12 +02:00
html += '</h3>';
html += '</div>';
2020-05-14 23:25:22 +02:00
if (index > 0) {
2022-02-24 20:15:24 +03:00
html += '<button type="button" is="paper-icon-button-light" title="' + globalize.translate('Up') + '" class="btnSortableMoveUp btnSortable" data-pluginindex="' + index + '"><span class="material-icons keyboard_arrow_up" aria-hidden="true"></span></button>';
2020-05-14 23:25:22 +02:00
} else if (plugins.length > 1) {
2022-02-24 20:15:24 +03:00
html += '<button type="button" is="paper-icon-button-light" title="' + globalize.translate('Down') + '" class="btnSortableMoveDown btnSortable" data-pluginindex="' + index + '"><span class="material-icons keyboard_arrow_down" aria-hidden="true"></span></button>';
2020-05-14 23:25:22 +02:00
}
html += '</div>';
2020-04-14 07:00:47 +02:00
});
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '<div class="fieldDescription">' + globalize.translate('LabelMetadataDownloadersHelp') + '</div>';
html += '</div>';
2019-05-06 17:26:18 -07:00
return html;
2018-10-23 01:05:09 +03:00
}
function getTypeOptions(allOptions, type) {
const allTypeOptions = allOptions.TypeOptions || [];
for (let i = 0; i < allTypeOptions.length; i++) {
const typeOptions = allTypeOptions[i];
2019-05-06 17:26:18 -07:00
if (typeOptions.Type === type) return typeOptions;
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
return null;
2018-10-23 01:05:09 +03:00
}
function renderMetadataFetchers(page, availableOptions, libraryOptions) {
let html = '';
const elem = page.querySelector('.metadataFetchers');
for (let i = 0; i < availableOptions.TypeOptions.length; i++) {
const availableTypeOptions = availableOptions.TypeOptions[i];
2019-05-06 17:26:18 -07:00
html += getMetadataFetchersForTypeHtml(availableTypeOptions, getTypeOptions(libraryOptions, availableTypeOptions.Type) || {});
}
elem.innerHTML = html;
if (html) {
2020-05-04 12:44:12 +02:00
elem.classList.remove('hide');
page.querySelector('.fldAutoRefreshInterval').classList.remove('hide');
page.querySelector('.fldMetadataLanguage').classList.remove('hide');
page.querySelector('.fldMetadataCountry').classList.remove('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
elem.classList.add('hide');
page.querySelector('.fldAutoRefreshInterval').classList.add('hide');
page.querySelector('.fldMetadataLanguage').classList.add('hide');
page.querySelector('.fldMetadataCountry').classList.add('hide');
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
return true;
2018-10-23 01:05:09 +03:00
}
function renderSubtitleFetchers(page, availableOptions, libraryOptions) {
let html = '';
const elem = page.querySelector('.subtitleFetchers');
2019-05-06 17:26:18 -07:00
let plugins = availableOptions.SubtitleFetchers;
2019-05-06 17:26:18 -07:00
plugins = getOrderedPlugins(plugins, libraryOptions.SubtitleFetcherOrder || []);
if (!plugins.length) return html;
html += `<h3 class="checkboxListLabel">${globalize.translate('LabelSubtitleDownloaders')}</h3>`;
2019-05-06 17:26:18 -07:00
html += '<div class="checkboxList paperList checkboxList-paperList">';
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
2022-01-30 00:27:26 +03:00
html += `<div class="listItem subtitleFetcherItem sortableOption" data-pluginname="${escapeHtml(plugin.Name)}">`;
const isChecked = libraryOptions.DisabledSubtitleFetchers ? !libraryOptions.DisabledSubtitleFetchers.includes(plugin.Name) : plugin.DefaultEnabled;
const checkedHtml = isChecked ? ' checked="checked"' : '';
2022-01-30 00:27:26 +03:00
html += `<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkSubtitleFetcher" data-pluginname="${escapeHtml(plugin.Name)}" ${checkedHtml}><span></span></label>`;
2019-05-06 17:26:18 -07:00
html += '<div class="listItemBody">';
html += '<h3 class="listItemBodyText">';
2022-01-30 00:27:26 +03:00
html += escapeHtml(plugin.Name);
2020-05-04 12:44:12 +02:00
html += '</h3>';
html += '</div>';
2019-05-06 17:26:18 -07:00
if (i > 0) {
2022-02-24 20:15:24 +03:00
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Up')}" class="btnSortableMoveUp btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_up" aria-hidden="true"></span></button>`;
2019-05-06 17:26:18 -07:00
} else if (plugins.length > 1) {
2022-02-24 20:15:24 +03:00
html += `<button type="button" is="paper-icon-button-light" title="${globalize.translate('Down')}" class="btnSortableMoveDown btnSortable" data-pluginindex="${i}"><span class="material-icons keyboard_arrow_down" aria-hidden="true"></span></button>`;
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += `<div class="fieldDescription">${globalize.translate('SubtitleDownloadersHelp')}</div>`;
2019-05-06 17:26:18 -07:00
elem.innerHTML = html;
2018-10-23 01:05:09 +03:00
}
function getImageFetchersForTypeHtml(availableTypeOptions, libraryOptionsForType) {
let html = '';
let plugins = availableTypeOptions.ImageFetchers;
2019-05-06 17:26:18 -07:00
plugins = getOrderedPlugins(plugins, libraryOptionsForType.ImageFetcherOrder || []);
if (!plugins.length) return html;
html += '<div class="imageFetcher" data-type="' + availableTypeOptions.Type + '">';
html += '<div class="flex align-items-center" style="margin:1.5em 0 .5em;">';
html += '<h3 class="checkboxListLabel" style="margin:0;">' + globalize.translate('HeaderTypeImageFetchers', globalize.translate('TypeOptionPlural' + availableTypeOptions.Type)) + '</h3>';
const supportedImageTypes = availableTypeOptions.SupportedImageTypes || [];
2020-07-30 16:07:13 +02:00
if (supportedImageTypes.length > 1 || supportedImageTypes.length === 1 && supportedImageTypes[0] !== 'Primary') {
html += '<button is="emby-button" class="raised btnImageOptionsForType" type="button" style="font-size:90%;"><span>' + globalize.translate('HeaderFetcherSettings') + '</span></button>';
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-05-06 17:26:18 -07:00
html += '<div class="checkboxList paperList checkboxList-paperList">';
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
2022-01-30 00:27:26 +03:00
html += '<div class="listItem imageFetcherItem sortableOption" data-pluginname="' + escapeHtml(plugin.Name) + '">';
const isChecked = libraryOptionsForType.ImageFetchers ? libraryOptionsForType.ImageFetchers.includes(plugin.Name) : plugin.DefaultEnabled;
const checkedHtml = isChecked ? ' checked="checked"' : '';
2022-01-30 00:27:26 +03:00
html += '<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkImageFetcher" data-pluginname="' + escapeHtml(plugin.Name) + '" ' + checkedHtml + '><span></span></label>';
2019-05-06 17:26:18 -07:00
html += '<div class="listItemBody">';
html += '<h3 class="listItemBodyText">';
2022-01-30 00:27:26 +03:00
html += escapeHtml(plugin.Name);
2020-05-04 12:44:12 +02:00
html += '</h3>';
html += '</div>';
2019-05-06 17:26:18 -07:00
if (i > 0) {
2022-02-24 20:15:24 +03:00
html += '<button type="button" is="paper-icon-button-light" title="' + globalize.translate('Up') + '" class="btnSortableMoveUp btnSortable" data-pluginindex="' + i + '"><span class="material-icons keyboard_arrow_up" aria-hidden="true"></span></button>';
2019-05-06 17:26:18 -07:00
} else if (plugins.length > 1) {
2022-02-24 20:15:24 +03:00
html += '<button type="button" is="paper-icon-button-light" title="' + globalize.translate('Down') + '" class="btnSortableMoveDown btnSortable" data-pluginindex="' + i + '"><span class="material-icons keyboard_arrow_down" aria-hidden="true"></span></button>';
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '<div class="fieldDescription">' + globalize.translate('LabelImageFetchersHelp') + '</div>';
html += '</div>';
2019-05-06 17:26:18 -07:00
return html;
2018-10-23 01:05:09 +03:00
}
function renderImageFetchers(page, availableOptions, libraryOptions) {
let html = '';
const elem = page.querySelector('.imageFetchers');
for (let i = 0; i < availableOptions.TypeOptions.length; i++) {
const availableTypeOptions = availableOptions.TypeOptions[i];
2019-05-06 17:26:18 -07:00
html += getImageFetchersForTypeHtml(availableTypeOptions, getTypeOptions(libraryOptions, availableTypeOptions.Type) || {});
}
elem.innerHTML = html;
if (html) {
2020-05-04 12:44:12 +02:00
elem.classList.remove('hide');
page.querySelector('.chkSaveLocalContainer').classList.remove('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
elem.classList.add('hide');
page.querySelector('.chkSaveLocalContainer').classList.add('hide');
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
return true;
2018-10-23 01:05:09 +03:00
}
2020-06-11 22:07:24 +03:00
function populateMetadataSettings(parent, contentType) {
const isNewLibrary = parent.classList.contains('newlibrary');
2020-05-04 12:44:12 +02:00
return ApiClient.getJSON(ApiClient.getUrl('Libraries/AvailableOptions', {
2018-10-23 01:05:09 +03:00
LibraryContentType: contentType,
IsNewLibrary: isNewLibrary
})).then(availableOptions => {
2019-05-06 17:26:18 -07:00
currentAvailableOptions = availableOptions;
parent.availableOptions = availableOptions;
renderMetadataSavers(parent, availableOptions.MetadataSavers);
renderMetadataReaders(parent, availableOptions.MetadataReaders);
renderMetadataFetchers(parent, availableOptions, {});
renderSubtitleFetchers(parent, availableOptions, {});
renderImageFetchers(parent, availableOptions, {});
2020-05-04 12:44:12 +02:00
availableOptions.SubtitleFetchers.length ? parent.querySelector('.subtitleDownloadSettings').classList.remove('hide') : parent.querySelector('.subtitleDownloadSettings').classList.add('hide');
}).catch(() => {
2019-05-06 17:26:18 -07:00
return Promise.resolve();
});
2018-10-23 01:05:09 +03:00
}
function adjustSortableListElement(elem) {
const btnSortable = elem.querySelector('.btnSortable');
const inner = btnSortable.querySelector('.material-icons');
2019-05-06 17:26:18 -07:00
if (elem.previousSibling) {
2020-08-13 21:31:29 +09:00
btnSortable.title = globalize.translate('Up');
2020-05-04 12:44:12 +02:00
btnSortable.classList.add('btnSortableMoveUp');
btnSortable.classList.remove('btnSortableMoveDown');
inner.classList.remove('keyboard_arrow_down');
inner.classList.add('keyboard_arrow_up');
2019-05-06 17:26:18 -07:00
} else {
2020-08-13 21:31:29 +09:00
btnSortable.title = globalize.translate('Down');
2020-05-04 12:44:12 +02:00
btnSortable.classList.remove('btnSortableMoveUp');
btnSortable.classList.add('btnSortableMoveDown');
inner.classList.remove('keyboard_arrow_up');
inner.classList.add('keyboard_arrow_down');
2019-05-06 17:26:18 -07:00
}
2018-10-23 01:05:09 +03:00
}
function showImageOptionsForType(type) {
2020-08-14 08:46:34 +02:00
import('../imageOptionsEditor/imageOptionsEditor').then(({default: ImageOptionsEditor}) => {
let typeOptions = getTypeOptions(currentLibraryOptions, type);
2020-04-14 07:00:47 +02:00
if (!typeOptions) {
typeOptions = {
Type: type
};
2020-04-25 22:37:06 +02:00
currentLibraryOptions.TypeOptions.push(typeOptions);
2020-04-14 07:00:47 +02:00
}
const availableOptions = getTypeOptions(currentAvailableOptions || {}, type);
2020-07-23 03:07:53 +03:00
const imageOptionsEditor = new ImageOptionsEditor();
imageOptionsEditor.show(type, typeOptions, availableOptions);
});
2018-10-23 01:05:09 +03:00
}
function onImageFetchersContainerClick(e) {
const btnImageOptionsForType = dom.parentWithClass(e.target, 'btnImageOptionsForType');
2018-10-23 01:05:09 +03:00
if (btnImageOptionsForType) {
2022-04-08 19:10:11 -07:00
showImageOptionsForType(dom.parentWithClass(btnImageOptionsForType, 'imageFetcher').getAttribute('data-type'));
return;
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
onSortableContainerClick.call(this, e);
2018-10-23 01:05:09 +03:00
}
function onSortableContainerClick(e) {
const btnSortable = dom.parentWithClass(e.target, 'btnSortable');
2018-10-23 01:05:09 +03:00
if (btnSortable) {
const li = dom.parentWithClass(btnSortable, 'sortableOption');
const list = dom.parentWithClass(li, 'paperList');
2020-05-04 12:44:12 +02:00
if (btnSortable.classList.contains('btnSortableMoveDown')) {
const next = li.nextSibling;
2020-04-14 07:00:47 +02:00
if (next) {
li.parentNode.removeChild(li);
next.parentNode.insertBefore(li, next.nextSibling);
}
2018-10-23 01:05:09 +03:00
} else {
const prev = li.previousSibling;
2020-04-14 07:00:47 +02:00
if (prev) {
li.parentNode.removeChild(li);
prev.parentNode.insertBefore(li, prev);
2020-04-25 22:37:06 +02:00
}
2018-10-23 01:05:09 +03:00
}
2020-05-04 12:44:12 +02:00
Array.prototype.forEach.call(list.querySelectorAll('.sortableOption'), adjustSortableListElement);
2018-10-23 01:05:09 +03:00
}
}
function bindEvents(parent) {
2020-05-04 12:44:12 +02:00
parent.querySelector('.metadataReaders').addEventListener('click', onSortableContainerClick);
parent.querySelector('.subtitleFetchers').addEventListener('click', onSortableContainerClick);
parent.querySelector('.metadataFetchers').addEventListener('click', onSortableContainerClick);
parent.querySelector('.imageFetchers').addEventListener('click', onImageFetchersContainerClick);
2018-10-23 01:05:09 +03:00
}
2020-07-23 03:07:53 +03:00
export async function embed(parent, contentType, libraryOptions) {
2018-10-23 01:05:09 +03:00
currentLibraryOptions = {
TypeOptions: []
2019-05-06 17:26:18 -07:00
};
currentAvailableOptions = null;
2020-07-30 16:07:13 +02:00
const isNewLibrary = libraryOptions === null;
2020-05-04 12:44:12 +02:00
isNewLibrary && parent.classList.add('newlibrary');
2020-11-08 12:37:53 +00:00
parent.innerHTML = globalize.translateHtml(template);
2020-07-23 03:07:53 +03:00
populateRefreshInterval(parent.querySelector('#selectAutoRefreshInterval'));
const promises = [populateLanguages(parent), populateCountries(parent.querySelector('#selectCountry'))];
Promise.all(promises).then(function() {
return setContentType(parent, contentType).then(function() {
libraryOptions && setLibraryOptions(parent, libraryOptions);
bindEvents(parent);
});
2019-05-06 17:26:18 -07:00
});
2018-10-23 01:05:09 +03:00
}
export function setContentType(parent, contentType) {
2020-05-04 12:44:12 +02:00
if (contentType === 'homevideos' || contentType === 'photos') {
parent.querySelector('.chkEnablePhotosContainer').classList.remove('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
parent.querySelector('.chkEnablePhotosContainer').classList.add('hide');
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
if (contentType !== 'tvshows' && contentType !== 'movies' && contentType !== 'homevideos' && contentType !== 'musicvideos' && contentType !== 'mixed') {
parent.querySelector('.chapterSettingsSection').classList.add('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
parent.querySelector('.chapterSettingsSection').classList.remove('hide');
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
if (contentType === 'tvshows') {
parent.querySelector('.chkAutomaticallyGroupSeriesContainer').classList.remove('hide');
parent.querySelector('.fldSeasonZeroDisplayName').classList.remove('hide');
parent.querySelector('#txtSeasonZeroName').setAttribute('required', 'required');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
parent.querySelector('.chkAutomaticallyGroupSeriesContainer').classList.add('hide');
parent.querySelector('.fldSeasonZeroDisplayName').classList.add('hide');
parent.querySelector('#txtSeasonZeroName').removeAttribute('required');
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
if (contentType === 'books' || contentType === 'boxsets' || contentType === 'playlists' || contentType === 'music') {
parent.querySelector('.chkEnableEmbeddedTitlesContainer').classList.add('hide');
2019-05-06 17:26:18 -07:00
} else {
2020-05-04 12:44:12 +02:00
parent.querySelector('.chkEnableEmbeddedTitlesContainer').classList.remove('hide');
2019-05-06 17:26:18 -07:00
}
2020-05-04 12:44:12 +02:00
if (contentType === 'tvshows') {
parent.querySelector('.chkEnableEmbeddedEpisodeInfosContainer').classList.remove('hide');
} else {
2020-05-04 12:44:12 +02:00
parent.querySelector('.chkEnableEmbeddedEpisodeInfosContainer').classList.add('hide');
}
if (contentType === 'tvshows' || contentType === 'movies' || contentType === 'musicvideos' || contentType === 'mixed') {
parent.querySelector('.fldAllowEmbeddedSubtitlesContainer').classList.remove('hide');
} else {
parent.querySelector('.fldAllowEmbeddedSubtitlesContainer').classList.add('hide');
}
2022-02-12 20:10:12 +00:00
parent.querySelector('.chkAutomaticallyAddToCollectionContainer').classList.toggle('hide', contentType !== 'movies' && contentType !== 'mixed');
2019-05-06 17:26:18 -07:00
return populateMetadataSettings(parent, contentType);
2018-10-23 01:05:09 +03:00
}
function setSubtitleFetchersIntoOptions(parent, options) {
options.DisabledSubtitleFetchers = Array.prototype.map.call(Array.prototype.filter.call(parent.querySelectorAll('.chkSubtitleFetcher'), elem => {
return !elem.checked;
}), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
options.SubtitleFetcherOrder = Array.prototype.map.call(parent.querySelectorAll('.subtitleFetcherItem'), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
2018-10-23 01:05:09 +03:00
}
function setMetadataFetchersIntoOptions(parent, options) {
const sections = parent.querySelectorAll('.metadataFetcher');
for (let i = 0; i < sections.length; i++) {
const section = sections[i];
const type = section.getAttribute('data-type');
let typeOptions = getTypeOptions(options, type);
2019-05-06 17:26:18 -07:00
if (!typeOptions) {
typeOptions = {
Type: type
};
options.TypeOptions.push(typeOptions);
}
typeOptions.MetadataFetchers = Array.prototype.map.call(Array.prototype.filter.call(section.querySelectorAll('.chkMetadataFetcher'), elem => {
2019-05-06 17:26:18 -07:00
return elem.checked;
}), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
typeOptions.MetadataFetcherOrder = Array.prototype.map.call(section.querySelectorAll('.metadataFetcherItem'), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
2018-10-23 01:05:09 +03:00
}
}
function setImageFetchersIntoOptions(parent, options) {
const sections = parent.querySelectorAll('.imageFetcher');
for (let i = 0; i < sections.length; i++) {
const section = sections[i];
const type = section.getAttribute('data-type');
let typeOptions = getTypeOptions(options, type);
2019-05-06 17:26:18 -07:00
if (!typeOptions) {
typeOptions = {
Type: type
};
options.TypeOptions.push(typeOptions);
}
typeOptions.ImageFetchers = Array.prototype.map.call(Array.prototype.filter.call(section.querySelectorAll('.chkImageFetcher'), elem => {
return elem.checked;
}), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
typeOptions.ImageFetcherOrder = Array.prototype.map.call(section.querySelectorAll('.imageFetcherItem'), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
2018-10-23 01:05:09 +03:00
}
}
function setImageOptionsIntoOptions(options) {
const originalTypeOptions = (currentLibraryOptions || {}).TypeOptions || [];
for (let i = 0; i < originalTypeOptions.length; i++) {
const originalTypeOption = originalTypeOptions[i];
let typeOptions = getTypeOptions(options, originalTypeOption.Type);
2019-05-06 17:26:18 -07:00
if (!typeOptions) {
typeOptions = {
Type: originalTypeOption.Type
2019-05-06 17:26:18 -07:00
};
options.TypeOptions.push(typeOptions);
}
originalTypeOption.ImageOptions && (typeOptions.ImageOptions = originalTypeOption.ImageOptions);
2018-10-23 01:05:09 +03:00
}
}
export function getLibraryOptions(parent) {
const options = {
2019-05-06 17:26:18 -07:00
EnableArchiveMediaFiles: false,
2020-05-04 12:44:12 +02:00
EnablePhotos: parent.querySelector('.chkEnablePhotos').checked,
EnableRealtimeMonitor: parent.querySelector('.chkEnableRealtimeMonitor').checked,
ExtractChapterImagesDuringLibraryScan: parent.querySelector('.chkExtractChaptersDuringLibraryScan').checked,
EnableChapterImageExtraction: parent.querySelector('.chkExtractChapterImages').checked,
2019-05-06 17:26:18 -07:00
EnableInternetProviders: true,
2020-05-04 12:44:12 +02:00
SaveLocalMetadata: parent.querySelector('#chkSaveLocal').checked,
EnableAutomaticSeriesGrouping: parent.querySelector('.chkAutomaticallyGroupSeries').checked,
PreferredMetadataLanguage: parent.querySelector('#selectLanguage').value,
MetadataCountryCode: parent.querySelector('#selectCountry').value,
SeasonZeroDisplayName: parent.querySelector('#txtSeasonZeroName').value,
AutomaticRefreshIntervalDays: parseInt(parent.querySelector('#selectAutoRefreshInterval').value),
EnableEmbeddedTitles: parent.querySelector('#chkEnableEmbeddedTitles').checked,
EnableEmbeddedEpisodeInfos: parent.querySelector('#chkEnableEmbeddedEpisodeInfos').checked,
AllowEmbeddedSubtitles: parent.querySelector('#selectAllowEmbeddedSubtitles').value,
2020-05-04 12:44:12 +02:00
SkipSubtitlesIfEmbeddedSubtitlesPresent: parent.querySelector('#chkSkipIfGraphicalSubsPresent').checked,
SkipSubtitlesIfAudioTrackMatches: parent.querySelector('#chkSkipIfAudioTrackPresent').checked,
SaveSubtitlesWithMedia: parent.querySelector('#chkSaveSubtitlesLocally').checked,
RequirePerfectSubtitleMatch: parent.querySelector('#chkRequirePerfectMatch').checked,
AutomaticallyAddToCollection: parent.querySelector('#chkAutomaticallyAddToCollection').checked,
MetadataSavers: Array.prototype.map.call(Array.prototype.filter.call(parent.querySelectorAll('.chkMetadataSaver'), elem => {
return elem.checked;
}), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2018-10-23 01:05:09 +03:00
}),
TypeOptions: []
};
2019-05-06 17:26:18 -07:00
options.LocalMetadataReaderOrder = Array.prototype.map.call(parent.querySelectorAll('.localReaderOption'), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-pluginname');
2019-05-06 17:26:18 -07:00
});
options.SubtitleDownloadLanguages = Array.prototype.map.call(Array.prototype.filter.call(parent.querySelectorAll('.chkSubtitleLanguage'), elem => {
return elem.checked;
}), elem => {
2020-05-04 12:44:12 +02:00
return elem.getAttribute('data-lang');
2019-05-06 17:26:18 -07:00
});
setSubtitleFetchersIntoOptions(parent, options);
setMetadataFetchersIntoOptions(parent, options);
setImageFetchersIntoOptions(parent, options);
setImageOptionsIntoOptions(options);
2019-05-06 17:26:18 -07:00
return options;
2018-10-23 01:05:09 +03:00
}
function getOrderedPlugins(plugins, configuredOrder) {
2019-05-06 17:26:18 -07:00
plugins = plugins.slice(0);
plugins.sort((a, b) => {
a = configuredOrder.indexOf(a.Name);
b = configuredOrder.indexOf(b.Name);
return a - b;
2019-05-06 17:26:18 -07:00
});
return plugins;
2018-10-23 01:05:09 +03:00
}
export function setLibraryOptions(parent, options) {
2019-05-06 17:26:18 -07:00
currentLibraryOptions = options;
currentAvailableOptions = parent.availableOptions;
2020-05-04 12:44:12 +02:00
parent.querySelector('#selectLanguage').value = options.PreferredMetadataLanguage || '';
parent.querySelector('#selectCountry').value = options.MetadataCountryCode || '';
parent.querySelector('#selectAutoRefreshInterval').value = options.AutomaticRefreshIntervalDays || '0';
parent.querySelector('#txtSeasonZeroName').value = options.SeasonZeroDisplayName || 'Specials';
parent.querySelector('.chkEnablePhotos').checked = options.EnablePhotos;
parent.querySelector('.chkEnableRealtimeMonitor').checked = options.EnableRealtimeMonitor;
parent.querySelector('.chkExtractChaptersDuringLibraryScan').checked = options.ExtractChapterImagesDuringLibraryScan;
parent.querySelector('.chkExtractChapterImages').checked = options.EnableChapterImageExtraction;
parent.querySelector('#chkSaveLocal').checked = options.SaveLocalMetadata;
parent.querySelector('.chkAutomaticallyGroupSeries').checked = options.EnableAutomaticSeriesGrouping;
parent.querySelector('#chkEnableEmbeddedTitles').checked = options.EnableEmbeddedTitles;
parent.querySelector('#chkEnableEmbeddedEpisodeInfos').value = options.EnableEmbeddedEpisodeInfos;
2022-02-12 20:10:12 +00:00
parent.querySelector('#selectAllowEmbeddedSubtitles').value = options.AllowEmbeddedSubtitles;
2020-05-04 12:44:12 +02:00
parent.querySelector('#chkSkipIfGraphicalSubsPresent').checked = options.SkipSubtitlesIfEmbeddedSubtitlesPresent;
parent.querySelector('#chkSaveSubtitlesLocally').checked = options.SaveSubtitlesWithMedia;
parent.querySelector('#chkSkipIfAudioTrackPresent').checked = options.SkipSubtitlesIfAudioTrackMatches;
parent.querySelector('#chkRequirePerfectMatch').checked = options.RequirePerfectSubtitleMatch;
parent.querySelector('#chkAutomaticallyAddToCollection').checked = options.AutomaticallyAddToCollection;
Array.prototype.forEach.call(parent.querySelectorAll('.chkMetadataSaver'), elem => {
2020-07-30 16:07:13 +02:00
elem.checked = options.MetadataSavers ? options.MetadataSavers.includes(elem.getAttribute('data-pluginname')) : elem.getAttribute('data-defaultenabled') === 'true';
2019-05-06 17:26:18 -07:00
});
Array.prototype.forEach.call(parent.querySelectorAll('.chkSubtitleLanguage'), elem => {
elem.checked = !!options.SubtitleDownloadLanguages && options.SubtitleDownloadLanguages.includes(elem.getAttribute('data-lang'));
2019-05-06 17:26:18 -07:00
});
renderMetadataReaders(parent, getOrderedPlugins(parent.availableOptions.MetadataReaders, options.LocalMetadataReaderOrder || []));
renderMetadataFetchers(parent, parent.availableOptions, options);
renderImageFetchers(parent, parent.availableOptions, options);
renderSubtitleFetchers(parent, parent.availableOptions, options);
2018-10-23 01:05:09 +03:00
}
2019-05-06 17:26:18 -07:00
let currentLibraryOptions;
let currentAvailableOptions;
/* eslint-enable indent */
export default {
embed: embed,
setContentType: setContentType,
getLibraryOptions: getLibraryOptions,
setLibraryOptions: setLibraryOptions
};