2020-08-14 08:46:34 +02:00
|
|
|
import * as userSettings from './settings/userSettings';
|
|
|
|
import globalize from './globalize';
|
2020-07-27 20:06:11 +01:00
|
|
|
|
|
|
|
export function getSavedQueryKey(modifier) {
|
|
|
|
return window.location.href.split('#')[0] + (modifier || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadSavedQueryValues(key, query) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let values = userSettings.get(key);
|
2020-07-27 20:06:11 +01:00
|
|
|
|
|
|
|
if (values) {
|
|
|
|
values = JSON.parse(values);
|
|
|
|
return Object.assign(query, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveQueryValues(key, query) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const values = {};
|
2020-07-27 20:06:11 +01:00
|
|
|
|
|
|
|
if (query.SortBy) {
|
|
|
|
values.SortBy = query.SortBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.SortOrder) {
|
|
|
|
values.SortOrder = query.SortOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
userSettings.set(key, JSON.stringify(values));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveViewSetting (key, value) {
|
|
|
|
userSettings.set(key + '-_view', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSavedView (key) {
|
|
|
|
return userSettings.get(key + '-_view');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function showLayoutMenu (button, currentLayout, views) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let dispatchEvent = true;
|
2020-07-27 20:06:11 +01:00
|
|
|
|
|
|
|
if (!views) {
|
|
|
|
dispatchEvent = false;
|
|
|
|
views = button.getAttribute('data-layouts');
|
|
|
|
views = views ? views.split(',') : ['List', 'Poster', 'PosterCard', 'Thumb', 'ThumbCard'];
|
|
|
|
}
|
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const menuItems = views.map(function (v) {
|
2020-07-27 20:06:11 +01:00
|
|
|
return {
|
2020-08-28 21:24:00 +09:00
|
|
|
name: globalize.translate(v),
|
2020-07-27 20:06:11 +01:00
|
|
|
id: v,
|
|
|
|
selected: currentLayout == v
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../components/actionSheet/actionSheet').then(({default: actionsheet}) => {
|
2020-07-27 20:06:11 +01:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: button,
|
|
|
|
callback: function (id) {
|
|
|
|
button.dispatchEvent(new CustomEvent('layoutchange', {
|
|
|
|
detail: {
|
|
|
|
viewStyle: id
|
|
|
|
},
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (!dispatchEvent) {
|
|
|
|
if (window.$) {
|
|
|
|
$(button).trigger('layoutchange', [id]);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-27 20:06:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-07-28 13:09:05 +01:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
export function getQueryPagingHtml (options) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const startIndex = options.startIndex;
|
|
|
|
const limit = options.limit;
|
|
|
|
const totalRecordCount = options.totalRecordCount;
|
|
|
|
let html = '';
|
|
|
|
const recordsEnd = Math.min(startIndex + limit, totalRecordCount);
|
|
|
|
const showControls = limit < totalRecordCount;
|
2020-07-27 20:06:11 +01:00
|
|
|
|
2022-05-30 20:44:41 -07:00
|
|
|
html += '<div class="listPaging">';
|
|
|
|
|
|
|
|
if (showControls) {
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '<span style="vertical-align:middle;">';
|
2022-07-03 13:46:54 -04:00
|
|
|
html += globalize.translate('ListPaging', (totalRecordCount ? startIndex + 1 : 0).toLocaleString(), recordsEnd.toLocaleString(), totalRecordCount.toLocaleString());
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '</span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showControls || options.viewButton || options.filterButton || options.sortButton || options.addLayoutButton) {
|
|
|
|
html += '<div style="display:inline-block;">';
|
|
|
|
|
|
|
|
if (showControls) {
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="btnPreviousPage autoSize" ' + (startIndex ? '' : 'disabled') + '><span class="material-icons arrow_back" aria-hidden="true"></span></button>';
|
|
|
|
html += '<button is="paper-icon-button-light" class="btnNextPage autoSize" ' + (startIndex + limit >= totalRecordCount ? 'disabled' : '') + '><span class="material-icons arrow_forward" aria-hidden="true"></span></button>';
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (options.addLayoutButton) {
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button is="paper-icon-button-light" title="' + globalize.translate('ButtonSelectView') + '" class="btnChangeLayout autoSize" data-layouts="' + (options.layouts || '') + '" onclick="LibraryBrowser.showLayoutMenu(this, \'' + (options.currentLayout || '') + '\');"><span class="material-icons view_comfy" aria-hidden="true"></span></button>';
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (options.sortButton) {
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="btnSort autoSize" title="' + globalize.translate('Sort') + '"><span class="material-icons sort_by_alpha" aria-hidden="true"></span></button>';
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (options.filterButton) {
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="btnFilter autoSize" title="' + globalize.translate('Filter') + '"><span class="material-icons filter_list" aria-hidden="true"></span></button>';
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '</div>';
|
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
return html += '</div>';
|
|
|
|
}
|
2020-07-28 13:09:05 +01:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
export function showSortMenu (options) {
|
2020-08-08 23:48:24 +01:00
|
|
|
Promise.all([
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../components/dialogHelper/dialogHelper'),
|
|
|
|
import('../elements/emby-radio/emby-radio')
|
2020-08-08 23:53:34 +01:00
|
|
|
]).then(([{default: dialogHelper}]) => {
|
2020-07-27 20:06:11 +01:00
|
|
|
function onSortByChange() {
|
2020-10-07 21:12:14 +09:00
|
|
|
const newValue = this.value;
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (this.checked) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const changed = options.query.SortBy != newValue;
|
2020-07-27 20:06:11 +01:00
|
|
|
options.query.SortBy = newValue.replace('_', ',');
|
|
|
|
options.query.StartIndex = 0;
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (options.callback && changed) {
|
|
|
|
options.callback();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
function onSortOrderChange() {
|
2020-10-07 21:12:14 +09:00
|
|
|
const newValue = this.value;
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (this.checked) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const changed = options.query.SortOrder != newValue;
|
2020-07-27 20:06:11 +01:00
|
|
|
options.query.SortOrder = newValue;
|
|
|
|
options.query.StartIndex = 0;
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
if (options.callback && changed) {
|
|
|
|
options.callback();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-27 20:06:11 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const dlg = dialogHelper.createDialog({
|
2020-07-27 20:06:11 +01:00
|
|
|
removeOnClose: true,
|
|
|
|
modal: false,
|
|
|
|
entryAnimationDuration: 160,
|
|
|
|
exitAnimationDuration: 200
|
|
|
|
});
|
|
|
|
dlg.classList.add('ui-body-a');
|
|
|
|
dlg.classList.add('background-theme-a');
|
|
|
|
dlg.classList.add('formDialog');
|
2020-10-07 21:12:14 +09:00
|
|
|
let html = '';
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '<div style="margin:0;padding:1.25em 1.5em 1.5em;">';
|
|
|
|
html += '<h2 style="margin:0 0 .5em;">';
|
|
|
|
html += globalize.translate('HeaderSortBy');
|
|
|
|
html += '</h2>';
|
2020-10-07 21:12:14 +09:00
|
|
|
let i;
|
|
|
|
let length;
|
|
|
|
let isChecked;
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '<div>';
|
|
|
|
for (i = 0, length = options.items.length; i < length; i++) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const option = options.items[i];
|
|
|
|
const radioValue = option.id.replace(',', '_');
|
2020-07-27 20:06:11 +01:00
|
|
|
isChecked = (options.query.SortBy || '').replace(',', '_') == radioValue ? ' checked' : '';
|
|
|
|
html += '<label class="radio-label-block"><input type="radio" is="emby-radio" name="SortBy" data-id="' + option.id + '" value="' + radioValue + '" class="menuSortBy" ' + isChecked + ' /><span>' + option.name + '</span></label>';
|
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '</div>';
|
|
|
|
html += '<h2 style="margin: 1em 0 .5em;">';
|
|
|
|
html += globalize.translate('HeaderSortOrder');
|
|
|
|
html += '</h2>';
|
|
|
|
html += '<div>';
|
2020-07-30 16:07:13 +02:00
|
|
|
isChecked = options.query.SortOrder == 'Ascending' ? ' checked' : '';
|
2020-08-24 08:20:29 +09:00
|
|
|
html += '<label class="radio-label-block"><input type="radio" is="emby-radio" name="SortOrder" value="Ascending" class="menuSortOrder" ' + isChecked + ' /><span>' + globalize.translate('Ascending') + '</span></label>';
|
2020-07-30 16:07:13 +02:00
|
|
|
isChecked = options.query.SortOrder == 'Descending' ? ' checked' : '';
|
2020-08-24 08:20:29 +09:00
|
|
|
html += '<label class="radio-label-block"><input type="radio" is="emby-radio" name="SortOrder" value="Descending" class="menuSortOrder" ' + isChecked + ' /><span>' + globalize.translate('Descending') + '</span></label>';
|
2020-07-27 20:06:11 +01:00
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
dialogHelper.open(dlg);
|
2020-10-07 21:12:14 +09:00
|
|
|
const sortBys = dlg.querySelectorAll('.menuSortBy');
|
2020-07-27 20:06:11 +01:00
|
|
|
|
|
|
|
for (i = 0, length = sortBys.length; i < length; i++) {
|
|
|
|
sortBys[i].addEventListener('change', onSortByChange);
|
|
|
|
}
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const sortOrders = dlg.querySelectorAll('.menuSortOrder');
|
2019-10-08 00:58:10 +03:00
|
|
|
|
2020-07-27 20:06:11 +01:00
|
|
|
for (i = 0, length = sortOrders.length; i < length; i++) {
|
|
|
|
sortOrders[i].addEventListener('change', onSortOrderChange);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-07-27 20:06:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-28 16:49:31 +01:00
|
|
|
const libraryBrowser = {
|
2020-07-27 20:06:11 +01:00
|
|
|
getSavedQueryKey,
|
|
|
|
loadSavedQueryValues,
|
|
|
|
saveQueryValues,
|
|
|
|
saveViewSetting,
|
|
|
|
getSavedView,
|
|
|
|
showLayoutMenu,
|
|
|
|
getQueryPagingHtml,
|
|
|
|
showSortMenu
|
2020-07-28 13:09:05 +01:00
|
|
|
};
|
2020-07-28 16:49:31 +01:00
|
|
|
|
|
|
|
window.LibraryBrowser = libraryBrowser;
|
|
|
|
|
|
|
|
export default libraryBrowser;
|