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-select/emby-select';
|
|
|
|
import '../../elements/emby-button/paper-icon-button-light';
|
|
|
|
import 'material-design-icons-iconfont';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../formdialog.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../elements/emby-button/emby-button';
|
2020-11-06 00:00:34 +00:00
|
|
|
import '../../assets/css/flexstyles.scss';
|
2020-11-25 00:17:24 -05:00
|
|
|
import template from './sortmenu.template.html';
|
2020-08-06 08:43:52 +01:00
|
|
|
|
|
|
|
function onSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initEditor(context, settings) {
|
|
|
|
context.querySelector('form').addEventListener('submit', onSubmit);
|
|
|
|
|
|
|
|
context.querySelector('.selectSortOrder').value = settings.sortOrder;
|
|
|
|
context.querySelector('.selectSortBy').value = settings.sortBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
function centerFocus(elem, horiz, on) {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../scripts/scrollHelper').then((scrollHelper) => {
|
2020-08-06 08:43:52 +01:00
|
|
|
const fn = on ? 'on' : 'off';
|
|
|
|
scrollHelper.centerFocus[fn](elem, horiz);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function fillSortBy(context, options) {
|
|
|
|
const selectSortBy = context.querySelector('.selectSortBy');
|
|
|
|
|
|
|
|
selectSortBy.innerHTML = options.map(function (o) {
|
|
|
|
return '<option value="' + o.value + '">' + o.name + '</option>';
|
|
|
|
}).join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveValues(context, settingsKey) {
|
|
|
|
userSettings.setFilter(settingsKey + '-sortorder', context.querySelector('.selectSortOrder').value);
|
|
|
|
userSettings.setFilter(settingsKey + '-sortby', context.querySelector('.selectSortBy').value);
|
|
|
|
}
|
|
|
|
|
|
|
|
class SortMenu {
|
|
|
|
show(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
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">';
|
|
|
|
html += '<button is="paper-icon-button-light" class="btnCancel hide-mouse-idle-tv" tabindex="-1"><span class="material-icons arrow_back"></span></button>';
|
|
|
|
html += '<h3 class="formDialogHeaderTitle">${Sort}</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
|
|
|
fillSortBy(dlg, options.sortOptions);
|
|
|
|
initEditor(dlg, options.settings);
|
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('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.settingsKey);
|
|
|
|
resolve();
|
|
|
|
return;
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-11-25 00:17:24 -05:00
|
|
|
reject();
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
2020-08-06 08:43:52 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 08:43:52 +01:00
|
|
|
export default SortMenu;
|