import globalize from 'lib/globalize'; export function showLayoutMenu (button, currentLayout, views) { let dispatchEvent = true; if (!views) { dispatchEvent = false; views = button.getAttribute('data-layouts'); views = views ? views.split(',') : ['List', 'Poster', 'PosterCard', 'Thumb', 'ThumbCard']; } const menuItems = views.map(function (v) { return { name: globalize.translate(v), id: v, selected: currentLayout == v }; }); import('../components/actionSheet/actionSheet').then(({ default: actionsheet }) => { actionsheet.show({ items: menuItems, positionTo: button, callback: function (id) { button.dispatchEvent(new CustomEvent('layoutchange', { detail: { viewStyle: id }, bubbles: true, cancelable: false })); if (!dispatchEvent && window.$) { $(button).trigger('layoutchange', [id]); } } }); }); } export function getQueryPagingHtml (options) { const startIndex = options.startIndex; const limit = options.limit; const totalRecordCount = options.totalRecordCount; let html = ''; const recordsStart = totalRecordCount ? startIndex + 1 : 0; const recordsEnd = limit ? Math.min(startIndex + limit, totalRecordCount) : totalRecordCount; const showControls = limit > 0 && limit < totalRecordCount; html += '
'; html += ''; html += globalize.translate('ListPaging', recordsStart, recordsEnd, totalRecordCount); html += ''; if (showControls || options.viewButton || options.filterButton || options.sortButton || options.addLayoutButton) { html += '
'; if (showControls) { html += ''; html += ''; } if (options.addLayoutButton) { html += ''; } if (options.sortButton) { html += ''; } if (options.filterButton) { html += ''; } html += '
'; } html += '
'; return html; } export function showSortMenu (options) { Promise.all([ import('../components/dialogHelper/dialogHelper'), import('../elements/emby-radio/emby-radio') ]).then(([{ default: dialogHelper }]) => { function onSortByChange() { const newValue = this.value; if (this.checked) { const changed = options.query.SortBy != newValue; options.query.SortBy = newValue.replace('_', ','); options.query.StartIndex = 0; if (options.callback && changed) { options.callback(); } } } function onSortOrderChange() { const newValue = this.value; if (this.checked) { const changed = options.query.SortOrder != newValue; options.query.SortOrder = newValue; options.query.StartIndex = 0; if (options.callback && changed) { options.callback(); } } } const dlg = dialogHelper.createDialog({ removeOnClose: true, modal: false, entryAnimationDuration: 160, exitAnimationDuration: 200 }); dlg.classList.add('ui-body-a'); dlg.classList.add('background-theme-a'); dlg.classList.add('formDialog'); let html = ''; html += '
'; html += '

'; html += globalize.translate('HeaderSortBy'); html += '

'; let i; let length; let isChecked; html += '
'; for (i = 0, length = options.items.length; i < length; i++) { const option = options.items[i]; const radioValue = option.id.replace(',', '_'); isChecked = (options.query.SortBy || '').replace(',', '_') == radioValue ? ' checked' : ''; html += ''; } html += '
'; html += '

'; html += globalize.translate('HeaderSortOrder'); html += '

'; html += '
'; isChecked = options.query.SortOrder == 'Ascending' ? ' checked' : ''; html += ''; isChecked = options.query.SortOrder == 'Descending' ? ' checked' : ''; html += ''; html += '
'; html += '
'; dlg.innerHTML = html; dialogHelper.open(dlg); const sortBys = dlg.querySelectorAll('.menuSortBy'); for (i = 0, length = sortBys.length; i < length; i++) { sortBys[i].addEventListener('change', onSortByChange); } const sortOrders = dlg.querySelectorAll('.menuSortOrder'); for (i = 0, length = sortOrders.length; i < length; i++) { sortOrders[i].addEventListener('change', onSortOrderChange); } }); } const libraryBrowser = { showLayoutMenu, getQueryPagingHtml, showSortMenu }; window.LibraryBrowser = libraryBrowser; export default libraryBrowser;