2020-06-09 22:28:08 +03:00
|
|
|
/* eslint-disable indent */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module for image Options Editor.
|
|
|
|
* @module components/imageOptionsEditor/imageOptionsEditor
|
|
|
|
*/
|
|
|
|
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import dom from 'dom';
|
|
|
|
import dialogHelper from 'dialogHelper';
|
|
|
|
import 'emby-checkbox';
|
|
|
|
import 'emby-select';
|
|
|
|
import 'emby-input';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function getDefaultImageConfig(itemType, type) {
|
|
|
|
return {
|
|
|
|
Type: type,
|
|
|
|
MinWidth: 0,
|
2020-05-04 12:44:12 +02:00
|
|
|
Limit: 'Primary' === type ? 1 : 0
|
2019-10-09 18:59:17 +03:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function findImageOptions(imageOptions, type) {
|
2020-06-09 22:28:08 +03:00
|
|
|
return imageOptions.filter(i => {
|
2019-10-09 18:59:17 +03:00
|
|
|
return i.Type == type;
|
|
|
|
})[0];
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getImageConfig(options, availableOptions, imageType, itemType) {
|
2019-10-09 18:59:17 +03:00
|
|
|
return findImageOptions(options.ImageOptions || [], imageType) || findImageOptions(availableOptions.DefaultImageOptions || [], imageType) || getDefaultImageConfig(itemType, imageType);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setVisibilityOfBackdrops(elem, visible) {
|
2019-10-09 18:59:17 +03:00
|
|
|
if (visible) {
|
2020-05-04 12:44:12 +02:00
|
|
|
elem.classList.remove('hide');
|
|
|
|
elem.querySelector('input').setAttribute('required', 'required');
|
2019-10-09 18:59:17 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
elem.classList.add('hide');
|
|
|
|
elem.querySelector('input').setAttribute('required', '');
|
|
|
|
elem.querySelector('input').removeAttribute('required');
|
2019-10-09 18:59:17 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadValues(context, itemType, options, availableOptions) {
|
2020-06-09 22:28:08 +03:00
|
|
|
const supportedImageTypes = availableOptions.SupportedImageTypes || [];
|
|
|
|
setVisibilityOfBackdrops(context.querySelector('.backdropFields'), supportedImageTypes.includes('Backdrop'));
|
|
|
|
setVisibilityOfBackdrops(context.querySelector('.screenshotFields'), supportedImageTypes.includes('Screenshot'));
|
|
|
|
Array.prototype.forEach.call(context.querySelectorAll('.imageType'), i => {
|
|
|
|
const imageType = i.getAttribute('data-imagetype');
|
|
|
|
const container = dom.parentWithTag(i, 'LABEL');
|
2019-10-09 18:59:17 +03:00
|
|
|
|
2020-06-09 22:28:08 +03:00
|
|
|
if (!supportedImageTypes.includes(imageType)) {
|
2020-05-04 12:44:12 +02:00
|
|
|
container.classList.add('hide');
|
2019-10-09 18:59:17 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
container.classList.remove('hide');
|
2019-10-09 18:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getImageConfig(options, availableOptions, imageType, itemType).Limit) {
|
|
|
|
i.checked = true;
|
|
|
|
} else {
|
|
|
|
i.checked = false;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2020-06-09 22:28:08 +03:00
|
|
|
const backdropConfig = getImageConfig(options, availableOptions, 'Backdrop', itemType);
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('#txtMaxBackdrops').value = backdropConfig.Limit;
|
|
|
|
context.querySelector('#txtMinBackdropDownloadWidth').value = backdropConfig.MinWidth;
|
2020-06-09 22:28:08 +03:00
|
|
|
const screenshotConfig = getImageConfig(options, availableOptions, 'Screenshot', itemType);
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('#txtMaxScreenshots').value = screenshotConfig.Limit;
|
|
|
|
context.querySelector('#txtMinScreenshotDownloadWidth').value = screenshotConfig.MinWidth;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveValues(context, options) {
|
2020-06-09 22:28:08 +03:00
|
|
|
options.ImageOptions = Array.prototype.map.call(context.querySelectorAll('.imageType:not(.hide)'), c => {
|
2018-10-23 01:05:09 +03:00
|
|
|
return {
|
2020-05-04 12:44:12 +02:00
|
|
|
Type: c.getAttribute('data-imagetype'),
|
2018-10-23 01:05:09 +03:00
|
|
|
Limit: c.checked ? 1 : 0,
|
|
|
|
MinWidth: 0
|
2019-10-09 18:59:17 +03:00
|
|
|
};
|
|
|
|
});
|
|
|
|
options.ImageOptions.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
Type: 'Backdrop',
|
|
|
|
Limit: context.querySelector('#txtMaxBackdrops').value,
|
|
|
|
MinWidth: context.querySelector('#txtMinBackdropDownloadWidth').value
|
2019-10-09 18:59:17 +03:00
|
|
|
});
|
|
|
|
options.ImageOptions.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
Type: 'Screenshot',
|
|
|
|
Limit: context.querySelector('#txtMaxScreenshots').value,
|
|
|
|
MinWidth: context.querySelector('#txtMinScreenshotDownloadWidth').value
|
2019-10-09 18:59:17 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 22:28:08 +03:00
|
|
|
export class editor {
|
|
|
|
constructor() {
|
|
|
|
this.show = (itemType, options, availableOptions) => {
|
|
|
|
return new Promise((resolve) => {
|
2020-06-11 22:07:24 +03:00
|
|
|
import('text!./components/imageOptionsEditor/imageOptionsEditor.template.html').then(({default: template}) => {
|
2020-06-09 22:28:08 +03:00
|
|
|
const dlg = dialogHelper.createDialog({
|
2020-05-11 21:43:41 +02:00
|
|
|
size: 'small',
|
2019-10-09 18:59:17 +03:00
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
dlg.classList.add('formDialog');
|
2019-10-09 18:59:17 +03:00
|
|
|
dlg.innerHTML = globalize.translateDocument(template);
|
2020-06-09 22:28:08 +03:00
|
|
|
dlg.addEventListener('close', () => {
|
2019-10-09 18:59:17 +03:00
|
|
|
saveValues(dlg, options);
|
|
|
|
});
|
|
|
|
loadValues(dlg, itemType, options, availableOptions);
|
|
|
|
dialogHelper.open(dlg).then(resolve, resolve);
|
2020-06-09 22:28:08 +03:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', () => {
|
2019-10-09 18:59:17 +03:00
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
2020-06-09 22:28:08 +03:00
|
|
|
});
|
2019-10-09 18:59:17 +03:00
|
|
|
});
|
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-06-09 22:28:08 +03:00
|
|
|
}
|
2019-10-09 18:59:17 +03:00
|
|
|
|
2020-06-09 22:28:08 +03:00
|
|
|
/* eslint-enable indent */
|
|
|
|
export default editor;
|