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-07-23 03:07:53 +03:00
|
|
|
async function showEditor(itemType, options, availableOptions) {
|
|
|
|
const response = await fetch('components/imageOptionsEditor/imageOptionsEditor.template.html');
|
|
|
|
const template = await response.text();
|
|
|
|
|
|
|
|
var dlg = dialogHelper.createDialog({
|
|
|
|
size: 'small',
|
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
|
|
|
});
|
|
|
|
dlg.classList.add('formDialog');
|
|
|
|
dlg.innerHTML = globalize.translateDocument(template);
|
|
|
|
dlg.addEventListener('close', function () {
|
|
|
|
saveValues(dlg, options);
|
|
|
|
});
|
|
|
|
loadValues(dlg, itemType, options, availableOptions);
|
|
|
|
dialogHelper.open(dlg).then(() => {
|
|
|
|
return;
|
|
|
|
}).catch(() => {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
|
|
|
dialogHelper.close(dlg);
|
2020-06-26 21:15:00 +03:00
|
|
|
});
|
2020-07-23 03:07:53 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class editor {
|
|
|
|
constructor() {
|
|
|
|
this.show = showEditor;
|
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 */
|
2020-07-23 03:07:53 +03:00
|
|
|
export default editor;
|