2020-08-14 08:46:34 +02:00
|
|
|
import dialogHelper from '../dialogHelper/dialogHelper';
|
|
|
|
import layoutManager from '../layoutManager';
|
|
|
|
import globalize from '../../scripts/globalize';
|
|
|
|
import * as userSettings from '../../scripts/settings/userSettings';
|
|
|
|
import '../../elements/emby-checkbox/emby-checkbox';
|
|
|
|
import '../../elements/emby-input/emby-input';
|
|
|
|
import '../../elements/emby-button/emby-button';
|
|
|
|
import '../../elements/emby-button/paper-icon-button-light';
|
|
|
|
import '../../elements/emby-select/emby-select';
|
|
|
|
import 'material-design-icons-iconfont';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../formdialog.scss';
|
2020-11-06 00:00:34 +00:00
|
|
|
import '../../assets/css/flexstyles.scss';
|
2020-11-25 00:17:24 -05:00
|
|
|
import template from './viewSettings.template.html';
|
2020-08-06 11:41:58 +01:00
|
|
|
|
|
|
|
function onSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initEditor(context, settings) {
|
|
|
|
context.querySelector('form').addEventListener('submit', onSubmit);
|
|
|
|
|
|
|
|
const elems = context.querySelectorAll('.viewSetting-checkboxContainer');
|
|
|
|
|
|
|
|
for (const elem of elems) {
|
|
|
|
elem.querySelector('input').checked = settings[elem.getAttribute('data-settingname')] || false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
context.querySelector('.selectImageType').value = settings.imageType || 'primary';
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
function saveValues(context, settings, settingsKey) {
|
|
|
|
const elems = context.querySelectorAll('.viewSetting-checkboxContainer');
|
|
|
|
for (const elem of elems) {
|
|
|
|
userSettings.set(settingsKey + '-' + elem.getAttribute('data-settingname'), elem.querySelector('input').checked);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
userSettings.set(settingsKey + '-imageType', context.querySelector('.selectImageType').value);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
function centerFocus(elem, horiz, on) {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../scripts/scrollHelper').then((scrollHelper) => {
|
2020-08-06 11:41:58 +01:00
|
|
|
const fn = on ? 'on' : 'off';
|
|
|
|
scrollHelper.centerFocus[fn](elem, horiz);
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
function showIfAllowed(context, selector, visible) {
|
|
|
|
const elem = context.querySelector(selector);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
if (visible && !elem.classList.contains('hiddenFromViewSettings')) {
|
|
|
|
elem.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
elem.classList.add('hide');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-08-06 11:41:58 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
class ViewSettings {
|
|
|
|
show(options) {
|
2022-10-05 02:44:28 +03:00
|
|
|
return new Promise(function (resolve) {
|
2020-11-25 00:17:24 -05:00
|
|
|
const dialogOptions = {
|
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
|
|
|
};
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
dialogOptions.size = 'fullscreen';
|
|
|
|
} else {
|
|
|
|
dialogOptions.size = 'small';
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
const dlg = dialogHelper.createDialog(dialogOptions);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.classList.add('formDialog');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
html += '<div class="formDialogHeader">';
|
2022-02-24 19:03:42 +03:00
|
|
|
html += `<button is="paper-icon-button-light" class="btnCancel hide-mouse-idle-tv" tabindex="-1" title="${globalize.translate('ButtonBack')}"><span class="material-icons arrow_back" aria-hidden="true"></span></button>`;
|
2020-11-25 00:17:24 -05:00
|
|
|
html += '<h3 class="formDialogHeaderTitle">${Settings}</h3>';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
html += '</div>';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
html += template;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.innerHTML = globalize.translateHtml(html, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
const settingElements = dlg.querySelectorAll('.viewSetting');
|
|
|
|
for (const settingElement of settingElements) {
|
|
|
|
if (options.visibleSettings.indexOf(settingElement.getAttribute('data-settingname')) === -1) {
|
|
|
|
settingElement.classList.add('hide');
|
|
|
|
settingElement.classList.add('hiddenFromViewSettings');
|
|
|
|
} else {
|
|
|
|
settingElement.classList.remove('hide');
|
|
|
|
settingElement.classList.remove('hiddenFromViewSettings');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-11-25 00:17:24 -05:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
initEditor(dlg, options.settings);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.querySelector('.selectImageType').addEventListener('change', function () {
|
2022-10-05 02:44:28 +03:00
|
|
|
showIfAllowed(dlg, '.chkTitleContainer', this.value !== 'list' && this.value !== 'banner');
|
|
|
|
showIfAllowed(dlg, '.chkYearContainer', this.value !== 'list' && this.value !== 'banner');
|
|
|
|
showIfAllowed(dlg, '.chkCardLayoutContainer', this.value !== 'list' && this.value !== 'banner');
|
2020-11-25 00:17:24 -05:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
centerFocus(dlg.querySelector('.formDialogContent'), false, true);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
let submitted;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.querySelector('.selectImageType').dispatchEvent(new CustomEvent('change', {}));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dlg.querySelector('form').addEventListener('change', function () {
|
|
|
|
submitted = true;
|
|
|
|
}, true);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
dialogHelper.open(dlg).then(function () {
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
centerFocus(dlg.querySelector('.formDialogContent'), false, false);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
if (submitted) {
|
|
|
|
saveValues(dlg, options.settings, options.settingsKey);
|
2022-10-05 02:44:28 +03:00
|
|
|
return resolve();
|
2020-11-25 00:17:24 -05:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2022-10-05 02:44:28 +03:00
|
|
|
return resolve();
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
2020-08-06 11:41:58 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 11:41:58 +01:00
|
|
|
export default ViewSettings;
|