2020-05-04 12:44:12 +02:00
|
|
|
define(['globalize', 'dom', 'dialogHelper', 'emby-checkbox', 'emby-select', 'emby-input'], function (globalize, dom, dialogHelper) {
|
|
|
|
'use strict';
|
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) {
|
2019-10-09 18:59:17 +03:00
|
|
|
return imageOptions.filter(function (i) {
|
|
|
|
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) {
|
|
|
|
var supportedImageTypes = availableOptions.SupportedImageTypes || [];
|
2020-05-04 12:44:12 +02:00
|
|
|
setVisibilityOfBackdrops(context.querySelector('.backdropFields'), -1 != supportedImageTypes.indexOf('Backdrop'));
|
|
|
|
setVisibilityOfBackdrops(context.querySelector('.screenshotFields'), -1 != supportedImageTypes.indexOf('Screenshot'));
|
|
|
|
Array.prototype.forEach.call(context.querySelectorAll('.imageType'), function (i) {
|
|
|
|
var imageType = i.getAttribute('data-imagetype');
|
|
|
|
var container = dom.parentWithTag(i, 'LABEL');
|
2019-10-09 18:59:17 +03:00
|
|
|
|
|
|
|
if (-1 == supportedImageTypes.indexOf(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-05-04 12:44:12 +02:00
|
|
|
var backdropConfig = getImageConfig(options, availableOptions, 'Backdrop', itemType);
|
|
|
|
context.querySelector('#txtMaxBackdrops').value = backdropConfig.Limit;
|
|
|
|
context.querySelector('#txtMinBackdropDownloadWidth').value = backdropConfig.MinWidth;
|
|
|
|
var screenshotConfig = getImageConfig(options, availableOptions, 'Screenshot', itemType);
|
|
|
|
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-05-04 12:44:12 +02:00
|
|
|
options.ImageOptions = Array.prototype.map.call(context.querySelectorAll('.imageType:not(.hide)'), function (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
|
|
|
}
|
|
|
|
|
|
|
|
function editor() {
|
2019-10-09 18:59:17 +03:00
|
|
|
this.show = function (itemType, options, availableOptions) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var xhr = new XMLHttpRequest();
|
2020-05-04 12:44:12 +02:00
|
|
|
xhr.open('GET', 'components/imageoptionseditor/imageoptionseditor.template.html', true);
|
2019-10-09 18:59:17 +03:00
|
|
|
|
|
|
|
xhr.onload = function (e) {
|
|
|
|
var template = this.response;
|
|
|
|
var dlg = dialogHelper.createDialog({
|
2020-05-04 12:44:12 +02:00
|
|
|
size: 'medium-tall',
|
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-05-04 12:44:12 +02:00
|
|
|
dlg.addEventListener('close', function () {
|
2019-10-09 18:59:17 +03:00
|
|
|
saveValues(dlg, options);
|
|
|
|
});
|
|
|
|
loadValues(dlg, itemType, options, availableOptions);
|
|
|
|
dialogHelper.open(dlg).then(resolve, resolve);
|
2020-05-04 12:44:12 +02:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
2019-10-09 18:59:17 +03:00
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-09 18:59:17 +03:00
|
|
|
|
|
|
|
return editor;
|
|
|
|
});
|